Fixes for small bugs
There were some blocking issues in the code. They are small, but break tests and/or production. Fixed some of them.
This commit is contained in:
parent
0eeb2adad7
commit
4551a808be
@ -40,7 +40,7 @@ class VideoMediaManager(MediaManagerBase):
|
||||
video_res = video_config['available_resolutions']
|
||||
video_res.remove(video_config['default_resolution'])
|
||||
video_res.insert(0, video_config['default_resolution'])
|
||||
video_res = map((lambda x: unicode('webm_' + str(x), 'utf-8')), video_res)
|
||||
video_res = ['webm_{}'.format(x) for x in video_res]
|
||||
return ([u'webm_video'] + video_res + [u'original'])
|
||||
|
||||
|
||||
|
@ -172,29 +172,34 @@ def main_task(entry_id, resolution, medium_size, **process_info):
|
||||
entry, manager = get_entry_and_processing_manager(entry_id)
|
||||
with CommonVideoProcessor(manager, entry) as processor:
|
||||
processor.common_setup(resolution)
|
||||
processor.transcode(medium_size=tuple(medium_size), vp8_quality=process_info['vp8_quality'],
|
||||
vp8_threads=process_info['vp8_threads'], vorbis_quality=process_info['vorbis_quality'])
|
||||
processor.transcode(medium_size=tuple(medium_size),
|
||||
vp8_quality=process_info['vp8_quality'],
|
||||
vp8_threads=process_info['vp8_threads'],
|
||||
vorbis_quality=process_info['vorbis_quality'])
|
||||
processor.generate_thumb(thumb_size=process_info['thumb_size'])
|
||||
processor.store_orig_metadata()
|
||||
# Make state of entry as processed
|
||||
entry.state = u'processed'
|
||||
entry.save()
|
||||
_log.info(u'MediaEntry ID {0} is processed (transcoded to default resolution'
|
||||
'): {1}'.format(unicode(entry.id), unicode(medium_size)))
|
||||
_log.info(u'MediaEntry ID {0} is processed (transcoded to default'
|
||||
' resolution): {1}'.format(entry.id, medium_size))
|
||||
_log.debug('MediaEntry processed')
|
||||
|
||||
|
||||
@celery.task()
|
||||
def complementary_task(entry_id, resolution, medium_size, **process_info):
|
||||
def complementary_task(entry_id, resolution, medium_size, **process_info):
|
||||
"""
|
||||
Side celery task to transcode the video to other resolutions
|
||||
"""
|
||||
entry, manager = get_entry_and_processing_manager(entry_id)
|
||||
with CommonVideoProcessor(manager, entry) as processor:
|
||||
processor.common_setup(resolution)
|
||||
processor.transcode(medium_size=tuple(medium_size), vp8_quality=process_info['vp8_quality'],
|
||||
vp8_threads=process_info['vp8_threads'], vorbis_quality=process_info['vorbis_quality'])
|
||||
_log.info(u'MediaEntry ID {0} is transcoded to {1}'.format(unicode(entry.id), unicode(medium_size)))
|
||||
processor.transcode(medium_size=tuple(medium_size),
|
||||
vp8_quality=process_info['vp8_quality'],
|
||||
vp8_threads=process_info['vp8_threads'],
|
||||
vorbis_quality=process_info['vorbis_quality'])
|
||||
_log.info(u'MediaEntry ID {0} is transcoded to {1}'.format(
|
||||
entry.id, medium_size))
|
||||
|
||||
|
||||
@celery.task()
|
||||
@ -215,7 +220,7 @@ class CommonVideoProcessor(MediaProcessor):
|
||||
Provides a base for various video processing steps
|
||||
"""
|
||||
acceptable_files = ['original, best_quality', 'webm_144p', 'webm_360p',
|
||||
'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video']
|
||||
'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video']
|
||||
|
||||
def common_setup(self, resolution=None):
|
||||
self.video_config = mgg \
|
||||
@ -225,7 +230,7 @@ class CommonVideoProcessor(MediaProcessor):
|
||||
self.process_filename = get_process_filename(
|
||||
self.entry, self.workbench, self.acceptable_files)
|
||||
self.name_builder = FilenameBuilder(self.process_filename)
|
||||
|
||||
|
||||
self.transcoder = transcoders.VideoTranscoder()
|
||||
self.did_transcode = False
|
||||
|
||||
@ -336,7 +341,12 @@ class CommonVideoProcessor(MediaProcessor):
|
||||
|
||||
else:
|
||||
_log.debug('Entered transcoder')
|
||||
video_config = (mgg.global_config['plugins']
|
||||
['mediagoblin.media_types.video'])
|
||||
num_res = len(video_config['available_resolutions'])
|
||||
default_res = video_config['default_resolution']
|
||||
self.transcoder.transcode(self.process_filename, tmp_dst,
|
||||
default_res, num_res,
|
||||
vp8_quality=vp8_quality,
|
||||
vp8_threads=vp8_threads,
|
||||
vorbis_quality=vorbis_quality,
|
||||
@ -569,7 +579,7 @@ class VideoProcessingManager(ProcessingManager):
|
||||
|
||||
def workflow(self, entry, feed_url, reprocess_action, reprocess_info=None):
|
||||
|
||||
video_config = mgg.global_config['plugins'][MEDIA_TYPE]
|
||||
video_config = mgg.global_config['plugins'][MEDIA_TYPE]
|
||||
def_res = video_config['default_resolution']
|
||||
priority_num = len(video_config['available_resolutions']) + 1
|
||||
|
||||
|
@ -158,7 +158,7 @@ class VideoTranscoder(object):
|
||||
self.progress_percentage = 0
|
||||
self.loop = GLib.MainLoop()
|
||||
|
||||
def transcode(self, src, dst, **kwargs):
|
||||
def transcode(self, src, dst, default_res, num_res, **kwargs):
|
||||
'''
|
||||
Transcode a video file into a 'medium'-sized version.
|
||||
'''
|
||||
@ -187,9 +187,8 @@ class VideoTranscoder(object):
|
||||
self._progress_callback = kwargs.get('progress_callback') or None
|
||||
|
||||
# Get number of resolutions available for the video
|
||||
video_config = mgg.global_config['plugins']['mediagoblin.media_types.video']
|
||||
self.num_of_resolutions = len(video_config['available_resolutions'])
|
||||
self.default_resolution = video_config['default_resolution']
|
||||
self.num_of_resolutions = num_res
|
||||
self.default_resolution = default_res
|
||||
|
||||
if not type(self.destination_dimensions) == tuple:
|
||||
raise Exception('dimensions must be tuple: (width, height)')
|
||||
|
@ -47,7 +47,10 @@ import os
|
||||
import pytest
|
||||
import webtest.forms
|
||||
import pkg_resources
|
||||
import mock
|
||||
try:
|
||||
import mock
|
||||
except ImportError:
|
||||
import unittest.mock as mock
|
||||
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
@ -635,7 +638,7 @@ class TestSubmissionVideo(BaseTestSubmission):
|
||||
manager.workflow(entry, feed_url=None, reprocess_action='initial')
|
||||
|
||||
# test section
|
||||
mock_main_task.assert_called_once_with(args=(entry.id, def_res,
|
||||
mock_main_task.assert_called_once_with(args=(entry.id, def_res,
|
||||
ACCEPTED_RESOLUTIONS[def_res]),
|
||||
kwargs=reprocess_info, queue='default',
|
||||
priority=main_priority, immutable=True)
|
||||
@ -724,7 +727,7 @@ class TestSubmissionVideo(BaseTestSubmission):
|
||||
manager = VideoProcessingManager()
|
||||
processor = CommonVideoProcessor(manager, entry)
|
||||
acceptable_files = ['original, best_quality', 'webm_144p', 'webm_360p',
|
||||
'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video']
|
||||
'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video']
|
||||
assert processor.acceptable_files == acceptable_files
|
||||
|
||||
|
||||
|
@ -32,6 +32,7 @@ from mediagoblin.media_types.video.transcoders import (capture_thumb,
|
||||
VideoTranscoder)
|
||||
from mediagoblin.media_types.video.util import ACCEPTED_RESOLUTIONS
|
||||
from mediagoblin.media_types.tools import discover
|
||||
from mediagoblin.tests.tools import get_app
|
||||
|
||||
@contextmanager
|
||||
def create_data(suffix=None, make_audio=False):
|
||||
@ -115,6 +116,7 @@ def test_transcoder():
|
||||
transcoder = VideoTranscoder()
|
||||
transcoder.transcode(
|
||||
video_name, result_name,
|
||||
'480p', 1,
|
||||
vp8_quality=8,
|
||||
vp8_threads=0, # autodetect
|
||||
vorbis_quality=0.3,
|
||||
@ -125,6 +127,7 @@ def test_transcoder():
|
||||
transcoder = VideoTranscoder()
|
||||
transcoder.transcode(
|
||||
video_name, result_name,
|
||||
'480p', 1,
|
||||
vp8_quality=8,
|
||||
vp8_threads=0, # autodetect
|
||||
vorbis_quality=0.3,
|
||||
|
Loading…
x
Reference in New Issue
Block a user