Added more error handling
This commit is contained in:
parent
a0ed152846
commit
30359c25dd
1 changed files with 30 additions and 13 deletions
|
@ -83,7 +83,7 @@ def main(argv):
|
||||||
# Check for needed Programs
|
# Check for needed Programs
|
||||||
global mpbin
|
global mpbin
|
||||||
mpbin = None
|
mpbin = None
|
||||||
if not _mpbin == None and os.path.exists(_mpbin) and not os.path.isdir(_mpbin):
|
if not _mpbin == None and os.path.isfile(_mpbin):
|
||||||
mpbin = _mpbin
|
mpbin = _mpbin
|
||||||
else:
|
else:
|
||||||
mpbin = progpath("mplayer")
|
mpbin = progpath("mplayer")
|
||||||
|
@ -93,7 +93,7 @@ def main(argv):
|
||||||
|
|
||||||
global ffbin
|
global ffbin
|
||||||
ffbin = None
|
ffbin = None
|
||||||
if not _ffbin == None and os.path.exists(_ffbin) and not os.path.isdir(_ffbin):
|
if not _ffbin == None and os.path.isfile(_ffbin):
|
||||||
ffbin = _ffbin
|
ffbin = _ffbin
|
||||||
else:
|
else:
|
||||||
ffbin = progpath("ffmpeg")
|
ffbin = progpath("ffmpeg")
|
||||||
|
@ -124,7 +124,11 @@ def calculate(input):
|
||||||
|
|
||||||
# Get characteristics using mplayer
|
# Get characteristics using mplayer
|
||||||
cmd=[mpbin, "-ao", "null", "-vo", "null", "-frames", "0", "-identify", input]
|
cmd=[mpbin, "-ao", "null", "-vo", "null", "-frames", "0", "-identify", input]
|
||||||
mp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
try:
|
||||||
|
mp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||||
|
except:
|
||||||
|
print("Error: Couldn't execute mplayer")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = re.compile("^ID_VIDEO_ASPECT=(.*)$", re.M)
|
s = re.compile("^ID_VIDEO_ASPECT=(.*)$", re.M)
|
||||||
|
@ -162,8 +166,12 @@ def convert(input, output, res, abitrate, vbitrate, threads, mpopts):
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
afifo = "/tmp/stream" + str(pid) + ".wav"
|
afifo = "/tmp/stream" + str(pid) + ".wav"
|
||||||
vfifo = "/tmp/stream" + str(pid) + ".yuv"
|
vfifo = "/tmp/stream" + str(pid) + ".yuv"
|
||||||
os.mkfifo(afifo)
|
try:
|
||||||
os.mkfifo(vfifo)
|
os.mkfifo(afifo)
|
||||||
|
os.mkfifo(vfifo)
|
||||||
|
except:
|
||||||
|
print("Error: Couldn't create fifos!")
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
# Define mplayer command for video decoding
|
# Define mplayer command for video decoding
|
||||||
mpvideodec = [ mpbin,
|
mpvideodec = [ mpbin,
|
||||||
|
@ -233,7 +241,16 @@ def convert(input, output, res, abitrate, vbitrate, threads, mpopts):
|
||||||
except:
|
except:
|
||||||
print("Error: Starting decoding threads failed!")
|
print("Error: Starting decoding threads failed!")
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
|
print("Waiting for decoding threads to start...")
|
||||||
|
|
||||||
|
# Wait
|
||||||
|
sleep(2)
|
||||||
|
# Check if the decoding processes are running
|
||||||
|
if (mda.poll() != None or mdv.poll() != None):
|
||||||
|
print("Error: Starting decoding threads failed!")
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
# Start ffmpeg encoding process in foreground
|
# Start ffmpeg encoding process in foreground
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(ffmenc)
|
subprocess.check_call(ffmenc)
|
||||||
|
@ -259,21 +276,21 @@ def cleanup():
|
||||||
# Cleanup
|
# Cleanup
|
||||||
try:
|
try:
|
||||||
if (mda != None):
|
if (mda != None):
|
||||||
if (mda.pid() != None):
|
if (mda.returncode == None):
|
||||||
os.kill(mda.pid())
|
mda.kill()
|
||||||
if (mdv != None):
|
if (mdv != None):
|
||||||
if (mda.pid() != None):
|
if (mdv.returncode == None):
|
||||||
os.kill(mdv.pid())
|
mdv.kill()
|
||||||
finally:
|
finally:
|
||||||
if (afifo != None):
|
if (afifo != None and os.path.exists(afifo)):
|
||||||
os.remove(afifo)
|
os.remove(afifo)
|
||||||
if (vfifo != None):
|
if (vfifo != None and os.path.exists(vfifo)):
|
||||||
os.remove(vfifo)
|
os.remove(vfifo)
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
"""Print avaiable commandline arguments"""
|
"""Print avaiable commandline arguments"""
|
||||||
|
|
||||||
print("This is n900-encode.py (C) 2010 Stefan Brand <seiichiro0185 AT tol DOT ch>")
|
print("This is n900-encode.py (C) 2012 Stefan Brand <seiichiro0185 AT seiichiro0185 DOT org>")
|
||||||
print("Usage:")
|
print("Usage:")
|
||||||
print(" n900-encode.py --input <file> [opts]\n")
|
print(" n900-encode.py --input <file> [opts]\n")
|
||||||
print("Options:")
|
print("Options:")
|
||||||
|
|
Loading…
Reference in a new issue