FFmpeg - How to achieve a circular video overlay..?

3

I'm helping my daughter and her friends with their Youtube VLOG channel, and now they want to do screen-casts and put a smaller circular face close-up (e.g. in a the upper right or left corner) where you can see them talk about the actual thing they're screencasting. I've used FFmpeg for more basic stuff for almost ten years, but I can tell this is more of a complex task.

I stumbled onto another question thread ( https://stackoverflow.com/questions/42518592/circular-movie-overlay-in-ffmpeg ) thanks to Google, and I think he's trying to accomplish more or less the same, apart from him using the same source for both the small circular overlay and the "main" video, whereas I want to use separate inputs; use "main.mkv" and "facecloseup.mkv" for example command line if anyone is up for solving this delicate task! ;)

For simplicity I'll probably have the two sources with optimized resolution already, say 1080p for the main.mkv and 240x240 or something like that for the facecloseup.mkv and then I just need the math syntax to get a center-circle cropped from facecloseup.mkv and put in some corner, take the upper left for simplicity.

Cheers!

Gew

Posted 2017-11-22T22:25:36.017

Reputation: 31

Answers

2

Use

ffmpeg -i main.mkv -i facecloseup.mkv
 -filter_complex "[1]trim=end_frame=1,
  geq='st(3,pow(X-(W/2),2)+pow(Y-(H/2),2));if(lte(ld(3),pow(min(W/2,H/2),2)),255,0)':128:128,
  loop=-1:1,setpts=N/FRAME_RATE/TB[mask];
  [1][mask]alphamerge[cutout];
  [0][cutout]overlay=x=W-w:y=0[v];
  [0][1]amix=2[a]"
 -map "[v]" -map "[a]"  out.mp4

The commentary video is used to construct a circular grayscale mask centered at the centre of the video. It is then merged as a alpha channel with the source. It is overlaid in the upper-right corner. The audios are mixed together. Remove this last filter and -map "[a]" if the main video has no audio.

Gyan

Posted 2017-11-22T22:25:36.017

Reputation: 21 016

Wow, big thanks for a quick response! This was exactly what I was looking for. I would probably never have figured this one out by myself, since my math skills are on a basic arithmetic level, at most. Also, I'm convinced that this post will help others too; I searched the web for almost two hours for existing Q/A but to no avail. The link I posted was the closest I got to finding an answer. Oh, a small add-on question, say I wanted the "bubble" in the upper left corner instead, would that be much hassle achieving? Again, big thanks! This will help me a lot with automation. – Gew – 2017-11-23T22:16:50.570

In the overlay filter, the values for x and y represent where the top-left corner of the overlaid video (cutout) is located with respect to the top-left corner of the base image (main). Here, x is W-w i.e. at full width of main - full width of cutout which will right-align the two inputs horizontally. Change that to 0 to left-align. – Gyan – 2017-11-24T05:56:44.150