def __init__(self, name, encoderArguments, destdir=None, ffmpegbin=None): """ Args: name: Name of this quality (Used in path names) encoderArguments: :class:`configobj.ConfigObj` with valid ffmpeg options. This will be passed to a new :class:`FFMpeg` object. destdir: The location where files will be saved. ffmpegbin: Path to ffmpeg binary. """ super(HTTPLiveVariantStream, self).__init__(name=name) self.name = name """Name of this variant""" self.encoder = None """The :class:`FFMpeg` object used for encoding""" self.segmenter = None """The :class:`HTTPLiveSegmenter` object used for segmenting""" self.destinationDirectory = None self.setDestdir(destdir) # Set up the encoder if ffmpegbin: self.encoder = FFMpeg(ffmpegbin=ffmpegbin, encoderArguments=encoderArguments) else: self.encoder = FFMpeg(encoderArguments=encoderArguments) self.segmenter = HTTPLiveSegmenter(name=self.name + "_segmenter", destdir=self.destinationDirectory) # Hook everything up self.addOutlet(self.encoder) self.encoder.addOutlet(self.segmenter)
def __init__(self, ffmpeg_path=None, ffprobe_path=None): """ Initialize a new Converter object. """ self.ffmpeg = FFMpeg(ffmpeg_path=ffmpeg_path, ffprobe_path=ffprobe_path) self.video_codecs = {} self.audio_codecs = {} self.subtitle_codecs = {} self.formats = {} for cls in audio_codec_list: name = cls.codec_name self.audio_codecs[name] = cls for cls in video_codec_list: name = cls.codec_name self.video_codecs[name] = cls for cls in subtitle_codec_list: name = cls.codec_name self.subtitle_codecs[name] = cls for cls in format_list: name = cls.format_name self.formats[name] = cls
def test_ffmpeg_live_output(self): f = FFMpeg() p = Popen('ffmpeg', stderr=PIPE, stdin=PIPE, stdout=PIPE) generator = f._ffmpeg_live_output(p) for line in generator: first_line = line break self.assertIn('ffmpeg version 3.2', first_line)
def test_get_media_type(self): # instantiate the class f = FFMpeg() self.assertEqual(f.get_media_type('test.mp4'), { 'audio': True, 'video': True }) self.assertEqual(f.get_media_type('test.aac'), {'audio': True}) self.assertEqual(f.get_media_type('noaudio.mp4'), {'video': True})
def start(self, request): super().start() inst = FFMpeg(self, request.user_agent, codes_folder, avc_table, hevc_table) inst.process(request) #TODO: Should the media itself keep track of the instances it has started? #Probably #Later #This would require us to remove this start and ask the MediaDirectory class to start a file return inst
def test_get_extension(self): f = FFMpeg() audio_extension = f._get_extension('test.aac', 'audio') mp3_extension = f._get_extension('test.mp3', 'audio') video_extension = f._get_extension('test.mp4', 'video') avi_extension = f._get_extension('test.avi', 'video') self.assertEqual(audio_extension, 'aac') self.assertEqual(mp3_extension, 'mp3') self.assertEqual(video_extension, 'mp4') self.assertEqual(avi_extension, 'avi')
def test_add_audio_to_video(self): # test if method can add an audio stream # to a video file which does not have one f = FFMpeg(verbose=False) v = VideoFFMpeg(verbose=False) v.add_audio_to_video('noaudio.mp4', 'gotaudio.mp4', 'test.aac') # get the second stream stream = f.probe('gotaudio.mp4').streams[1] self.assertEqual(stream.codec.codec_type, 'audio') # unlink the output video file if os.path.exists('gotaudio.mp4'): os.unlink('gotaudio.mp4')
def test_parse_codec_line(self): f = FFMpeg() features, codec_name, desc = ['DES...', 'xsub', 'XSUB'] codec = f._parse_codec_line(features, codec_name, desc) _codec = { 'xsub': { 'encoding': True, 'codec_type': 'subtitle', 'description': 'XSUB', 'decoding': True } } self.assertIsInstance(codec, dict) self.assertDictEqual(codec, _codec)
def test_list_codecs(self): f = FFMpeg() codecs = f.list_codecs() codec = codecs[0] _codec = { '012v': { 'codec_type': 'video', 'decoding': True, 'description': 'Uncompressed 4:2:2 10-bit', 'intraframe_only': True } } self.assertIsInstance(codecs, list) self.assertIsInstance(codec, dict) self.assertEqual(414, len(codecs)) self.assertDictEqual(codec, _codec)
def run(self): inputfile = self.inputEdit.displayText() for index, segment in enumerate(self.segments): timestamps = {} filenames = {} filenames['input'] = inputfile filenames['output'] = segment['name'].displayText() try: timestamps['start'] = utils.parse_time( segment['start'].displayText()) timestamps['end'] = utils.parse_time( segment['end'].displayText()) except ValueError: QMessageBox.about(self, 'Error', 'Segment %d is invalid.' % (index + 1)) return FFMpeg(filenames, timestamps, path=self.ffmpeg_path).run()
def test_ffmpeg_probe(self): # instantiate the FFMpeg object f = FFMpeg() self.assertEqual(f.probe('nonexistent'), None) self.assertEqual(f.probe(''), None) info = f.probe('test.mp4') format_info = info.format_info streams = info.streams self.assertEqual(len(streams), 2) self.assertEqual(format_info.get('nb_streams'), '2') self.assertEqual(format_info.get('nb_programs'), '0') self.assertEqual(format_info.get('bit_rate'), '1452696') self.assertAlmostEqual(float(format_info.get('duration')), 293.63, places=0) # get the video stream and create tests for it v_stream = streams[0] self.assertEqual(v_stream.height, '720') self.assertEqual(v_stream.width, '1280') self.assertEqual(v_stream.codec.codec_type, 'video') self.assertEqual(v_stream.codec.codec_name, 'h264') self.assertEqual(v_stream.codec.codec_tag_string, 'avc1') self.assertEqual(v_stream.codec.codec_tag, '0x31637661') # get the audio stream and create tests for it a_stream = streams[1] self.assertEqual(a_stream.height, None) self.assertEqual(a_stream.width, None) self.assertAlmostEqual(float(a_stream.duration), 293.63, places=0) self.assertEqual(a_stream.codec.codec_long_name, 'AAC (Advanced Audio Coding)') self.assertEqual(a_stream.codec.codec_name, 'aac') self.assertEqual(a_stream.codec.codec_type, 'audio') self.assertEqual(a_stream.codec.codec_tag_string, 'mp4a') self.assertEqual(a_stream.codec.codec_tag, '0x6134706d')
def test_ffmpeg_binary_paths(self): f = FFMpeg() self.assertIsNotNone(f.ffmpeg_path) self.assertIsNotNone(f.ffprobe_path)