Reputation: 55
I use this command.
ffmpeg -i Input.mp4 -i logo.png -c:v h264_nvenc -filter_complex "[0:v]scale=-1:720[video];[1:v][video]scale2ref=(iw/ih)*ih/8/sar:ih/8[wm][base];[base][wm]overlay=10:10" output.mp4
But what does this mean?
scale2ref=(iw/ih)*ih/8/sar:ih/8
Upvotes: 3
Views: 5997
Reputation: 93319
What scale2ref=(iw/ih)*ih/8/sar:ih/8
does is scale the image height to 1/8th the video's height, and scale the image width to, well, a weird value. If the scale is meant to preserve the image's aspect ratio, use
scale2ref=oh*mdar:ih/8
(FFmpeg version 4.0 to 7.1)
Edit: Since FFmpeg 7.1, scale2ref
has been merged into existing scale
filter with secondary reference input:
scale=-1:rh/8
Note that this filter outputs single stream of the modified one instead of two video streams.
Upvotes: 1
Reputation: 3521
To understand the -filter_complex
language, it is essential to read this small chapter of the ffmpeg docs.
You can put the filter description also into a file and use -filter_complex_script <file>
.
Compare the filter to a function. The parameters are separated by :
. By-position just value
, else dictionary-style name=value
. To start the parameter list, you use =
, too.
The actual data goes via labels [<inlabel>]<filter>[<outlabel>]
.
Within a chain of filters (separated by ,
), labels are not necessary.
Chains are separated by ;
.
ffmpeg -filters | grep scale2ref
would give you the in and out channels for the scale2ref
filter (VV->VV
),
i.e. 2 videos, in and out.
ffmpeg -help filter=scale2ref
gives you info on the parameters of the filter.
The order of the parameters is not so obvious, as in this case w
is followed by width
.
But w
and width
are the same. So the actual order is width,height
of output.
(iw/ih)*ih/8/sar:ih/8
is thus width=(iw/ih)*ih/8/sar:height=ih/8
.
To know what variables are predefined/preset for a filter, you need to look into the docs or even better into the source code.
Upvotes: 7