ffmpegvideo-watermarking

Watermarking with scale2ref conundrum - video resizes to watermark rather than watermark scaling to fit video


Hope you can hep me figure out where I am misleading myself. I am trying to watermark a bunch of videos with varying resolution sizes with a .png watermark file that is 1200x600. I have videos that are as large as 2480x1280 and as small as 360x141.

I had originally thought that ffmpeg could handle it, but I am having issues with the conversion, and I am pretty sure it is my misunderstanding of how to leverage scale2ref command properly. Now, from scale2ref documentation they say this:

Scale a subtitle stream (b) to match the main video (a) in size before overlaying

'scale2ref[b][a];[a][b]overlay'

I understand that stream[b] is my watermark file, and stream[a] is my video file.

My ffmpeg command is this:

while read -r line || [[ -n "$line" ]]; do fn_out="w$line"; (/u2/vidmarktest/scripttesting/files_jeud8334j/dioffmpeg/ffmpeg -report -nostdin -i /u2/vidmarktest/scripttesting/files_jeud8334j/"$line" -i /u2/vidmarktest/mw1.1200x600.png -filter_complex "scale2ref[b][a];[b][a]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2" /u2/vidmarktest/scripttesting/files_jeud8334j/converted/"$fn_out" -c:v libx265); done < videos.txt 

To do some 'splainin, it is going to be part of a bash script that will be cron-ed so we can make sure we have all our latest submissions to the directory watermarked.

The problem is this:

All of my converted videos are scaled to fit 1200x600 now, rather than remaining in their original configuration with the watermark being the part that should be scaled to fit the video.

To note, that in this section: [b][a]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2, many will say I need to switch the [a] and [b] values. When you do that, the watermark is obscured by the video, not interlaced. Switching those two values puts the [b] value (the watermark) over the [a] value (the video).

Any feedback will be highly appreciated, welcomed, and graded :)

I am expecting to get the watermark to adjust to the video resolution, but am failing miserably. What do I not know about ffmpeg and scale2ref that is causing my problem?


Solution

  • In the command, your video is the first input, and the watermark the 2nd. In scale2ref, the inputs aren't explicitly set, so ffmpeg picks streams in input order, whereas you need the watermark to be the first input.

    Use [1:v][0:v]scale2ref[wm][v];[v][wm]overlay=...