#80: add video_bitrate and audio_bitrate params

This commit is contained in:
Karl Kroening 2018-06-01 23:41:24 -07:00
parent 593cd3e790
commit 0ed77a30c7
3 changed files with 27 additions and 6 deletions

View File

@ -62,12 +62,19 @@ def output(*streams_and_filename, **kwargs):
Syntax: Syntax:
`ffmpeg.output(stream1[, stream2, stream3...], filename, **ffmpeg_args)` `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 If multiple streams are provided, they are mapped to the same
output. 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. To tell ffmpeg to write to stdout, use ``pipe:`` as the filename.
Official documentation: `Synopsis <https://ffmpeg.org/ffmpeg.html#Synopsis>`__ Official documentation: `Synopsis <https://ffmpeg.org/ffmpeg.html#Synopsis>`__

View File

@ -120,9 +120,12 @@ def _get_output_args(node, stream_name_map):
kwargs = copy.copy(node.kwargs) kwargs = copy.copy(node.kwargs)
filename = kwargs.pop('filename') filename = kwargs.pop('filename')
fmt = kwargs.pop('format', None) if 'format' in kwargs:
if fmt: args += ['-f', kwargs.pop('format')]
args += ['-f', fmt] 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'))]
args += _convert_kwargs_to_cmd_line_args(kwargs) args += _convert_kwargs_to_cmd_line_args(kwargs)
args += [filename] args += [filename]
return args return args

View File

@ -237,6 +237,17 @@ 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']
def test_filter_normal_arg_escape(): def test_filter_normal_arg_escape():
"""Test string escaping of normal filter args (e.g. ``font`` param of ``drawtext`` filter).""" """Test string escaping of normal filter args (e.g. ``font`` param of ``drawtext`` filter)."""
def _get_drawtext_font_repr(font): def _get_drawtext_font_repr(font):