4

I want to crop an area from an input video, then rotate this area 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!

1 Answers1

11

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

llogan
  • 63,280