FFMPEG - How to set overlay video's size to input size

417 views Asked by At

Ok, I'm using FFMPEG wasm in a NextJS project, but I think general FFMPEG solutions will work since FFMPEG wasm will parse normal FFMPEG commands.
What I'm trying to do is to add an overlay video on top of the input video, I also change the overlay video's opacity so that I can see the main video below. I already have that working, with this line of code:
-i input.mkv -i overlay.mov -filter_complex [1:v]format=argb,geq=r=\'r(X,Y)\':a=\'0.5*alpha(X,Y)\'[zork];[0:v][zork]overlay -pix_fmt yuv420p -preset ultrafast -c:a copy output.mkv.

The problem is that the input.mkv size might change as well as the overlay.mov, and I want to set the overlay.mov size to be the same as the input.mkv (so the solutions preferrebly can't use fixed values as well). I've seen other questions about that in stackoverflow, but since I'm already using the command to change the overlay's opacity I can't make it work with the command to also change the overlay's size, I don't have experience with FFMPEG whatsoever, so even though I've seen how to change overlay's opacity, and how to change overlay's size, I can't figure out how to combine those commands into a single one that do both.

1

There are 1 answers

0
Gyan On BEST ANSWER

First scale using scale2ref, then change opacity.

-i input.mkv -i overlay.mov -filter_complex [1:v][0:v]scale2ref[zork][video]; [zork]format=argb,lutrgb=a=val*0.5[zork];[video][zork]overlay -pix_fmt yuv420p -preset ultrafast -c:a copy output.mkv