Search code examples
ffmpegoverlayscaling

ffmpeg transpose source and scale watermark to fit on different video sizes


I'm using already using the line below to transpose the source, but I'm facing a problem of the watermark being out of proportion when the video resolution is different

How can I make watermark fit on different video sizes?

ffmpeg -i input  -i watermark.png -filter_complex "transpose=1,overlay=-40:300"  -vb 370k -minrate 300k -maxrate 350k -bufsize 350k -aspect "720:1280" -s "360x640" -c:v libx264 -profile:v "Main" -level "3.1" -r 25 -g 25 -keyint_min 50 -x264opts "keyint=50:min-keyint=50:no-scenecut" -c:a aac -strict experimental -b:a 32000 -ar 32000 -ac 1 output

Solution

  • The scale2ref filter is meant for this use case.

    -filter_complex "[0]transpose=1[v];[1][v]scale2ref=oh*mdar:ih/8[w][v];[v][w]overlay=X:Y"
    

    The watermark's height will be resized to 1/8th the height of the video. The width will be proportionally resized.