Ejemplo n.º 1
0
    def assert_same_video_duration(self, source_video_path,
                                   transcoded_video_path):
        source_metadata = commands.get_metadata_json(source_video_path)
        transcoded_metadata = commands.get_metadata_json(transcoded_video_path)

        self.assertEqual(round(meta.get_duration(transcoded_metadata)),
                         round(meta.get_duration(source_metadata)))
Ejemplo n.º 2
0
    def assert_video_metadata(
        self,
        video_path,
        transcode_step_targs,
        replace_step_targs,
    ):
        metadata = commands.get_metadata_json(video_path)

        num_video_streams = meta.count_streams(metadata, 'video')
        num_audio_streams = meta.count_streams(metadata, 'audio')

        expected_demuxer = formats.Container(
            transcode_step_targs['container']).get_demuxer()
        self.assertEqual(meta.get_format(metadata), expected_demuxer)
        self.assertEqual(meta.get_codecs(metadata, 'video'),
                         [transcode_step_targs['video']['codec']] *
                         num_video_streams)
        self.assertEqual(meta.get_resolutions(metadata),
                         [transcode_step_targs['resolution']] *
                         num_video_streams)
        self.assertEqual(meta.get_frame_rates(metadata),
                         [transcode_step_targs['frame_rate']] *
                         num_video_streams)
        self.assertEqual(meta.get_codecs(metadata, 'audio'),
                         [replace_step_targs['audio']['codec']] *
                         num_audio_streams)
Ejemplo n.º 3
0
    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,
        )
Ejemplo n.º 4
0
    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,
        )
Ejemplo n.º 5
0
    def run_split_step(self, input_path, work_dir, num_segments):
        input_metadata = commands.get_metadata_json(input_path)
        input_duration = meta.get_duration(input_metadata)
        input_demuxer = meta.get_format(input_metadata)
        output_muxer = formats.get_safe_intermediate_format_for_demuxer(
            input_demuxer)

        segment_list_path = commands.split_video(input_path, work_dir,
                                                 input_duration / num_segments,
                                                 output_muxer)

        return segment_list_path