From c21e8c103ffb535f4e1a9702d1b2881d1136efd6 Mon Sep 17 00:00:00 2001 From: Karl Kroening Date: Sat, 2 Jun 2018 00:25:47 -0700 Subject: [PATCH 1/2] Support video_size output tuple --- ffmpeg/_run.py | 8 ++++++-- ffmpeg/tests/test_ffmpeg.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index c5a2b52..1222853 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -1,10 +1,9 @@ from __future__ import unicode_literals - from .dag import get_outgoing_edges, topo_sort from ._utils import basestring from builtins import str from functools import reduce -from past.builtins import basestring +import collections import copy import operator import subprocess @@ -123,6 +122,11 @@ def _get_output_args(node, stream_name_map): fmt = kwargs.pop('format', None) if fmt: args += ['-f', fmt] + if 'video_size' in kwargs: + video_size = kwargs.pop('video_size') + if not isinstance(video_size, basestring) and isinstance(video_size, collections.Iterable): + video_size = '{}x{}'.format(video_size[0], video_size[1]) + args += ['-video_size', video_size] args += _convert_kwargs_to_cmd_line_args(kwargs) args += [filename] return args diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 25aedd1..ceb94a1 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -237,6 +237,17 @@ def test_filter_asplit(): ] +@pytest.mark.parametrize('video_size', [(320, 240), '320x240']) +def test__output__video_size(video_size): + args = ( + ffmpeg + .input('in') + .output('out', video_size=video_size) + .get_args() + ) + assert args == ['-i', 'in', '-video_size', '320x240', 'out'] + + def test_filter_normal_arg_escape(): """Test string escaping of normal filter args (e.g. ``font`` param of ``drawtext`` filter).""" def _get_drawtext_font_repr(font): From 54db6e4272f14046d6d919007b9932d13a6358db Mon Sep 17 00:00:00 2001 From: Karl Kroening Date: Sat, 2 Jun 2018 00:30:24 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e4e46ec..f5bf6c3 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,10 @@ $ python >>> import ffmpeg ``` +## [Examples](https://github.com/kkroening/ffmpeg-python/tree/master/examples) + +When in doubt, take a look at the [examples](https://github.com/kkroening/ffmpeg-python/tree/master/examples) to see if there's something that's close to whatever you're trying to do. + ## [API Reference](https://kkroening.github.io/ffmpeg-python/) API documentation is automatically generated from python docstrings and hosted on github pages: https://kkroening.github.io/ffmpeg-python/