added support for mp4, manually tested, mp4 files transcoded and links correctly populated in html

This commit is contained in:
Miroslav Pavleski
2015-05-24 15:50:30 +02:00
parent b901d681fe
commit 01d442d3ef
4 changed files with 18 additions and 6 deletions

View File

@@ -181,9 +181,13 @@ class Video(Media):
self.date = None
self.src_filename = filename
if not settings['use_orig'] or not is_valid_html5_video(ext):
self.filename = self.url = base + '.webm'
self.mime = get_mime('.webm')
self.dst_path = join(settings['destination'], path, base + '.webm')
video_format = settings['video_format']
ext = '.' + video_format
self.filename = self.url = base + ext
self.mime = get_mime(ext)
self.dst_path = join(settings['destination'], path, base + ext)
else:
self.mime = get_mime(ext)

View File

@@ -72,7 +72,7 @@ def generate_cache_metadata(gallery, f):
proposed_cache_control = None
if 'media_max_age' in gallery.settings['upload_s3_options'] and \
file_extension in ['.jpg','.png','.webm']:
file_extension in ['.jpg','.png','.webm','.mp4']:
proposed_cache_control = "max-age=%s" % \
gallery.settings['upload_s3_options']['media_max_age']
elif 'max_age' in gallery.settings['upload_s3_options']:

View File

@@ -67,8 +67,10 @@ _DEFAULT_CONFIG = {
'use_orig': False,
'video_size': (480, 360),
'watermark': '',
'video_format': 'webm',
'webm_options': ['-crf', '10', '-b:v', '1.6M',
'-qmin', '4', '-qmax', '63'],
'mp4_options': ['-crf', '23' ],
'write_html': True,
'zip_gallery': False,
'zip_media_format': 'resized',

View File

@@ -156,9 +156,15 @@ def process_video(filepath, outpath, settings):
outname = os.path.join(outpath, filename)
utils.copy(filepath, outname, symlink=settings['orig_link'])
else:
outname = os.path.join(outpath, basename + '.webm')
valid_formats = ['mp4', 'webm']
video_format = settings['video_format']
if video_format not in valid_formats:
raise ValueError('Invalid video_format. Please choose one of: ' + str(valid_formats))
outname = os.path.join(outpath, basename + '.' + video_format)
generate_video(filepath, outname, settings,
options=settings['webm_options'])
options=settings[video_format + '_options'])
except Exception:
return Status.FAILURE