Skip to content

Commit

Permalink
FFmpegProcessor.crop() fails with non-overlapping cropping area.
Browse files Browse the repository at this point in the history
  • Loading branch information
eseifert committed Aug 6, 2018
1 parent 15a0bdb commit a3c4cbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions madam/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ def crop(self, asset, x, y, width, height):
if x == 0 and y == 0 and width == asset.width and height == asset.height:
return asset

max_x = max(0, min(asset.width, width + x))
max_y = max(0, min(asset.height, height + y))
min_x = max(0, min(asset.width, x))
min_y = max(0, min(asset.height, y))

if min_x == asset.width or min_y == asset.height or max_x <= min_x or max_y <= min_y:
raise OperatorError('Invalid cropping area: <x=%r, y=%r, width=%r, height=%r>' % (x, y, width, height))

return None


Expand Down
11 changes: 11 additions & 0 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,14 @@ def test_crop_with_original_dimensions_returns_identical_asset(self, processor,
cropped_asset = crop_operator(video_asset)

assert cropped_asset is video_asset

@pytest.mark.parametrize('x, y, width, height', [
(-DEFAULT_WIDTH, -DEFAULT_HEIGHT, DEFAULT_WIDTH, DEFAULT_HEIGHT),
(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH, DEFAULT_HEIGHT),
(0, 0, -DEFAULT_WIDTH, -DEFAULT_HEIGHT),
])
def test_crop_fails_with_non_overlapping_cropping_area(self, processor, video_asset, x, y, width, height):
crop_operator = processor.crop(x=x, y=y, width=width, height=height)

with pytest.raises(OperatorError):
crop_operator(video_asset)

0 comments on commit a3c4cbd

Please sign in to comment.