Example #1
0
    def test_should_raise_if_multiple_matches_found_in_ffmpeg_output(self):
        sample_ffmpeg_output = ('Muxer 3g2 [3GP2 (3GPP2 file format)]:\n'
                                '   Common extensions: 3g2.\n'
                                '   Default video codec: h263.\n'
                                '   Default audio codec: amr_nb.\n'
                                '   Default audio codec: mp3.\n'
                                '   Default audio codec: amr_nb.\n')

        with mock.patch.object(commands,
                               'exec_cmd_to_string',
                               return_value=sample_ffmpeg_output):
            with self.assertRaises(exceptions.NoMatchingEncoder):
                commands.query_muxer_info(formats.Container.c_3G2)
    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,
        )
Example #4
0
    def test_default_audio_codec_field_should_not_be_omitted_if_codec_name_is_an_empty_string(
            self):
        sample_ffmpeg_output = ('Muxer 3g2 [3GP2 (3GPP2 file format)]:\n'
                                '   Common extensions: 3g2.\n'
                                '   Default audio codec:\n')

        with mock.patch.object(commands,
                               'exec_cmd_to_string',
                               return_value=sample_ffmpeg_output):
            muxer_info = commands.query_muxer_info(formats.Container.c_3G2)
            self.assertIsInstance(muxer_info, dict)
            self.assertEqual(muxer_info['default_audio_codec'], '')
Example #5
0
    def test_default_audio_codec_field_should_be_omitted_if_not_found_in_ffmpeg_output(
            self):
        sample_ffmpeg_output = ('Muxer 3g2 [3GP2 (3GPP2 file format)]:\n'
                                '   Common extensions: 3g2.\n'
                                '   Default video codec: h263.\n')

        with mock.patch.object(commands,
                               'exec_cmd_to_string',
                               return_value=sample_ffmpeg_output):
            muxer_info = commands.query_muxer_info(formats.Container.c_3G2)
            self.assertIsInstance(muxer_info, dict)
            self.assertNotIn('default_audio_codec', muxer_info)
Example #6
0
    def test_function_should_return_valid_encoder(self):
        sample_ffmpeg_output = ('Muxer 3g2 [3GP2 (3GPP2 file format)]:\n'
                                '   Common extensions: 3g2.\n'
                                '   Default video codec: h263.\n'
                                '   Default audio codec: amr_nb.\n'
                                'matroska muxer AVOptions:')

        with mock.patch.object(commands,
                               'exec_cmd_to_string',
                               return_value=sample_ffmpeg_output):
            muxer_info = commands.query_muxer_info(formats.Container.c_3G2)
            self.assertEqual(muxer_info['default_audio_codec'], 'amr_nb')
Example #7
0
 def test_demuxer_should_result_in_default_audio_codec_not_being_found(
         self):
     muxer_info = commands.query_muxer_info(
         formats.Container.c_MATROSKA_WEBM_DEMUXER.value)
     self.assertIsInstance(muxer_info, dict)
     self.assertNotIn('default_audio_codec', muxer_info)
Example #8
0
 def test_muxer_not_recognized_by_ffmpeg_should_result_in_default_audio_codec_not_being_found(
         self):
     muxer_info = commands.query_muxer_info('non_existent_container')
     self.assertIsInstance(muxer_info, dict)
     self.assertNotIn('default_audio_codec', muxer_info)