8000 #80: add `video_bitrate` and `audio_bitrate` params · monir-dev/ffmpeg-python@0ed77a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ed77a3

Browse files
committed
kkroening#80: add video_bitrate and audio_bitrate params
1 parent 593cd3e commit 0ed77a3

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

ffmpeg/_ffmpeg.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,19 @@ def output(*streams_and_filename, **kwargs):
6262
Syntax:
6363
`ffmpeg.output(stream1[, stream2, stream3...], filename, **ffmpeg_args)`
6464
65+
Any supplied keyword arguments are passed to ffmpeg verbatim (e.g.
66+
``t=20``, ``f='mp4'``, ``acodec='pcm'``, ``vcodec='rawvideo'``,
67+
etc.). Some keyword-arguments are handled specially, as shown below.
68+
69+
Args:
70+
video_bitrate: parameter for ``-b:v``, e.g. ``video_bitrate=1000``.
71+
audio_bitrate: parameter for ``-b:a``, e.g. ``audio_bitrate=200``.
72+
format: alias for ``-f`` parameter, e.g. ``format='mp4'``
73+
(equivalent to ``f='mp4'``).
74+
6575
If multiple streams are provided, they are mapped to the same
6676
output.
6777
68-
Any supplied kwargs are passed to ffmpeg verbatim (e.g. ``t=20``,
69-
``f='mp4'``, ``acodec='pcm'``, etc.).
70-
7178
To tell ffmpeg to write to stdout, use ``pipe:`` as the filename.
7279
7380
Official documentation: `Synopsis <https://ffmpeg.org/ffmpeg.html#Synopsis>`__

ffmpeg/_run.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@ def _get_output_args(node, stream_name_map):
120120

121121
kwargs = copy.copy(node.kwargs)
122122
filename = kwargs.pop('filename')
123-
fmt = kwargs.pop('format', None)
124-
if fmt:
125-
args += ['-f', fmt]
123+
if 'format' in kwargs:
124+
args += ['-f', kwargs.pop('format')]
125+
if 'video_bitrate' in kwargs:
126+
args += ['-b:v', str(kwargs.pop('video_bitrate'))]
127+
if 'audio_bitrate' in kwargs:
128+
args += ['-b:a', str(kwargs.pop('audio_bitrate'))]
126129
args += _convert_kwargs_to_cmd_line_args(kwargs)
127130
args += [filename]
128131
return args

ffmpeg/tests/test_ffmpeg.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ def test_filter_asplit():
237237
]
238238

239239

240+
241+
def test__output__bitrate():
242+
args = (
243+
ffmpeg
244+
.input('in')
245+
.output('out', video_bitrate=1000, audio_bitrate=200)
246+
.get_args()
247+
)
248+
assert args == ['-i', 'in', '-b:v', '1000', '-b:a', '200', 'out']
249+
250+
240251
def test_filter_normal_arg_escape():
241252
"""Test string escaping of normal filter args (e.g. ``font`` param of ``drawtext`` filter)."""
242253
def _get_drawtext_font_repr(font):

0 commit comments

Comments
 (0)
0