8000 Merge pull request #87 from kkroening/feature-80 · omnix-jenkins/ffmpeg-python@57eeea2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 57eeea2

Browse files
authored
Merge pull request kkroening#87 from kkroening/feature-80
Add `video_bitrate` and `audio_bitrate` params
2 parents 1681e8c + 0cc0bfa commit 57eeea2

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-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
@@ -119,9 +119,12 @@ def _get_output_args(node, stream_name_map):
119119

120120
kwargs = copy.copy(node.kwargs)
121121
filename = kwargs.pop('filename')
122-
fmt = kwargs.pop('format', None)
123-
if fmt:
124-
args += ['-f', fmt]
122+
if 'format' in kwargs:
123+
args += ['-f', kwargs.pop('format')]
124+
if 'video_bitrate' in kwargs:
125+
args += ['-b:v', str(kwargs.pop('video_bitrate'))]
126+
if 'audio_bitrate' in kwargs:
127+
args += ['-b:a', str(kwargs.pop('audio_bitrate'))]
125128
if 'video_size' in kwargs:
126129
video_size = kwargs.pop('video_size')
127130
if not isinstance(video_size, basestring) and isinstance(video_size, collections.Iterable):

ffmpeg/tests/test_ffmpeg.py

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

239239

240+
def test__output__bitrate():
241+
args = (
242+
ffmpeg
243+
.input('in')
244+
.output('out', video_bitrate=1000, audio_bitrate=200)
245+
.get_args()
246+
)
247+
assert args == ['-i', 'in', '-b:v', '1000', '-b:a', '200', 'out']
248+
249+
240250
@pytest.mark.parametrize('video_size', [(320, 240), '320x240'])
241251
def test__output__video_size(video_size):
242252
args = (

0 commit comments

Comments
 (0)
0