Ticket #460: issue_460_2.patch

File issue_460_2.patch, 3.8 KB (added by Boris Bobrov, 10 years ago)
  • mediagoblin/media_types/video/processing.py

    From b2833c310a470f72bc939f4c4579ecac641cc059 Mon Sep 17 00:00:00 2001
    From: Boris Bobrov <breton@cynicmansion.ru>
    Date: Sat, 7 Mar 2015 13:30:43 +0300
    Subject: [PATCH] Prevent exception on transcoding failure
    
    Fix an unhandled exception when video fails to transcode for some
    reason
    ---
     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 bf19522..a85b232 100644
    a b class CommonVideoProcessor(MediaProcessor):  
    252252        # metadata itself has container-related data in tags, like video-codec
    253253        store_metadata(self.entry, metadata)
    254254
     255        orig_dst_dimensions = (metadata.get_video_streams()[0].get_width(),
     256                metadata.get_video_streams()[0].get_height())
     257
    255258        # Figure out whether or not we need to transcode this video or
    256259        # if we can skip it
    257260        if skip_transcode(metadata, medium_size):
    258261            _log.debug('Skipping transcoding')
    259262
    260             dst_dimensions = (metadata.get_video_streams()[0].get_width(),
    261                     metadata.get_video_streams()[0].get_height())
     263            dst_dimensions = orig_dst_dimensions
    262264
    263265            # If there is an original and transcoded, delete the transcoded
    264266            # since it must be of lower quality then the original
    class CommonVideoProcessor(MediaProcessor):  
    273275                                      vorbis_quality=vorbis_quality,
    274276                                      progress_callback=progress_callback,
    275277                                      dimensions=tuple(medium_size))
    276             video_info = self.transcoder.dst_data.get_video_streams()[0]
    277             dst_dimensions = (video_info.get_width(), video_info.get_height())
    278             self._keep_best()
    279 
    280             # Push transcoded video to public storage
    281             _log.debug('Saving medium...')
    282             store_public(self.entry, 'webm_video', tmp_dst,
    283                          self.name_builder.fill('{basename}.medium.webm'))
    284             _log.debug('Saved medium')
    285 
    286             self.entry.set_file_metadata('webm_video', **file_metadata)
    287 
    288             self.did_transcode = True
     278            if self.transcoder.dst_data:
     279                video_info = self.transcoder.dst_data.get_video_streams()[0]
     280                dst_dimensions = (video_info.get_width(),
     281                                  video_info.get_height())
     282                self._keep_best()
     283
     284                # Push transcoded video to public storage
     285                _log.debug('Saving medium...')
     286                store_public(self.entry, 'webm_video', tmp_dst,
     287                             self.name_builder.fill('{basename}.medium.webm'))
     288                _log.debug('Saved medium')
     289
     290                self.entry.set_file_metadata('webm_video', **file_metadata)
     291
     292                self.did_transcode = True
     293            else:
     294                dst_dimensions = orig_dst_dimensions
    289295
    290296        # Save the width and height of the transcoded video
    291297        self.entry.media_data_init(
  • mediagoblin/media_types/video/transcoders.py

    diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py
    index 3c060fd..ba469af 100644
    a b class VideoTranscoder(object):  
    358358                    _log.info('{percent}% done...'.format(percent=percent))
    359359        elif message.type == Gst.MessageType.ERROR:
    360360            _log.error('Got error: {0}'.format(message.parse_error()))
     361            self.dst_data = None
    361362            self.__stop()
    362363
    363364    def __stop(self):