def test_should_raise_if_sample_rates_are_not_integers(self, input_line): sample_ffmpeg_output = ('some text before sample line \n' f'Supported sample rates: {input_line} \n' 'some text after sample line \n') with mock.patch.object(commands, 'exec_cmd_to_string', return_value=sample_ffmpeg_output): with self.assertRaises(exceptions.InvalidSampleRateInfo): commands.query_encoder_info('mp3')
def test_should_raise_if_multiple_matches_found_in_ffmpeg_output(self): sample_ffmpeg_output = ( 'Encoder libmp3lame [libmp3lame MP3 (MPEG audio layer 3)]:\n' 'Supported sample rates: 44100 48000 32000 22050 24000 16000 11025 12000 8000\n' 'Supported sample rates: 22050 8000\n' 'Supported sample formats: s32p fltp s16p\n') with mock.patch.object(commands, 'exec_cmd_to_string', return_value=sample_ffmpeg_output): with self.assertRaises(exceptions.InvalidSampleRateInfo): commands.query_encoder_info('mp3')
def test_extract_split_transcoding_merge_replace_with_multiple_video_and_audio_streams( self): input_path = os.path.join(self.tmp_dir, 'video.mkv') generate_sample_video([ codecs.VideoCodec.VP8.value, codecs.VideoCodec.MJPEG.value, codecs.AudioCodec.MP3.value, codecs.AudioCodec.AAC.value, codecs.SubtitleCodec.SUBRIP.value, ], input_path, container=formats.Container.c_MATROSKA.value) assert os.path.isfile(input_path) input_metadata = commands.get_metadata_json(input_path) validation.validate_video(input_metadata) transcode_step_targs = { 'container': formats.Container.c_MATROSKA.value, 'frame_rate': '30/1', 'video': { 'codec': codecs.VideoCodec.H_264.value }, 'resolution': [160, 90], } replace_step_targs = { 'audio': { 'codec': codecs.AudioCodec.MP3.value }, } validation.validate_transcoding_params( { **transcode_step_targs, **replace_step_targs }, input_metadata, commands.query_muxer_info(transcode_step_targs['container']), commands.query_encoder_info(codecs.VideoCodec.VP8.get_encoder()), ) self.run_extract_split_transcoding_merge_replace_test( num_segments=5, input_path=input_path, extract_step_output_path=os.path.join(self.work_dirs['extract'], "video[video-only].mkv"), split_step_basename_template="video[video-only]_{}.mkv", transcode_step_basename_template="video[video-only]_{}_TC.mkv", merge_step_output_path=os.path.join(self.work_dirs['merge'], "video[video-only]_TC.mkv"), replace_step_output_path=os.path.join(self.work_dirs['replace'], "video_TC.mkv"), ffconcat_list_path=os.path.join(self.work_dirs['transcode'], "merge-input.ffconcat"), transcode_step_targs=transcode_step_targs, replace_step_targs=replace_step_targs, )
def test_extract_split_transcoding_merge_replace(self): input_path = get_absolute_resource_path( "ForBiggerBlazes-[codec=h264].mp4") input_metadata = commands.get_metadata_json(input_path) validation.validate_video(input_metadata) transcode_step_targs = { 'container': formats.Container.c_MATROSKA.value, 'frame_rate': '25/1', 'video': { 'codec': codecs.VideoCodec.VP8.value, 'bitrate': '1000k', }, 'resolution': [160, 90], 'scaling_alg': 'neighbor', } replace_step_targs = { 'audio': { 'codec': codecs.AudioCodec.MP3.value, 'bitrate': '128k', }, } validation.validate_transcoding_params( { **transcode_step_targs, **replace_step_targs }, input_metadata, commands.query_muxer_info(transcode_step_targs['container']), commands.query_encoder_info(codecs.VideoCodec.VP8.get_encoder()), ) self.run_extract_split_transcoding_merge_replace_test( num_segments=3, input_path=input_path, extract_step_output_path=os.path.join( self.work_dirs['extract'], "ForBiggerBlazes-[codec=h264][video-only].mp4"), split_step_basename_template= "ForBiggerBlazes-[codec=h264][video-only]_{}.mp4", transcode_step_basename_template= "ForBiggerBlazes-[codec=h264][video-only]_{}_TC.mkv", merge_step_output_path=os.path.join( self.work_dirs['merge'], "ForBiggerBlazes-[codec=h264][video-only]_TC.mkv"), replace_step_output_path=os.path.join( self.work_dirs['replace'], "ForBiggerBlazes-[codec=h264]_TC.mkv"), ffconcat_list_path=os.path.join(self.work_dirs['transcode'], "merge-input.ffconcat"), transcode_step_targs=transcode_step_targs, replace_step_targs=replace_step_targs, )
def test_should_not_raise_if_sample_rates_are_integers( self, input_line, expected_rates): sample_ffmpeg_output = ('some text before sample line \n' f'Supported sample rates: {input_line} \n' 'some text after sample line \n') with mock.patch.object(commands, 'exec_cmd_to_string', return_value=sample_ffmpeg_output): encoder_info = commands.query_encoder_info('mp3') self.assertEqual(encoder_info, {'sample_rates': expected_rates})
def test_encoder_not_recognized_by_ffmpeg_should_result_in_sample_rates_not_being_found( self): sample_ffmpeg_output = ( "Codec 'invalid encoder' is not recognized by FFmpeg.\n") with mock.patch.object(commands, 'exec_cmd_to_string', return_value=sample_ffmpeg_output): encoder_info = commands.query_encoder_info('invalid encoder') self.assertIsInstance(encoder_info, dict) self.assertNotIn('sample_rates', encoder_info)
def test_sample_rates_field_should_be_omitted_if_not_found_in_ffmpeg_output( self): sample_ffmpeg_output = ( 'Encoder libx264[libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]:\n' 'General capabilities: delay threads\n' 'Threading capabilities: auto\n') with mock.patch.object(commands, 'exec_cmd_to_string', return_value=sample_ffmpeg_output): encoder_info = commands.query_encoder_info('h264') self.assertEqual(encoder_info, {})
def test_should_return_sample_rates(self): sample_ffmpeg_output = ( 'Encoder libmp3lame [libmp3lame MP3 (MPEG audio layer 3)]:\n' 'General capabilities: delay small\n' 'Threading capabilities: none\n' 'Supported sample rates: 44100 48000 32000 22050 24000 16000 11025 12000 8000\n' 'Supported sample formats: s32p fltp s16p\n' 'Supported channel layouts: mono stereo\n') expected_encoder_info = { 'sample_rates': [44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000] } with mock.patch.object(commands, 'exec_cmd_to_string', return_value=sample_ffmpeg_output): encoder_info = commands.query_encoder_info('mp3') self.assertEqual(encoder_info, expected_encoder_info)