rename files after encoding to never end up with unfinished files after a power cut or crash

This commit is contained in:
j 2014-11-03 12:16:09 +02:00
parent a41879662e
commit 0b95dd0057

View file

@ -292,7 +292,8 @@ def video_cmd(video, target, profile, info):
return cmd
def video(video, target, profile, info):
cmd = video_cmd(video, target, profile, info)
enc_target = target if target.endswith('.mp4') else target + '.tmp.webm'
cmd = video_cmd(video, enc_target, profile, info)
profile, format = profile.split('.')
#r = run_command(cmd, -1)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
@ -306,11 +307,17 @@ def video(video, target, profile, info):
stderr=subprocess.STDOUT)
p.communicate()
os.unlink("%s.mp4" % target)
elif r == 0 and target != enc_target:
shutil.move(enc_target, target)
print 'Input:\t', video
print 'Output:\t', target
except KeyboardInterrupt:
p.kill()
r = 1
if os.path.exists(enc_target):
print "\n\ncleanup unfinished encoding:\nremoving", enc_target
print "\n"
os.unlink(enc_target)
if os.path.exists(target):
print "\n\ncleanup unfinished encoding:\nremoving", target
print "\n"