D
D
Dwellss2021-08-10 20:31:42
fmpeg
Dwellss, 2021-08-10 20:31:42

What is the right way to scale the watermark on the video?

Friends, I spent two days experimenting, I give up.
I can't understand the scale logic in ffmpeg
Here is the command:
ffmpeg -y -i "$file" -i watermark.png -filter_complex "[1]scale=iw*3.0:-1[wm];[0][wm] overlay=x=(Ww)/2:y=(Hh)/2" "out/$file"

Watermark.png size 347x21
As a result, different video results result in different video widths.
With a width of 1440 - everything is ok
1280 - the logo is already larger than necessary
496 - the logo stupidly goes beyond the video

scale=iw*3.0:-1 - played with the parameters, but it's impossible to make the logo FOR ALL videos with different widths be really proportional width.

I, apparently, do not understand the logic itself of how to scale the logo. I have it 347x21, a long inscription.

My task is to make the logo width either original or no more than 90% of the screen.
Help me please...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-08-10
@sergiks

Option 1. In the script, get the dimensions of the next video, calculate the correct size of the logo and make a PNG copy of the required size. It remains to apply ffmpeg without scaling. So it will probably be faster.
Option 2. instead of a filter scale, use a similar scale2ref filter - it allows you to take the dimensions of one input to scale another.

ffmpeg -i "$file" -i "$wm" \
  -filter_complex "[1][0:v]scale2ref=w='min(347, iw * 9/10)':h=ow/main_dar[logo][vid];
    [vid][logo]overlay=x=(W-w) / 2:y=H - 2 * h[v]" \
  -map [v]:v  -map 0:a \
  -y "$file-out.mp4"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question