Ejemplo n.º 1
0
    def test_audio_convert(self, mock_subprocess):
        MediaConverter(AudioTrack('a.wav', codecs.AAC('256k', 2, 44100)), 'a.m4a').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.wav',
               '-map', '0:a:0', '-c:a:0', 'aac', '-b:a', '256k', '-ac', '2', '-ar', '44100',
               '-threads', '0', 'a.m4a']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 2
0
    def test_silent_audio_for_10_secs(self, mock_subprocess):
        MediaConverter([AudioTrack(None, codecs.AAC('256k', 2, 48000))], 'b.m4a').convert(duration=10)

        cmd = ['/somewhere/ffmpeg', '-y',
               '-ar', '48000', '-ac', '1', '-f', 's16le', '-i', '/dev/zero',
               '-map', '0:a:0', '-c:a:0', 'aac', '-b:a', '256k', '-ac', '2', '-ar', '48000', '-t', '10',
               '-threads', '0', 'b.m4a']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 3
0
    def test_h265_with_ac3(self, mock_subprocess):
        MediaConverter([VideoTrack('a.mkv', codecs.H265(constant_rate_factor=18, preset='slow')),
                        AudioTrack('a.mkv', codecs.AC3('448k', 6, 48000))], 'b.mp4').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mkv',
               '-map', '0:v:0', '-c:v:0', 'libx265', '-preset', 'slow', '-x265-params', 'crf=18',
               '-map', '0:a:0', '-c:a:0', 'ac3', '-b:a', '448k', '-ac', '6', '-ar', '48000',
               '-threads', '0', 'b.mp4']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 4
0
    def test_video_convert(self, mock_subprocess):
        MediaConverter([VideoTrack('a.mp4', codecs.MPEG2('3000k', '16:9', '23.97')),
                        AudioTrack('a.mp4', codecs.MP2('256k', 2, 44100))], 'b.mkv').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mp4',
               '-map', '0:v:0', '-c:v:0', 'mpeg2video', '-b:v', '3000k', '-aspect', '16:9', '-r', '23.97',
               '-map', '0:a:0', '-c:a:0', 'mp2', '-b:a', '256k', '-ac', '2', '-ar', '44100',
               '-threads', '0', 'b.mkv']
        mock_subprocess.assert_called_with(cmd)
    def tracks(self):
        for track in self._tracks:
            if isinstance(track, Track):
                yield track
                continue

            for codec in self._get_default_codecs():
                if isinstance(codec, VideoCodec):
                    yield VideoTrack(track, codec)
                elif isinstance(codec, AudioCodec):
                    yield AudioTrack(track, codec)
Ejemplo n.º 6
0
    def test_convert_to_480p(self, mock_subprocess):
        vos = VideoOutstream('a.mp4').scale(height=480)
        MediaConverter([VideoTrack(vos, codecs.MPEG2('3000k', '16:9', '23.97')),
                        AudioTrack('a.mp4', codecs.AAC('256k', 2, 44100))], 'b.mkv').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mp4',
               '-filter_complex', '[0:v:0]scale=-2:480[vout0]',
               '-map', '[vout0]', '-c:v:0', 'mpeg2video', '-b:v', '3000k', '-aspect', '16:9', '-r', '23.97',
               '-map', '0:a:0', '-c:a:0', 'aac', '-b:a', '256k', '-ac', '2', '-ar', '44100',
               '-threads', '0', 'b.mkv']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 7
0
    def test_copy(self, mock_subprocess):
        MediaConverter([VideoTrack('a.mkv', codecs.Copy()),
                        AudioTrack('a.mkv', codecs.Copy()),
                        SubtitleTrack('a.mkv', codecs.Copy())], 'b.mkv').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mkv',
               '-map', '0:v:0', '-c:v:0', 'copy',
               '-map', '0:a:0', '-c:a:0', 'copy',
               '-map', '0:s:0', '-c:s:0', 'copy',
               '-threads', '0', 'b.mkv']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 8
0
    def test_blank_video_with_audio(self, mock_subprocess):
        MediaConverter([VideoTrack(None, codecs.H264()),
                        AudioTrack('a.mp3', codecs.AAC())], 'b.mp4').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-s', '640x360', '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-r', '30', '-i', '/dev/zero',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mp3',
               '-map', '0:v:0', '-c:v:0', 'h264', '-crf', '23', '-pix_fmt', 'yuv420p',
               '-profile:v', 'high', '-level', '3.1',
               '-map', '1:a:0', '-c:a:0', 'aac', '-b:a', '192k', '-ac', '2', '-ar', '44100',
               '-shortest',
               '-threads', '0', 'b.mp4']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 9
