def test_video_defaults(self): """Ensure that default video options are properly generated.""" built = Stream(1, 'video', FAKE_CODEC) assert built.build_options() == [ '-c:v:0', 'libx264', '-preset', defaults.PRESET, '-crf', str(defaults.CRF), '-pix_fmt', 'yuv420p' ]
def test_subtitle_transcode(self): """Ensure that subtitle options are properly generated for transcoding.""" built = Stream(1, 'subtitle', FAKE_CODEC) assert built.build_options() == ['-c:s:0', defaults.C_SUBS] assert built.option_summary == ('transcode -> {}'.format( defaults.C_SUBS))
def test_stream_ops_transcode_num(self): """Ensure that Stream.build_options properly includes the stream number when generating stream transcoding options.""" for number in range(0, 10, 3): for stream_type in ['audio', 'video', 'subtitle']: built = Stream(number // 2, stream_type, FAKE_CODEC) options = built.build_options(number) assert options[0].split(':')[-1] == str(number)
def test_audio_defaults(self): """Ensure that default audio options are properly generated.""" built = Stream(4, 'audio', FAKE_CODEC) assert built.build_options() == [ '-c:a:0', defaults.C_AUDIO, '-b:a:0', str(defaults.BITRATE) + 'k' ] assert built.option_summary == ( 'transcode -> {}, bitrate={}Kib/s'.format(defaults.C_AUDIO, defaults.BITRATE))
def test_video_custom_crf(self): """Ensure that video options are properly generated with a custom crf.""" crf = 11 built = Stream(2, 'video', FAKE_CODEC, custom_crf=crf) assert built.build_options() == [ '-c:v:0', 'libx264', '-preset', defaults.PRESET, '-crf', str(crf), '-pix_fmt', 'yuv420p' ] assert built.option_summary == ('transcode -> {}, crf={}'.format( defaults.C_VIDEO, crf))
def test_stream_options_copy_number(self): """Ensure that Stream.build_options properly includes the stream number when generating stream copying options.""" for number in range(0, 10, 3): for stream_type, default in { 'audio': defaults.C_AUDIO, 'video': defaults.C_VIDEO, 'subtitle': defaults.C_SUBS }.items(): built = Stream(number // 2, stream_type, default) options = built.build_options(number) assert options[0].split(':')[-1] == str(number)
def test_audio_custom_bitrate(self): """Ensure that audio options are properly generated with a custom bitrate.""" bitrate = 512 built = Stream(5, 'audio', FAKE_CODEC, custom_bitrate=bitrate) assert built.build_options() == [ '-c:a:0', defaults.C_AUDIO, '-b:a:0', str(bitrate) + 'k' ] assert built.option_summary == ( 'transcode -> {}, bitrate={}Kib/s'.format(defaults.C_AUDIO, bitrate))
def test_audio_labels_bitrate(self): """Ensure that audio options are properly generated when using the labels bitrate.""" bitrate = 256 labels = StreamLabel(bitrate=bitrate) built = Stream(2, 'audio', FAKE_CODEC, labels=labels) assert built.build_options() == [ '-c:a:0', defaults.C_AUDIO, '-b:a:0', str(bitrate) + 'k' ] assert built.option_summary == ( 'transcode -> {}, bitrate={}Kib/s'.format(defaults.C_AUDIO, bitrate))
def test_minimal(self): """Ensure that optional and instance Stream attrs are properly instantiated.""" built = Stream(2, 'audio', 'mp3') attrs = { 'custom_crf': None, 'custom_bitrate': None, 'option_summary': None, 'labels': StreamLabel() } for attr, value in attrs.items(): assert getattr(built, attr) == value
def other_audio_stream(): """Return an example Stream that should match the non-default audio stream from example.json.""" return Stream(2, 'audio', 'opus', '', '', other_audio_streamlabel())
def example_audio_stream(): """Return an example Stream which should match the default audio stream from example.json.""" return Stream(1, 'audio', 'vorbis', '', '', example_audio_streamlabel())
def test_subtitle_copy(self): """Ensure that subtitle options are properly generated for copying.""" built = Stream(3, 'subtitle', defaults.C_SUBS) assert built.build_options() == ['-c:s:0', 'copy'] assert built.option_summary == 'copy'
def test_match_example_video(self, example_video_stream): """Ensure that the example audio instance matches one built from example.json.""" built = Stream.from_dict(EXAMPLE['streams'][0]) assert example_video_stream == built
def test_audio_copy(self): """Ensure that audio options are properly generated for copying.""" test = Stream(3, 'audio', defaults.C_AUDIO) assert test.build_options() == ['-c:a:0', 'copy'] assert test.option_summary == 'copy'
def test_match_example_sub(self, example_sub_stream): """Ensure that the example subtitle instance matches one built from example.json.""" built = Stream.from_dict(EXAMPLE['streams'][3]) assert example_sub_stream == built
def example_video_stream(): """Return an example Stream which should match the video stream from example.json.""" return Stream(0, 'video', 'vp8', '', '', example_video_streamlabel())
def example_sub_stream(): """Return an example Stream which should match the subtitle stream from example.json.""" return Stream(3, 'subtitle', 'subrip', '', '', example_sub_streamlabel())
def test_video_copy(self): """Ensure that video options are properly generated for copying.""" built = Stream(2, 'video', defaults.C_VIDEO) assert built.build_options() == ['-c:v:0', 'copy'] assert built.option_summary == 'copy'