8000 Add 'crop' filter · joebradly/ffmpeg-python@00fb91a · GitHub
[go: up one dir, main page]

Skip to content

Commit 00fb91a

Browse files
committed
Add 'crop' filter
1 parent f8409d4 commit 00fb91a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

ffmpeg/_filters.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,28 @@ def vflip(stream):
152152
return FilterNode(stream, vflip.__name__).stream()
153153

154154

155+
@filter_operator()
156+
def crop(stream, x, y, width, height, **kwargs):
157+
"""Crop the input video.
158+
159+
Args:
160+
x: The horizontal position, in the input video, of the left edge of
161+
the output video.
162+
y: The vertical position, in the input video, of the top edge of the
163+
output video.
164+
width: The width of the output video. Must be greater than 0.
165+
heigth: The height of the output video. Must be greater than 0.
166+
167+
Official documentation: `crop <https://ffmpeg.org/ffmpeg-filters.html#crop>`__
168+
"""
169+
return FilterNode(
170+
stream,
171+
crop.__name__,
172+
args=[width, height, x, y],
173+
kwargs=kwargs
174+
).stream()
175+
176+
155177
@filter_operator()
156178
def drawbox(stream, x, y, width, height, color, thickness=None, **kwargs):
157179
"""Draw a colored box on the input image.
@@ -395,6 +417,7 @@ def colorchannelmixer(stream, *args, **kwargs):
395417
__all__ = [
396418
'colorchannelmixer',
397419
'concat',
420+
'crop',
398421
'drawbox',
399422
'filter_',
400423
'hflip',

ffmpeg/tests/test_ffmpeg.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def _get_complex_filter_example():
114114
split1 = split[1]
115115

116116
overlay_file = ffmpeg.input(TEST_OVERLAY_FILE)
117+
overlay_file = ffmpeg.crop(overlay_file, 10, 10, 158, 112)
117118
return (ffmpeg
118119
.concat(
119120
split0.trim(start_frame=10, end_frame=20),
@@ -137,10 +138,11 @@ def test_get_args_complex_filter():
137138
'[s1]trim=end_frame=20:start_frame=10[s3];' \
138139
'[s2]trim=end_frame=40:start_frame=30[s4];' \
139140
'[s3][s4]concat=n=2[s5];' \
140-
'[1]hflip[s6];' \
141-
'[s5][s6]overlay=eof_action=repeat[s7];' \
142-
'[s7]drawbox=50:50:120:120:red:t=5[s8]',
143-
'-map', '[s8]', TEST_OUTPUT_FILE1,
141+
'[1]crop=158:112:10:10[s6];' \
142+
'[s6]hflip[s7];' \
143+
'[s5][s7]overlay=eof_action=repeat[s8];' \
144+
'[s8]drawbox=50:50:120:120:red:t=5[s9]',
145+
'-map', '[s9]', TEST_OUTPUT_FILE1,
144146
'-y'
145147
]
146148

0 commit comments

Comments
 (0)
0