Crop triangular area with FFMPEG

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!


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

  • alphaextract and alphamerge for the alpha component
  • split to make multiple copies of the alpha component
  • transpose/vflip/hflip or whatever combination of similar filters you prefer
  • pad to make the background "canvas"
  • overlay to place each video on the canvas

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 filter graphs must have unique edges, meaning every label connects two "nodes" or filter. So you have to split the output of any filter if you want to send its output to two places.

  • 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.