From 3456abe90196d5894fc5f8aa0383d02b894b1f2d Mon Sep 17 00:00:00 2001 From: vijeth-aradhya Date: Thu, 10 Aug 2017 19:32:29 +0530 Subject: [PATCH] Fix percentage reporting Report transcoding_progress as the overall percent of all resolutions. Modify Logging. Closes #6 --- mediagoblin/db/models.py | 4 ++-- mediagoblin/media_types/video/processing.py | 3 ++- mediagoblin/media_types/video/transcoders.py | 20 ++++++++++++++++++-- mediagoblin/processing/__init__.py | 5 ++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index f4644b9f..cc06b12f 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -25,7 +25,7 @@ import datetime from sqlalchemy import Column, Integer, Unicode, UnicodeText, DateTime, \ Boolean, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, \ - SmallInteger, Date, types + SmallInteger, Date, types, Float from sqlalchemy.orm import relationship, backref, with_polymorphic, validates, \ class_mapper from sqlalchemy.orm.collections import attribute_mapped_collection @@ -542,7 +542,7 @@ class MediaEntry(Base, MediaEntryMixin, CommentingMixin): fail_error = Column(Unicode) fail_metadata = Column(JSONEncoded) - transcoding_progress = Column(SmallInteger) + transcoding_progress = Column(Float, default=0) queued_media_file = Column(PathTupleWithSlashes) diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index 66363476..dc7264fc 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -341,7 +341,8 @@ class CommonVideoProcessor(MediaProcessor): vp8_threads=vp8_threads, vorbis_quality=vorbis_quality, progress_callback=progress_callback, - dimensions=tuple(medium_size)) + dimensions=tuple(medium_size), + media_entry=self.entry) 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 2d3392f2..d94bf59f 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -21,8 +21,10 @@ import sys import logging import multiprocessing +from mediagoblin import mg_globals as mgg from mediagoblin.media_types.tools import discover from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ +from .util import ACCEPTED_RESOLUTIONS #os.environ['GST_DEBUG'] = '4,python:4' @@ -163,6 +165,9 @@ class VideoTranscoder(object): self.source_path = src self.destination_path = dst + # Get media entry + self.entry = kwargs.get('media_entry') or None + # vp8enc options self.destination_dimensions = kwargs.get('dimensions', (640, 640)) self.vp8_quality = kwargs.get('vp8_quality', 8) @@ -184,6 +189,11 @@ 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'] + 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)') @@ -354,10 +364,16 @@ class VideoTranscoder(object): # Update progress state if it has changed (success, percent) = structure.get_int('percent') if self.progress_percentage != percent and success: + if self.progress_percentage > percent and percent == 0: + percent = 100 + percent_increment = percent - self.progress_percentage self.progress_percentage = percent if self._progress_callback: - self._progress_callback(percent) - _log.info('{percent}% done...'.format(percent=percent)) + self._progress_callback(percent_increment/self.num_of_resolutions) + _log.info('{percent}% of {dest} resolution done..' + '.'.format(percent=percent, dest=self.destination_dimensions)) + _log.info('{0:.2f}% of all resolutions done' + '...'.format(self.entry.transcoding_progress)) elif message.type == Gst.MessageType.ERROR: _log.error('Got error: {0}'.format(message.parse_error())) self.dst_data = None diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py index 7d407a36..a9d5442b 100644 --- a/mediagoblin/processing/__init__.py +++ b/mediagoblin/processing/__init__.py @@ -41,7 +41,10 @@ class ProgressCallback(object): def __call__(self, progress): if progress: - self.entry.transcoding_progress = progress + if 100 - (self.entry.transcoding_progress + progress) < 0.01: + self.entry.transcoding_progress = 100 + else: + self.entry.transcoding_progress += progress self.entry.save() -- 2.25.1