From 121f6def821341e7157f4a91cde989d09bce2e6e Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Wed, 22 Feb 2012 19:22:47 +0100 Subject: [PATCH 1/2] print statments converted to functions --- n900-encode.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/n900-encode.py b/n900-encode.py index 9990a61..ddd0544 100755 --- a/n900-encode.py +++ b/n900-encode.py @@ -38,8 +38,8 @@ def main(argv): # CLI Argument Processing try: opts, args = getopt.getopt(argv, "i:o:m:v:a:t:hf", ["input=", "output=", "mpopts=", "abitrate=", "vbitrate=", "threads=", "help", "force-overwrite"]) - except getopt.GetoptError, err: - print str(err) + except getopt.GetoptError as err: + printi(str(err)) usage() input = None @@ -75,7 +75,7 @@ def main(argv): else: mpbin = progpath("mplayer") if mpbin == None: - print "Error: mplayer not found in PATH and no binary given, Aborting!" + print("Error: mplayer not found in PATH and no binary given, Aborting!") sys.exit(1) global ffbin @@ -85,19 +85,19 @@ def main(argv): else: ffbin = progpath("ffmpeg") if ffbin == None: - print "Error: ffmpeg not found in PATH and no binary given, Aborting!" + print( "Error: ffmpeg not found in PATH and no binary given, Aborting!") sys.exit(1) # Check input and output files if not os.path.isfile(input): - print "Error: input file is not a valid File or doesn't exist" + print("Error: input file is not a valid File or doesn't exist") sys.exit(2) if os.path.isfile(output): if overwrite: os.remove(output) else: - print "Error: output file " + output + " already exists, force overwrite with -f" + print("Error: output file " + output + " already exists, force overwrite with -f") sys.exit(1) # Start Processing @@ -124,7 +124,7 @@ def calculate(input): m = s.search(mp[0]) orig_height = m.group(1) except: - print "Error: unable to identify source video, exiting!" + print("Error: unable to identify source video, exiting!") sys.exit(2) # Calculate output resolution @@ -211,14 +211,14 @@ def convert(input, output, res, abitrate, vbitrate, threads, mpopts): mdv = subprocess.Popen(mpvideodec, stdout=None, stderr=None) mda = subprocess.Popen(mpaudiodec, stdout=None, stderr=None) except: - print "Error: Starting decoding threads failed!" + print("Error: Starting decoding threads failed!") sys.exit(3) # Start ffmpeg encoding process in foreground try: subprocess.check_call(ffmenc) except subprocess.CalledProcessError: - print "Error: Encoding thread failed!" + print("Error: Encoding thread failed!") sys .exit(4) @@ -250,18 +250,18 @@ def cleanup(): def usage(): """Print avaiable commandline arguments""" - print "This is n900-encode.py (C) 2010 Stefan Brand " - print "Usage:" - print " n900-encode.py --input [opts]\n" - print "Options:" - print " --input [-i]: Video to Convert" - print " --output [-o]: Name of the converted Video" - print " --mpopts \"\" [-m]: Additional options for mplayer (eg -sid 1 or -aid 1) Must be enclosed in \"\"" - print " --abitrate
[-a]: Audio Bitrate in KBit/s" - print " --vbitrate
[-v]: Video Bitrate in kBit/s" - print " --threads [-t]: Use Threads to encode" - print " --force-overwrite [-f]: Overwrite output-file if existing" - print " --help [-h]: Print this Help" + print("This is n900-encode.py (C) 2010 Stefan Brand ") + print("Usage:") + print(" n900-encode.py --input [opts]\n") + print("Options:") + print(" --input [-i]: Video to Convert") + print(" --output [-o]: Name of the converted Video") + print(" --mpopts \"\" [-m]: Additional options for mplayer (eg -sid 1 or -aid 1) Must be enclosed in \"\"") + print(" --abitrate
[-a]: Audio Bitrate in KBit/s") + print(" --vbitrate
[-v]: Video Bitrate in kBit/s") + print(" --threads [-t]: Use Threads to encode") + print(" --force-overwrite [-f]: Overwrite output-file if existing") + print(" --help [-h]: Print this Help") sys.exit(0) @@ -277,5 +277,5 @@ if __name__ == "__main__": if len(sys.argv) > 1: main(sys.argv[1:]) else: - print "Error: You have to give an input file at least!" + print("Error: You have to give an input file at least!") usage() From fc153ba08f4b81c385963c6ec60d141d15798052 Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Wed, 22 Feb 2012 19:31:45 +0100 Subject: [PATCH 2/2] adjusted exit handling to python 3 --- n900-encode.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/n900-encode.py b/n900-encode.py index ddd0544..cc3087e 100755 --- a/n900-encode.py +++ b/n900-encode.py @@ -32,6 +32,14 @@ _ffbin = None # ffmpeg binary, if set to None it is searched in your $PATH # Main Program, no changes needed below this line ########################################################################################### +# Global Variables + +mda = None +mdv = None +afifo = None +vfifo = None + +# Main Function def main(argv): """Main Function, cli argument processing and checking""" @@ -238,14 +246,16 @@ def cleanup(): # Cleanup try: - os.kill(mda.pid()) - os.kill(mdv.pid()) + if (mda != None): + os.kill(mda.pid()) + if (mdv != None): + os.kill(mdv.pid()) finally: - try: + if (afifo != None): os.remove(afifo) + if (vfifo != None): os.remove(vfifo) - finally: - sys.exit(0) + os._exit(0) def usage(): """Print avaiable commandline arguments""" @@ -262,7 +272,7 @@ def usage(): print(" --threads [-t]: Use Threads to encode") print(" --force-overwrite [-f]: Overwrite output-file if existing") print(" --help [-h]: Print this Help") - sys.exit(0) + os._exit(0) # Start the Main Function