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):
|
| 252 | 252 | # metadata itself has container-related data in tags, like video-codec |
| 253 | 253 | store_metadata(self.entry, metadata) |
| 254 | 254 | |
| | 255 | orig_dst_dimensions = (metadata.get_video_streams()[0].get_width(), |
| | 256 | metadata.get_video_streams()[0].get_height()) |
| | 257 | |
| 255 | 258 | # Figure out whether or not we need to transcode this video or |
| 256 | 259 | # if we can skip it |
| 257 | 260 | if skip_transcode(metadata, medium_size): |
| 258 | 261 | _log.debug('Skipping transcoding') |
| 259 | 262 | |
| 260 | | dst_dimensions = (metadata.get_video_streams()[0].get_width(), |
| 261 | | metadata.get_video_streams()[0].get_height()) |
| | 263 | dst_dimensions = orig_dst_dimensions |
| 262 | 264 | |
| 263 | 265 | # If there is an original and transcoded, delete the transcoded |
| 264 | 266 | # since it must be of lower quality then the original |
| … |
… |
class CommonVideoProcessor(MediaProcessor):
|
| 273 | 275 | vorbis_quality=vorbis_quality, |
| 274 | 276 | progress_callback=progress_callback, |
| 275 | 277 | 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 |
| 289 | 295 | |
| 290 | 296 | # Save the width and height of the transcoded video |
| 291 | 297 | self.entry.media_data_init( |
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):
|
| 358 | 358 | _log.info('{percent}% done...'.format(percent=percent)) |
| 359 | 359 | elif message.type == Gst.MessageType.ERROR: |
| 360 | 360 | _log.error('Got error: {0}'.format(message.parse_error())) |
| | 361 | self.dst_data = None |
| 361 | 362 | self.__stop() |
| 362 | 363 | |
| 363 | 364 | def __stop(self): |