use avconv to extract frames from mp4 videos

This commit is contained in:
j 2013-10-02 10:56:30 +00:00
parent 9ac3342acd
commit 8917a71f47

View file

@ -278,21 +278,33 @@ def run_command(cmd, timeout=10):
return p.returncode
def frame(videoFile, frame, position, height=128, redo=False):
def frame(video, frame, position, height=128, redo=False):
'''
params:
videoFile input
video input
frame output
position as float in seconds
height of frame
redo boolean to extract file even if it exists
'''
if exists(videoFile):
frameFolder = os.path.dirname(frame)
if exists(video):
folder = os.path.dirname(frame)
if redo or not exists(frame):
ox.makedirs(frameFolder)
cmd = ['oxframe', '-i', videoFile, '-o', frame,
'-p', str(position), '-y', str(height)]
ox.makedirs(folder)
if video.endswith('.mp4'):
cmd = [
AVCONV, '-y',
'-ss', str(position),
'-i', video,
'-an', '-vframes', '1',
'-vf', 'scale=-1:%s' % height
]
if not frame.endswith('.png'):
cmd += ['-f', 'mjpeg']
cmd += [frame]
else:
cmd = ['oxframe', '-i', video, '-o', frame,
'-p', str(position), '-y', str(height)]
run_command(cmd)