From bd50f8bf701d3719b349523fa0822ed4958a9531 Mon Sep 17 00:00:00 2001 From: Boris Bobrov Date: Sat, 7 Mar 2015 13:30:43 +0300 Subject: [PATCH] Prevent exception on transcoding failure (bug 460) Fix an unhandled exception when video fails to transcode for some reason. Closes bug 460. --- mediagoblin/media_types/video/processing.py | 36 ++++++++++++-------- mediagoblin/media_types/video/transcoders.py | 1 + 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index bf195222..a85b232c 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -252,13 +252,15 @@ class CommonVideoProcessor(MediaProcessor): # metadata itself has container-related data in tags, like video-codec store_metadata(self.entry, metadata) + orig_dst_dimensions = (metadata.get_video_streams()[0].get_width(), + metadata.get_video_streams()[0].get_height()) + # Figure out whether or not we need to transcode this video or # if we can skip it if skip_transcode(metadata, medium_size): _log.debug('Skipping transcoding') - dst_dimensions = (metadata.get_video_streams()[0].get_width(), - metadata.get_video_streams()[0].get_height()) + dst_dimensions = orig_dst_dimensions # If there is an original and transcoded, delete the transcoded # since it must be of lower quality then the original @@ -273,19 +275,23 @@ class CommonVideoProcessor(MediaProcessor): vorbis_quality=vorbis_quality, progress_callback=progress_callback, dimensions=tuple(medium_size)) - video_info = self.transcoder.dst_data.get_video_streams()[0] - dst_dimensions = (video_info.get_width(), video_info.get_height()) - self._keep_best() - - # Push transcoded video to public storage - _log.debug('Saving medium...') - store_public(self.entry, 'webm_video', tmp_dst, - self.name_builder.fill('{basename}.medium.webm')) - _log.debug('Saved medium') - - self.entry.set_file_metadata('webm_video', **file_metadata) - - self.did_transcode = True + if self.transcoder.dst_data: + video_info = self.transcoder.dst_data.get_video_streams()[0] + dst_dimensions = (video_info.get_width(), + video_info.get_height()) + self._keep_best() + + # Push transcoded video to public storage + _log.debug('Saving medium...') + store_public(self.entry, 'webm_video', tmp_dst, + self.name_builder.fill('{basename}.medium.webm')) + _log.debug('Saved medium') + + self.entry.set_file_metadata('webm_video', **file_metadata) + + self.did_transcode = True + else: + dst_dimensions = orig_dst_dimensions # Save the width and height of the transcoded video self.entry.media_data_init( diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index 3c060fd7..ba469af2 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -358,6 +358,7 @@ class VideoTranscoder(object): _log.info('{percent}% done...'.format(percent=percent)) elif message.type == Gst.MessageType.ERROR: _log.error('Got error: {0}'.format(message.parse_error())) + self.dst_data = None self.__stop() def __stop(self): -- 2.25.1