def test_replace_streams_command_validates_stream_type(self): with self.assertRaises(exceptions.InvalidArgument): commands.replace_streams_command( get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mp4'), get_absolute_resource_path( 'ForBiggerBlazes-[codec=h264][video-only].mkv'), get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mkv'), "v:1", {}, )
def test_replace_streams_command_does_not_accept_video_parameters(self): with self.assertRaises(exceptions.InvalidArgument): commands.replace_streams_command( get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mp4'), get_absolute_resource_path( 'ForBiggerBlazes-[codec=h264][video-only].mkv'), get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mkv'), "v", { 'video': { 'codec': 'h264', 'bitrate': '1000k', }, })
def test_replace_streams_command_should_leave_converting_subtitles_up_to_ffmpeg_if_no_container_specified( self, _mock_find_stream_indexes, _mock_count_streams, _mock_get_metadata_json): command = commands.replace_streams_command( input_file='input.mp4', replacement_source='input[video-only].mkv', output_file='output.mkv', stream_type="v", targs={}, container=None, strip_unsupported_data_streams=False, strip_unsupported_subtitle_streams=False, ) expected_command = [ "ffmpeg", "-nostdin", "-i", 'input.mp4', "-i", 'input[video-only].mkv', "-map", "1:v", "-map", "0", "-map", "-0:v", "-copy_unknown", "-c:v", "copy", "-c:d", "copy", 'output.mkv', ] self.assertEqual(command, expected_command)
def test_replace_streams_command_should_convert_unstripped_subtitle_streams( self, _mock_select_subtitle_conversions, _mock_find_stream_indexes, _mock_count_streams, _mock_get_metadata_json, ): command = commands.replace_streams_command( input_file='input.mp4', replacement_source='input[video-only].mkv', output_file='output.mkv', stream_type="v", targs={}, container='matroska', strip_unsupported_data_streams=False, strip_unsupported_subtitle_streams=False, ) expected_command = [ "ffmpeg", "-nostdin", "-i", 'input.mp4', "-i", 'input[video-only].mkv', "-map", "1:v", "-map", "0", "-map", "-0:v", "-codec:1", "subrip", "-codec:2", "ass", "-codec:3", "mov_text", "-codec:7", "ass", "-copy_unknown", "-c:v", "copy", "-c:d", "copy", "-f", "matroska", 'output.mkv', ] self.assertEqual(command, expected_command)
def test_replace_streams_command_removes_streams_not_in_whitelist_if_asked_to( self, _mock_find_unsupported_subtitle_streams, _mock_find_unsupported_data_streams, _mock_get_metadata_json, ): command = commands.replace_streams_command( get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mp4'), get_absolute_resource_path( 'ForBiggerBlazes-[codec=h264][video-only].mkv'), get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mkv'), "v", {}, strip_unsupported_data_streams=True, strip_unsupported_subtitle_streams=True) expected_command = [ "ffmpeg", "-nostdin", "-i", get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mp4'), "-i", get_absolute_resource_path( 'ForBiggerBlazes-[codec=h264][video-only].mkv'), "-map", "1:v", "-map", "0", "-map", "-0:v", '-map', '-0:2', '-map', '-0:3', "-copy_unknown", "-c:v", "copy", "-c:d", "copy", get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mkv'), ] self.assertEqual(command, expected_command)
def test_replace_streams_command(self, _mock_get_metadata_json): command = commands.replace_streams_command( get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mp4'), get_absolute_resource_path( 'ForBiggerBlazes-[codec=h264][video-only].mkv'), get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mkv'), "v", {'audio': { 'codec': 'mp3', 'bitrate': '128k', }}, ) expected_command = [ "ffmpeg", "-nostdin", "-i", get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mp4'), "-i", get_absolute_resource_path( 'ForBiggerBlazes-[codec=h264][video-only].mkv'), "-map", "1:v", "-map", "0", "-map", "-0:v", "-copy_unknown", "-c:v", "copy", "-c:d", "copy", "-c:a", codecs.AudioCodec.get_encoder(codecs.AudioCodec.MP3), "-b:a", "128k", get_absolute_resource_path('ForBiggerBlazes-[codec=h264].mkv'), ] self.assertEqual(command, expected_command)
def test_replace_streams_command_should_generate_correct_output_stream_indexes_when_some_streams_are_being_stripped( self, _mock_select_subtitle_conversions, _mock_find_unsupported_subtitle_streams, _mock_find_unsupported_data_streams, _mock_find_stream_indexes, _mock_count_streams, _mock_get_metadata_json, ): command = commands.replace_streams_command( input_file='input.mp4', replacement_source='input[video-only].mkv', output_file='output.mkv', stream_type="v", targs={}, container='matroska', strip_unsupported_data_streams=True, strip_unsupported_subtitle_streams=True, ) expected_command = [ "ffmpeg", "-nostdin", "-i", 'input.mp4', "-i", 'input[video-only].mkv', "-map", "1:v", "-map", "0", "-map", "-0:v", '-map', '-0:1', '-map', '-0:7', '-map', '-0:14', '-map', '-0:3', '-map', '-0:9', '-map', '-0:13', "-codec:2", "subrip", "-codec:4", "ass", "-codec:5", "mov_text", "-codec:6", "ass", "-copy_unknown", "-c:v", "copy", "-c:d", "copy", "-f", "matroska", 'output.mkv', ] self.assertEqual(command, expected_command)