port run_command from pad.ma, kill subproces if they do not finish in time

This commit is contained in:
j 2008-06-27 18:08:16 +02:00
parent 2dd8f949b6
commit cb315a7a86
1 changed files with 14 additions and 1 deletions

View File

@ -11,6 +11,18 @@ from subtitles import time2ms
img_extension="jpg"
def run_command(cmd, timeout=25):
p = subprocess.Popen(cmd, shell=True)
while timeout > 0:
time.sleep(0.2)
timeout -= 0.2
if p.poll() != None:
return p.returncode
if p.poll() == None:
os.kill(p.pid, 9)
killedpid, stat = os.waitpid(p.pid, os.WNOHANG)
return p.returncode
def extract_flash_ng(movie_file, flash_file, inpoint, outpoint, width=128, height=96, offset = 0):
ext = movie_file.split('.')[-1]
if ext in ('sub', 'srt'):
@ -157,10 +169,11 @@ def extract_poster_still(movie_file, png_file, inpoint):
extractClipScript = abspath(join(dirname(__file__), "tools/extract_frame.py"))
cmd = '''%s "%s" "%s" %s 0 128''' % (extractClipScript, movie_file, png_file, inpoint)
os.system(cmd.encode('utf-8'))
run_command(cmd.encode('utf-8'))
def extract_subtitles(movie_file, srt, img_folder, width=128, offset = 0, redo = False):
subtitles = srt2dict(srt)
for k in sorted([int(k) for k in subtitles]):
timestamp = subtitles["%s" % k]['start']
extract_frame(movie_file, timestamp, img_folder, width, offset, redo)