diff --git a/README.md b/README.md index 86976c1..e896444 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ [](https://travis-ci.org/kkroening/ffmpeg-python) +<img src="https://ibin.co/3g6Z1Duj7SVU.png" alt="ffmpeg-python logo" width="60%" /> ## Overview There are tons of Python FFmpeg wrappers out there but they seem to lack complex filter support. `ffmpeg-python` works well for simple as well as complex signal graphs. + ## Quickstart Flip a video horizontally: @@ -86,9 +88,9 @@ pip install ffmpeg-python It's also possible to clone the source and put it on your python path (`$PYTHONPATH`, `sys.path`, etc.): ``` -> git clone git@github.com:kkroening/ffmpeg-python.git -> export PYTHONPATH=${PYTHONPATH}:ffmpeg-python -> python +$ git clone git@github.com:kkroening/ffmpeg-python.git +$ export PYTHONPATH=${PYTHONPATH}:ffmpeg-python +$ python >>> import ffmpeg ``` @@ -98,8 +100,8 @@ API documentation is automatically generated from python docstrings and hosted o Alternatively, standard python help is available, such as at the python REPL prompt as follows: ``` -import ffmpeg -help(ffmpeg) +>>> import ffmpeg +>>> help(ffmpeg) ``` ## Custom Filters @@ -126,12 +128,16 @@ When in doubt, refer to the [existing filters](https://github.com/kkroening/ffmp ## Contributing +<img align="right" src="https://ibin.co/3g6U1BtizfZG.png" alt="ffmpeg-python logo" width="20%" /> + Feel free to report any bugs or feature requests. It should be fairly easy to use filters that aren't explicitly built into `ffmpeg-python` but if there's a feature or filter you'd really like to see included in the library, don't hesitate to open a feature request. Pull requests are welcome as well. +<br /> + ## Additional Resources - [API Reference](https://kkroening.github.io/ffmpeg-python/) @@ -140,3 +146,4 @@ Pull requests are welcome as well. - [FFmpeg Homepage](https://ffmpeg.org/) - [FFmpeg Documentation](https://ffmpeg.org/ffmpeg.html) - [FFmpeg Filters Documentation](https://ffmpeg.org/ffmpeg-filters.html) +- Matrix Chat: [#ffmpeg-python:matrix.org](https://riot.im/app/#/room/#ffmpeg-python:matrix.org) diff --git a/ffmpeg/_filters.py b/ffmpeg/_filters.py index 8c52732..0f980a7 100644 --- a/ffmpeg/_filters.py +++ b/ffmpeg/_filters.py @@ -152,6 +152,28 @@ def vflip(stream): return FilterNode(stream, vflip.__name__).stream() +@filter_operator() +def crop(stream, x, y, width, height, **kwargs): + """Crop the input video. + + Args: + x: The horizontal position, in the input video, of the left edge of + the output video. + y: The vertical position, in the input video, of the top edge of the + output video. + width: The width of the output video. Must be greater than 0. + heigth: The height of the output video. Must be greater than 0. + + Official documentation: `crop <https://ffmpeg.org/ffmpeg-filters.html#crop>`__ + """ + return FilterNode( + stream, + crop.__name__, + args=[width, height, x, y], + kwargs=kwargs + ).stream() + + @filter_operator() def drawbox(stream, x, y, width, height, color, thickness=None, **kwargs): """Draw a colored box on the input image. @@ -395,6 +417,7 @@ def colorchannelmixer(stream, *args, **kwargs): __all__ = [ 'colorchannelmixer', 'concat', + 'crop', 'drawbox', 'filter_', 'hflip', diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index de4f2af..95e0042 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -114,6 +114,7 @@ def _get_complex_filter_example(): split1 = split[1] overlay_file = ffmpeg.input(TEST_OVERLAY_FILE) + overlay_file = ffmpeg.crop(overlay_file, 10, 10, 158, 112) return (ffmpeg .concat( split0.trim(start_frame=10, end_frame=20), @@ -137,10 +138,11 @@ def test_get_args_complex_filter(): '[s1]trim=end_frame=20:start_frame=10[s3];' \ '[s2]trim=end_frame=40:start_frame=30[s4];' \ '[s3][s4]concat=n=2[s5];' \ - '[1]hflip[s6];' \ - '[s5][s6]overlay=eof_action=repeat[s7];' \ - '[s7]drawbox=50:50:120:120:red:t=5[s8]', - '-map', '[s8]', TEST_OUTPUT_FILE1, + '[1]crop=158:112:10:10[s6];' \ + '[s6]hflip[s7];' \ + '[s5][s7]overlay=eof_action=repeat[s8];' \ + '[s8]drawbox=50:50:120:120:red:t=5[s9]', + '-map', '[s9]', TEST_OUTPUT_FILE1, '-y' ] diff --git a/setup.py b/setup.py index 277368b..6f59cc0 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup from textwrap import dedent import subprocess -version = '0.1.8' +version = '0.1.9' download_url = 'https://github.com/kkroening/ffmpeg-python/archive/v{}.zip'.format(version) long_description = dedent("""\