コード例 #1
0
 def validate_video_missing_video_stream(self):
     with self.assertRaises(MissingVideoStream):
         validation.validate_video(filename=self._filename,
                                   metadata={
                                       "format": self._format_metadata,
                                       "streams": [self._audio_stream]
                                   })
コード例 #2
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,
        )
コード例 #3
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,
        )
コード例 #4
0
 def test_validate_video_invalid_video_codec(self):
     with self.assertRaises(UnsupportedVideoCodec):
         validation.validate_video(
             metadata={
                 "format":
                 self._format_metadata,
                 "streams": [
                     self._audio_stream, {
                         "codec_type": "video",
                         "codec_name": "unknown"
                     }
                 ]
             })
コード例 #5
0
    def test_validate_video_valid_codecs(self):
        for video_format in self._supported_formats:
            video_codecs = list_supported_video_codecs(video_format)
            audio_codecs = list_supported_audio_codecs(video_format)
            for video_codec in video_codecs:
                for audio_codec in audio_codecs:
                    metadata = {
                        "format": {
                            "format_name": video_format
                        },
                        "streams": [{
                            "codec_type": "video",
                            "codec_name": video_codec
                        }, {
                            "codec_type": "audio",
                            "codec_name": audio_codec
                        }]
                    }

                    self.assertTrue(
                        validation.validate_video(metadata=metadata))
コード例 #6
0
 def test_validate_valid_video(self):
     self.assertTrue(validation.validate_video(metadata=self._metadata))
コード例 #7
0
 def test_validate_video_without_format_metadata(self):
     with self.assertRaises(InvalidFormatMetadata):
         validation.validate_video(
             metadata={"streams": [self._audio_stream, self._video_stream]})
コード例 #8
0
    def test_validate_video_invalid_format(self):
        metadata = dict(self._metadata)
        metadata["format"] = {"format_name": "jpeg"}

        with self.assertRaises(UnsupportedVideoFormat):
            validation.validate_video(metadata=metadata)