|
|
|
|
@ -61,13 +61,9 @@ def check_subprocess(cmd, source, outname):
|
|
|
|
|
raise SubprocessException('Failed to process ' + source) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def video_size(source, settings={}): |
|
|
|
|
"""Returns the dimensions of the video. |
|
|
|
|
:param source: path to a video |
|
|
|
|
:param settings: settings dict |
|
|
|
|
""" |
|
|
|
|
def video_size(source, converter='ffmpeg'): |
|
|
|
|
"""Returns the dimensions of the video.""" |
|
|
|
|
|
|
|
|
|
converter = settings.get('video_converter', 'ffmpeg') |
|
|
|
|
ret, stdout, stderr = call_subprocess([converter, '-i', source]) |
|
|
|
|
pattern = re.compile(r'Stream.*Video.* ([0-9]+)x([0-9]+)') |
|
|
|
|
match = pattern.search(stderr) |
|
|
|
|
@ -96,7 +92,8 @@ def generate_video(source, outname, settings, options=None):
|
|
|
|
|
|
|
|
|
|
# Don't transcode if source is in the required format and |
|
|
|
|
# has fitting datedimensions, copy instead. |
|
|
|
|
w_src, h_src = video_size(source, settings) |
|
|
|
|
converter = settings['video_converter'] |
|
|
|
|
w_src, h_src = video_size(source, converter=converter) |
|
|
|
|
w_dst, h_dst = settings['video_size'] |
|
|
|
|
logger.debug('Video size: %i, %i -> %i, %i', w_src, h_src, w_dst, h_dst) |
|
|
|
|
|
|
|
|
|
@ -122,7 +119,6 @@ def generate_video(source, outname, settings, options=None):
|
|
|
|
|
|
|
|
|
|
# Encoding options improved, thanks to |
|
|
|
|
# http://ffmpeg.org/trac/ffmpeg/wiki/vpxEncodingGuide |
|
|
|
|
converter = settings.get('video_converter', 'ffmpeg') |
|
|
|
|
cmd = [converter, '-i', source, '-y'] # -y to overwrite output files |
|
|
|
|
if options is not None: |
|
|
|
|
cmd += options |
|
|
|
|
@ -132,22 +128,21 @@ def generate_video(source, outname, settings, options=None):
|
|
|
|
|
check_subprocess(cmd, source, outname) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_thumbnail(source, outname, box, delay, fit=True, options=None): |
|
|
|
|
def generate_thumbnail(source, outname, box, delay, fit=True, options=None, |
|
|
|
|
converter='ffmpeg'): |
|
|
|
|
"""Create a thumbnail image for the video source, based on ffmpeg.""" |
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
tmpfile = outname + ".tmp.jpg" |
|
|
|
|
|
|
|
|
|
# dump an image of the video |
|
|
|
|
converter = settings.get('video_converter', 'ffmpeg') |
|
|
|
|
cmd = [converter, '-i', source, '-an', '-r', '1', |
|
|
|
|
'-ss', delay, '-vframes', '1', '-y', tmpfile] |
|
|
|
|
logger.debug('Create thumbnail for video: %s', ' '.join(cmd)) |
|
|
|
|
check_subprocess(cmd, source, outname) |
|
|
|
|
|
|
|
|
|
# use the generate_thumbnail function from sigal.image |
|
|
|
|
image.generate_thumbnail(tmpfile, outname, box, delay, fit=fit, |
|
|
|
|
options=options) |
|
|
|
|
image.generate_thumbnail(tmpfile, outname, box, fit=fit, options=options) |
|
|
|
|
# remove the image |
|
|
|
|
os.unlink(tmpfile) |
|
|
|
|
|
|
|
|
|
@ -187,7 +182,8 @@ def process_video(filepath, outpath, settings):
|
|
|
|
|
generate_thumbnail( |
|
|
|
|
outname, thumb_name, settings['thumb_size'], |
|
|
|
|
settings['thumb_video_delay'], fit=settings['thumb_fit'], |
|
|
|
|
options=settings['jpg_options']) |
|
|
|
|
options=settings['jpg_options'], |
|
|
|
|
converter=settings['video_converter']) |
|
|
|
|
except Exception: |
|
|
|
|
if logger.getEffectiveLevel() == logging.DEBUG: |
|
|
|
|
raise |
|
|
|
|
|