Crop triangular area with FFMPEG

4

2

Is it possible to crop a triangular area from a video using ffmpeg filters?

I have to crop this area from an input video 1920 x 1080, then I've to rotate this area of 90 degrees four times. The output video should look like this:

https://dl.dropboxusercontent.com/u/88221856/cropping.png

This is a before image:
enter image description here

This is an after image:
enter image description here

Thanks in advance!

user3485914

Posted 2014-04-01T16:41:48.043

Reputation: 43

Answers

10

Make a kaleidoscope effect with ffmpeg

kaleidoscope

Example command

ffmpeg -i video.mkv -loop 1 -i mask.png -filter_complex \
"[1:v]alphaextract,split[a1][a2]; \
 [0:v][a1]alphamerge,transpose=1[e]; \
 [0:v][a2]alphamerge,transpose=2[w]; \
 [0:v]vflip,hflip[s]; \
 [0:v]pad=ih*2:ih*2:x=(ow-iw)/2[n]; \
 [n][s]overlay=W/2-w/2:W/2[bg]; \
 [bg][e]overlay=W/2:H/2-h/2[bg2]; \
 [bg2][w]overlay=0:H/2-h/2" \
-codec:a copy output.mkv

FFmpeg filters used

Notes

  • Use a recent ffmpeg. Either download a Linux build of ffmpeg or follow a step-by-step guide to compile ffmpeg.

  • You will need to make an image that contains an alpha mask. It needs to be the same frame size as your video input, so if video.mkv is 1920x1080, then mask.png also needs to be 1920x1080. You can download the alpha mask from this example.

  • split was used because I was unable to successfully re-use the same link label for the alphaextract output, and I've never used the alpha* filters before, so the example could possibly be shortened.

  • The black background color of the pad filter is visible in the corners. The crop filter can be used to remove it if you prefer.

  • The audio is stream copied instead of being re-encoded.

  • See the FFmpeg and x264 Encoding Guide for additional information on controlling the output quality.

llogan

Posted 2014-04-01T16:41:48.043

Reputation: 31 929