rename files after encoding to never end up with unfinished files after a power cut or crash
This commit is contained in:
parent
a41879662e
commit
0b95dd0057
1 changed files with 8 additions and 1 deletions
|
@ -292,7 +292,8 @@ def video_cmd(video, target, profile, info):
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def video(video, target, profile, info):
|
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('.')
|
profile, format = profile.split('.')
|
||||||
#r = run_command(cmd, -1)
|
#r = run_command(cmd, -1)
|
||||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
@ -306,11 +307,17 @@ def video(video, target, profile, info):
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
p.communicate()
|
p.communicate()
|
||||||
os.unlink("%s.mp4" % target)
|
os.unlink("%s.mp4" % target)
|
||||||
|
elif r == 0 and target != enc_target:
|
||||||
|
shutil.move(enc_target, target)
|
||||||
print 'Input:\t', video
|
print 'Input:\t', video
|
||||||
print 'Output:\t', target
|
print 'Output:\t', target
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
p.kill()
|
p.kill()
|
||||||
r = 1
|
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):
|
if os.path.exists(target):
|
||||||
print "\n\ncleanup unfinished encoding:\nremoving", target
|
print "\n\ncleanup unfinished encoding:\nremoving", target
|
||||||
print "\n"
|
print "\n"
|
||||||
|
|
Loading…
Reference in a new issue