Add 'crop' filter

This commit is contained in:
Noah Stier 2017-10-05 23:45:43 -07:00 committed by Davide Depau
parent 562be84048
commit fabd401e96
No known key found for this signature in database
GPG Key ID: C7D999B6A55EFE86
2 changed files with 29 additions and 4 deletions

View File

@ -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',

View File

@ -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'
]