diff --git a/ffmpeg/_ffmpeg.py b/ffmpeg/_ffmpeg.py index 7928930..30e8e71 100644 --- a/ffmpeg/_ffmpeg.py +++ b/ffmpeg/_ffmpeg.py @@ -62,12 +62,19 @@ def output(*streams_and_filename, **kwargs): Syntax: `ffmpeg.output(stream1[, stream2, stream3...], filename, **ffmpeg_args)` + Any supplied keyword arguments are passed to ffmpeg verbatim (e.g. + ``t=20``, ``f='mp4'``, ``acodec='pcm'``, ``vcodec='rawvideo'``, + etc.). Some keyword-arguments are handled specially, as shown below. + + Args: + video_bitrate: parameter for ``-b:v``, e.g. ``video_bitrate=1000``. + audio_bitrate: parameter for ``-b:a``, e.g. ``audio_bitrate=200``. + format: alias for ``-f`` parameter, e.g. ``format='mp4'`` + (equivalent to ``f='mp4'``). + If multiple streams are provided, they are mapped to the same output. - Any supplied kwargs are passed to ffmpeg verbatim (e.g. ``t=20``, - ``f='mp4'``, ``acodec='pcm'``, etc.). - To tell ffmpeg to write to stdout, use ``pipe:`` as the filename. Official documentation: `Synopsis `__ diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index 1222853..cbc0676 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -119,9 +119,12 @@ def _get_output_args(node, stream_name_map): kwargs = copy.copy(node.kwargs) filename = kwargs.pop('filename') - fmt = kwargs.pop('format', None) - if fmt: - args += ['-f', fmt] + if 'format' in kwargs: + args += ['-f', kwargs.pop('format')] + if 'video_bitrate' in kwargs: + args += ['-b:v', str(kwargs.pop('video_bitrate'))] + if 'audio_bitrate' in kwargs: + args += ['-b:a', str(kwargs.pop('audio_bitrate'))] if 'video_size' in kwargs: video_size = kwargs.pop('video_size') if not isinstance(video_size, basestring) and isinstance(video_size, collections.Iterable): diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index ceb94a1..49654bc 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -237,6 +237,16 @@ def test_filter_asplit(): ] +def test__output__bitrate(): + args = ( + ffmpeg + .input('in') + .output('out', video_bitrate=1000, audio_bitrate=200) + .get_args() + ) + assert args == ['-i', 'in', '-b:v', '1000', '-b:a', '200', 'out'] + + @pytest.mark.parametrize('video_size', [(320, 240), '320x240']) def test__output__video_size(video_size): args = (