def __init__(self, media_file, itemid, generation, chunk, media_info, request_path_func): self.media_file = media_file self.in_shutdown = False if chunk is not None: self.time_offset = chunk * TranscodeObject.segment_duration else: self.time_offset = 0 d, a, acodec, rate, v, vcodec, siz = media_info self.generation = generation self.duration = d self.itemid = itemid self.has_audio = a self.audio_codec = acodec self.audio_sample_rate = rate self.has_video = v self.video_codec = vcodec self.video_size = siz # This setting makes the environment global to the app instead of # the subtask. But I guess that's okay. setup_ffmpeg_presets() self.ffmpeg_handle = self.segmenter_handle = None self.transcode_handle = None # NB: Explicitly IPv4, FFmpeg does not understand IPv6. self.sink = TranscodeSinkServer(('127.0.0.1', 0), TranscodeRequestHandler) self.sink.obj = self self.request_path_func = request_path_func # note: nchunks is an estimate only. We don't know how many # chunks there are until we do the actual segmentation. self.nchunks = self.duration / TranscodeObject.segment_duration self.trailer = self.duration % TranscodeObject.segment_duration if self.trailer: self.nchunks += 1 logging.debug('TRANSCODE INFO, duration %s' % self.duration) logging.debug('TRANSCODE INFO, nchunks %s' % self.nchunks) logging.debug('TRANSCODE INFO, trailer %s' % self.trailer) if chunk is not None: self.current_chunk = self.start_chunk = chunk else: self.current_chunk = self.start_chunk = 0 self.chunk_buffer = [] self.chunk_throttle = threading.Event() self.chunk_throttle.set() self.chunk_lock = threading.Lock() self.chunk_sem = threading.Semaphore(0) self.tmp_file = tempfile.TemporaryFile() self.finished = False self.transcode_gate = threading.Event() self.create_playlist() logging.debug('TranscodeObject created %s', self)
def convert(converter_id, item_info, update_last=False): """Given a converter and an item, this starts the conversion for that item. """ conversion_manager.start_conversion(converter_id, item_info) if update_last: conversion_manager.set_last_conversion(converter_id) @eventloop.as_idle def _create_item_for_conversion(filename, source_info, conversion_name): """Make a new FileItem for a converted file.""" # Note: We are adding things to the database. This function # should only get called in the event loop. name = _('%(original_name)s (Converted to %(format)s)', {'original_name': source_info.name, 'format': conversion_name}) fp_values = item.fp_values_for_file(filename, name, source_info.description) manual_feed = models.Feed.get_manual_feed() models.FileItem(filename, feed_id=manual_feed.id, fp_values=fp_values) # FIXME - this should be in an init() and not module-level utils.setup_ffmpeg_presets() conversion_manager = ConversionManager()
def convert(converter_id, item_info, update_last=False): """Given a converter and an item, this starts the conversion for that item. """ conversion_manager.start_conversion(converter_id, item_info) if update_last: conversion_manager.set_last_conversion(converter_id) @eventloop.as_idle def _create_item_for_conversion(filename, source_info, conversion_name): """Make a new FileItem for a converted file.""" # Note: We are adding things to the database. This function # should only get called in the event loop. name = _('%(original_name)s (Converted to %(format)s)', { 'original_name': source_info.title, 'format': conversion_name }) fp_values = item.fp_values_for_file(filename, name, source_info.description) manual_feed = models.Feed.get_manual_feed() models.FileItem(filename, feed_id=manual_feed.id, fp_values=fp_values) # FIXME - this should be in an init() and not module-level utils.setup_ffmpeg_presets() conversion_manager = ConversionManager()