Monday, November 11, 2019

Non-Rectangular Video Cropping



I've come across a few posts asking how/if you can perform a circular crop on a video.  The focus of this post will be to demonstrate the effect of a circular crop.  In all fairness, this method will give the effect of a crop by applying a transparent mask overlay image.

Let's fire through a circular crop example; a three-step process:
1) create a two-tone image (black/white) image with the same dimension as the video file
2) convert the two-tone image to a transparent image where the view plane is transparent
3) apply the image overlay to the video

Create Two-Tone Image mask

$ convert -size 1280x720 xc:black -fill white -strokewidth 2 -draw 'circle 640,360 320,360' mask.png

Convert to Transparent View Image

$ convert mask.png -fuzz 10% -transparent white mask.png
Bear with me, the following image differs from the above, the inner circle is transparent but the blog background is white giving the appearance of the same image above.


Apply Mask Overlay To Video

$ ffmpeg -i input.mp4 -vf "movie=mask.png [watermark]; [in] [watermark] overlay=0:0 [out]" -strict -2 output.mp4

This final step gives the result;

No comments:

Post a Comment