From 91a7b1226cb95a8d61f7cc19be56ae472289639c Mon Sep 17 00:00:00 2001 From: vijeth-aradhya Date: Fri, 11 Aug 2017 19:40:41 +0530 Subject: [PATCH] Small changes to fixing transcode percentage Related to #6 --- mediagoblin/media_types/video/processing.py | 5 ++--- mediagoblin/media_types/video/transcoders.py | 13 ++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index e343930b..114c5057 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -336,13 +336,12 @@ class CommonVideoProcessor(MediaProcessor): else: _log.debug('Entered transcoder') - self.transcoder.transcode(self.process_filename, tmp_dst, + self.transcoder.transcode(self.process_filename, tmp_dst, self.entry, vp8_quality=vp8_quality, vp8_threads=vp8_threads, vorbis_quality=vorbis_quality, progress_callback=progress_callback, - dimensions=tuple(medium_size), - media_entry=self.entry) + dimensions=tuple(medium_size)) if self.transcoder.dst_data: # Push transcoded video to public storage _log.debug('Saving medium...') diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index d94bf59f..a2c8f431 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -155,18 +155,16 @@ class VideoTranscoder(object): ''' def __init__(self): _log.info('Initializing VideoTranscoder...') - self.progress_percentage = None + self.progress_percentage = 0 self.loop = GLib.MainLoop() - def transcode(self, src, dst, **kwargs): + def transcode(self, src, dst, entry, **kwargs): ''' Transcode a video file into a 'medium'-sized version. ''' self.source_path = src self.destination_path = dst - - # Get media entry - self.entry = kwargs.get('media_entry') or None + self.entry = entry # vp8enc options self.destination_dimensions = kwargs.get('dimensions', (640, 640)) @@ -190,9 +188,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'] + video_config = mgg.global_config['plugins']['mediagoblin.media_types.video'] self.num_of_resolutions = len(video_config['available_resolutions']) - self.progress_percentage = 0 if not type(self.destination_dimensions) == tuple: raise Exception('dimensions must be tuple: (width, height)') @@ -364,6 +361,8 @@ class VideoTranscoder(object): # Update progress state if it has changed (success, percent) = structure.get_int('percent') if self.progress_percentage != percent and success: + # FIXME: the code below is a workaround for structure.get_int('percent') + # returning 0 when the transcoding gets over (100%) if self.progress_percentage > percent and percent == 0: percent = 100 percent_increment = percent - self.progress_percentage -- 2.25.1