8000 Add `video_bitrate` and `audio_bitrate` params by kkroening · Pull Request #87 · kkroening/ffmpeg-python · GitHub
[go: up one dir, main page]

Skip to content

Add video_bitrate and audio_bitrate params #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions ffmpeg/_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://ffmpeg.org/ffmpeg.html#Synopsis>`__
Expand Down
9 changes: 6 additions & 3 deletions ffmpeg/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions ffmpeg/tests/test_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
0