Small changes to fixing transcode percentage

Related to #6
This commit is contained in:
vijeth-aradhya 2017-08-11 19:40:41 +05:30
parent 40f7e8d191
commit 91a7b1226c
2 changed files with 8 additions and 10 deletions

View File

@ -336,13 +336,12 @@ class CommonVideoProcessor(MediaProcessor):
else: else:
_log.debug('Entered transcoder') _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_quality=vp8_quality,
vp8_threads=vp8_threads, vp8_threads=vp8_threads,
vorbis_quality=vorbis_quality, vorbis_quality=vorbis_quality,
progress_callback=progress_callback, progress_callback=progress_callback,
dimensions=tuple(medium_size), dimensions=tuple(medium_size))
media_entry=self.entry)
if self.transcoder.dst_data: if self.transcoder.dst_data:
# Push transcoded video to public storage # Push transcoded video to public storage
_log.debug('Saving medium...') _log.debug('Saving medium...')

View File

@ -155,18 +155,16 @@ class VideoTranscoder(object):
''' '''
def __init__(self): def __init__(self):
_log.info('Initializing VideoTranscoder...') _log.info('Initializing VideoTranscoder...')
self.progress_percentage = None self.progress_percentage = 0
self.loop = GLib.MainLoop() 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. Transcode a video file into a 'medium'-sized version.
''' '''
self.source_path = src self.source_path = src
self.destination_path = dst self.destination_path = dst
self.entry = entry
# Get media entry
self.entry = kwargs.get('media_entry') or None
# vp8enc options # vp8enc options
self.destination_dimensions = kwargs.get('dimensions', (640, 640)) self.destination_dimensions = kwargs.get('dimensions', (640, 640))
@ -192,7 +190,6 @@ class VideoTranscoder(object):
# Get number of resolutions available for the video # 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.num_of_resolutions = len(video_config['available_resolutions'])
self.progress_percentage = 0
if not type(self.destination_dimensions) == tuple: if not type(self.destination_dimensions) == tuple:
raise Exception('dimensions must be tuple: (width, height)') raise Exception('dimensions must be tuple: (width, height)')
@ -364,6 +361,8 @@ class VideoTranscoder(object):
# Update progress state if it has changed # Update progress state if it has changed
(success, percent) = structure.get_int('percent') (success, percent) = structure.get_int('percent')
if self.progress_percentage != percent and success: 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: if self.progress_percentage > percent and percent == 0:
percent = 100 percent = 100
percent_increment = percent - self.progress_percentage percent_increment = percent - self.progress_percentage