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

后端 未结 3 1293
Happy的楠姐
Happy的楠姐 2020-12-13 16:30

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

相关标签:
3条回答
  • 2020-12-13 16:44

    Thank you to both @DiJuMx and @LordNeckbeard, you both got me closer to my solution. Ive not tried the filter_complex option yet but it certainly looks simpler.

    The solution I found to work is:

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

    Note that Ive replaced the -1 in the scale as that had the potential to cause an uneven number of pixels in the height of the video when scaling which would then cause encoding errors.

    0 讨论(0)
  • 2020-12-13 16:58

    From what I understand, this might work:

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

    You apply the scale filter to the input "[in]".

    Unfortunately I don't have much experience with the filters on ffmpeg so I can't help further. Sorry

    0 讨论(0)
  • 2020-12-13 16:59

    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
    0 讨论(0)
提交回复
热议问题