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!

0

1 Answer 1

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.

1
  • The website hosting the alpha mask image is gone, but you can still find it on wayback machine here: web.archive.org/web/20180722233243/http://avmule.com/images/… Your video file also has to have an alpha channel or you will get "Requested planes not available". Can re-encode in something like yuva420p using ffv1. Commented Apr 24, 2024 at 8:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.