Fix percentage reporting
Report transcoding_progress as the overall percent of all resolutions. Modify Logging. Closes #6
This commit is contained in:
parent
a0fa4b4bb2
commit
3456abe901
@ -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)
|
||||
|
||||
|
@ -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...')
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user