def test_transcoder(): # test without audio with create_data() as (video_name, result_name): transcoder = VideoTranscoder() transcoder.transcode( video_name, result_name, vp8_quality=8, vp8_threads=0, # autodetect vorbis_quality=0.3, dimensions=(640, 640), ) assert len(discover(result_name).get_video_streams()) == 1 # test with audio with create_data(make_audio=True) as (video_name, result_name): transcoder = VideoTranscoder() transcoder.transcode( video_name, result_name, vp8_quality=8, vp8_threads=0, # autodetect vorbis_quality=0.3, dimensions=(640, 640), ) assert len(discover(result_name).get_video_streams()) == 1 assert len(discover(result_name).get_audio_streams()) == 1
def test_transcoder(): # test without audio with create_data() as (video_name, result_name): transcoder = VideoTranscoder() transcoder.transcode( video_name, result_name, '480p', 1, vp8_quality=8, vp8_threads=0, # autodetect vorbis_quality=0.3, dimensions=(640, 640)) assert len(discover(result_name).get_video_streams()) == 1 # test with audio with create_data(make_audio=True) as (video_name, result_name): transcoder = VideoTranscoder() transcoder.transcode( video_name, result_name, '480p', 1, vp8_quality=8, vp8_threads=0, # autodetect vorbis_quality=0.3, dimensions=(640, 640)) assert len(discover(result_name).get_video_streams()) == 1 assert len(discover(result_name).get_audio_streams()) == 1
def test_transcoder(): ''' Tests AudioTransocder's transcode method ''' transcoder = AudioTranscoder() with create_data_for_test() as (audio_name, result_name): transcoder.transcode(audio_name, result_name, quality=0.3, progress_callback=None) info = discover(result_name) assert len(info.get_audio_streams()) == 1 transcoder.transcode(audio_name, result_name, quality=0.3, mux_name='oggmux', progress_callback=None) info = discover(result_name) assert len(info.get_audio_streams()) == 1
def _on_message(self, bus, message): _log.debug((bus, message, message.type)) if message.type == Gst.MessageType.EOS: self.dst_data = discover(self.destination_path) self.__stop() _log.info('Done') elif message.type == Gst.MessageType.ELEMENT: if message.has_name('progress'): structure = message.get_structure() # 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 self.progress_percentage = percent if self._progress_callback: if ACCEPTED_RESOLUTIONS[ self. default_resolution] == self.destination_dimensions: self._progress_callback( percent_increment / self.num_of_resolutions, percent) else: self._progress_callback(percent_increment / self.num_of_resolutions) _log.info('{percent}% of {dest} resolution done..' '.'.format(percent=percent, dest=self.destination_dimensions)) elif message.type == Gst.MessageType.ERROR: _log.error('Got error: {}'.format(message.parse_error())) self.dst_data = None self.__stop()
def sniff_handler(media_file, filename): _log.info('Sniffing {0}'.format(MEDIA_TYPE)) try: data = discover(media_file.name) except Exception as e: _log.info(six.text_type(e)) return None if data and data.get_audio_streams() and not data.get_video_streams(): return MEDIA_TYPE return None
def _on_message(self, bus, message): _log.debug((bus, message, message.type)) if message.type == Gst.MessageType.EOS: self.dst_data = discover(self.destination_path) self.__stop() _log.info('Done') elif message.type == Gst.MessageType.ELEMENT: if message.has_name('progress'): structure = message.get_structure() # Update progress state if it has changed (success, percent) = structure.get_int('percent') if self.progress_percentage != percent and success: self.progress_percentage = percent if self._progress_callback: self._progress_callback(percent) _log.info('{percent}% done...'.format(percent=percent)) elif message.type == Gst.MessageType.ERROR: _log.error('Got error: {0}'.format(message.parse_error())) self.__stop()
def transcode(self, src, dst, default_res, num_res, **kwargs): ''' Transcode a video file into a 'medium'-sized version. ''' self.source_path = src self.destination_path = dst # vp8enc options self.destination_dimensions = kwargs.get('dimensions', (640, 640)) self.vp8_quality = kwargs.get('vp8_quality', 8) # Number of threads used by vp8enc: # number of real cores - 1 as per recommendation on # <http://www.webmproject.org/tools/encoder-parameters/#6-multi-threaded-encode-and-decode> self.vp8_threads = kwargs.get('vp8_threads', CPU_COUNT - 1) # 0 means auto-detect, but dict.get() only falls back to CPU_COUNT # if value is None, this will correct our incompatibility with # dict.get() # This will also correct cases where there's only 1 CPU core, see # original self.vp8_threads assignment above. if self.vp8_threads == 0: self.vp8_threads = CPU_COUNT # vorbisenc options self.vorbis_quality = kwargs.get('vorbis_quality', 0.3) self._progress_callback = kwargs.get('progress_callback') or None # Get number of resolutions available for the video self.num_of_resolutions = num_res self.default_resolution = default_res if not type(self.destination_dimensions) == tuple: raise Exception('dimensions must be tuple: (width, height)') self._setup_pipeline() self.data = discover(self.source_path) self._link_elements() self.__setup_videoscale_capsfilter() self.pipeline.set_state(Gst.State.PLAYING) _log.info('Transcoding...') _log.debug('Initializing MainLoop()') self.loop.run()
def transcode(self, src, dst, **kwargs): ''' Transcode a video file into a 'medium'-sized version. ''' self.source_path = src self.destination_path = dst # vp8enc options self.destination_dimensions = kwargs.get('dimensions', (640, 640)) self.vp8_quality = kwargs.get('vp8_quality', 8) # Number of threads used by vp8enc: # number of real cores - 1 as per recommendation on # <http://www.webmproject.org/tools/encoder-parameters/#6-multi-threaded-encode-and-decode> self.vp8_threads = kwargs.get('vp8_threads', CPU_COUNT - 1) # 0 means auto-detect, but dict.get() only falls back to CPU_COUNT # if value is None, this will correct our incompatibility with # dict.get() # This will also correct cases where there's only 1 CPU core, see # original self.vp8_threads assignment above. if self.vp8_threads == 0: self.vp8_threads = CPU_COUNT # vorbisenc options self.vorbis_quality = kwargs.get('vorbis_quality', 0.3) self._progress_callback = kwargs.get('progress_callback') or None if not type(self.destination_dimensions) == tuple: raise Exception('dimensions must be tuple: (width, height)') self._setup_pipeline() self.data = discover(self.source_path) self._link_elements() self.__setup_videoscale_capsfilter() self.pipeline.set_state(Gst.State.PLAYING) _log.info('Transcoding...') _log.debug('Initializing MainLoop()') self.loop.run()