0
    def test_multiple_video_filters(self, mock_subprocess):
        vos = VideoOutstream('a.mp4').deinterlace().scale(width=1920)
        MediaConverter([VideoTrack(vos, codecs.H264()),
                        AudioTrack('a.mp4', codecs.AC3('448k', 6, 48000))], 'b.mp4').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mp4',
               '-filter_complex', '[0:v:0]yadif[vout0];[vout0]scale=1920:-2[vout1]',
               '-map', '[vout1]', '-c:v:0', 'h264', '-crf', '23', '-pix_fmt', 'yuv420p',
               '-profile:v', 'high', '-level', '3.1',
               '-map', '0:a:0', '-c:a:0', 'ac3', '-b:a', '448k', '-ac', '6', '-ar', '48000',
               '-threads', '0', 'b.mp4']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 10
0
    def test_delay_audio_for_5sec(self, mock_subprocess):
        delayed_instream = AudioInstream('a.mkv', start_at=5)
        MediaConverter([VideoTrack('a.mkv', codecs.H264()),
                        AudioTrack(delayed_instream, codecs.AC3('448k', 6, 48000))], 'b.mp4').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mkv',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-ss', '5', '-i', 'a.mkv',
               '-map', '0:v:0', '-c:v:0', 'h264', '-crf', '23', '-pix_fmt', 'yuv420p',
               '-profile:v', 'high', '-level', '3.1',
               '-map', '1:a:0', '-c:a:0', 'ac3', '-b:a', '448k', '-ac', '6', '-ar', '48000',
               '-threads', '0', 'b.mp4']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 11
0
    def test_image_video_with_audio(self, mock_valid, mock_subprocess):
        mock_valid.return_value = True
        MediaConverter([VideoTrack('a.png', codecs.H264()),
                        AudioTrack('a.mp3', codecs.AAC())], 'b.mp4').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-i', 'a.png',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mp3',
               '-map', '0:v:0', '-c:v:0', 'h264', '-crf', '23', '-pix_fmt', 'yuv420p',
               '-profile:v', 'high', '-level', '3.1',
               '-map', '1:a:0', '-c:a:0', 'aac', '-b:a', '192k', '-ac', '2', '-ar', '44100',
               '-threads', '0', 'b.mp4']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 12
0
    def test_subtitle_language(self, mock_subprocess):
        MediaConverter([VideoTrack('a.mp4', codecs.H264()),
                        AudioTrack('a.mp4', codecs.AAC()),
                        SubtitleTrack('a.srt', codecs.TimedText(), language='kor')], 'b.mp4').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mp4',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.srt',
               '-map', '0:v:0', '-c:v:0', 'h264', '-crf', '23', '-pix_fmt', 'yuv420p',
               '-profile:v', 'high', '-level', '3.1',
               '-map', '0:a:0', '-c:a:0', 'aac', '-b:a', '192k', '-ac', '2', '-ar', '44100',
               '-map', '1:s:0', '-c:s:0', 'mov_text',
               '-metadata:s:s:0', 'language=kor',
               '-threads', '0', 'b.mp4']
        mock_subprocess.assert_called_with(cmd)
Ejemplo n.º 13
0
    def test_overlay_filter_with_xy_option(self, mock_valid, mock_subprocess):
        mock_valid.side_effect = lambda x: x == 'a.png'

        vos = VideoOutstream('a.mp4').overlay('a.png', 30, 70)
        MediaConverter([VideoTrack(vos, codecs.H264()),
                        AudioTrack('a.mp4', codecs.AC3('448k', 6, 48000))], 'b.mp4').convert()

        cmd = ['/somewhere/ffmpeg', '-y',
               '-analyzeduration', '2147483647', '-probesize', '2147483647', '-i', 'a.mp4',
               '-i', 'a.png',
               '-filter_complex', '[0:v:0][1:v:0]overlay=30:70[vout0]',
               '-map', '[vout0]', '-c:v:0', 'h264', '-crf', '23', '-pix_fmt', 'yuv420p',
               '-profile:v', 'high', '-level', '3.1',
               '-map', '0:a:0', '-c:a:0', 'ac3', '-b:a', '448k', '-ac', '6', '-ar', '48000',
               '-threads', '0', 'b.mp4']
        mock_subprocess.assert_called_with(cmd)