Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

filter - FFmpeg - How to scale a video then apply a watermark?

Im trying to scale a video so that it is always 512 wide where the height changes in proportion to the original video. Once scaled, I then want to apply a watermark/overlay to the video, therefore the video will scale but the watermark wont.

I am able to achieve each of these separately using the following filters:

Scale

-vf "scale=512:-1"

Watermark

-vf "movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"

They work successfully on their own.

However when trying to combine the two, Im having a bit of trouble.

Having both as parameters of course does not work as one will override the other.

Ive tried:

-vf "scale=512:-1,movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"

my thinking was that the scale would be applied first then the watermark but all I get is an error

Too many inputs specified for the "movie" filter.

Error opening filters!

Then changing the , to a ; resulted in:

Simple filtergraph 'scale=512:-1; movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]' does not have exactly one input and output.

Error opening filters!

I presume I need to do something more with filterchains but Im struggling to figure it out.

Any ideas anyone?

Many thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the -filter_complex option with the scale and overlay filters:

ffmpeg -i input.mp4 -i logo.png -filter_complex "[0:v]scale=512:-1[bg];[bg][1:v]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" output
  • See scale and overlay filter documentation for more info.
  • No need for the movie source filter as in the other examples.
  • You can add -c:a copy if you want to stream copy (re-mux) the original audio instead of re-encoding it. This is useful if your input and output container formats are the same.
  • The example will place the logo in the center. For other placement options:
    • Upper left with 10 px padding: overlay=10:10
    • Upper right with 10 px padding: overlay=W-w-10:10
    • Lower right with 10 px padding: overlay=W-w-10:H-h-10
    • Lower left with 10 px padding: overlay=H-h-10:10

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...