0

I'm new to using ffmpeg and I want to combine two 1920x1080 videos using hstack. The output video also needs to be 1920x1080. At the same time I want to display a watermark at the bottom of the screen (outside the video area) and one in the top middle of the screen.

So far i managed to make an hstack with padding but the watermark won't display outside the video area.

Here is my first attempt:

ffmpeg -y -i input1.mp4 -i input2.mp4 -i watermark1.png -filter_complex "[0]pad=iw+5:color=black[left];[left][1]hstack=inputs=2","overlay=x=(main_w-overlay_w)*0.95:y=(main_h-overlay_h)*0.95","scale=w=1920:h=1080" Output.mp4

Here is a comparison of what i get and what i want:

wrong output desired output

Any help regarding my problem would be very much appreciated!

1 Answers1

0

The basic order of operations required is

1) scale down each video [, add padding if needed]

2) hstack them

3) pad the output

4) overlay logo

(Alternatively, in step 1, the padding can be sufficient to get rid of step 3.)

ffmpeg -y -i input1.mp4 -i input2.mp4 -i watermark1.png -filter_complex "[0]scale=iw/2:-1[left];[1]scale=iw/2:-1[right];[left][right]hstack=inputs=2,pad=1920:1080:-1:-1,overlay=x=(main_w-overlay_w)*0.95:y=(main_h-overlay_h)*0.95" Output.mp4

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • I tried your suggestion but i get the following error: `[Parsed_pad_3 @ 0550ece0] Negative values are not acceptable. [Parsed_pad_3 @ 0550ece0] Failed to configure input pad on Parsed_pad_3 Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #2:0` – Cédric Kamermans Feb 28 '20 at 08:12
  • Apparently, your ffmpeg build is old. Upgrade to 4.x series. – Gyan Feb 28 '20 at 08:36
  • how can I add some padding inbetween the videos in the same command? – Cédric Kamermans Feb 28 '20 at 14:01
  • Instead of scaling to iw/2, scale to a lower value and then add a pad filter to pad to 960 width. – Gyan Feb 28 '20 at 18:09
  • Instead of `[0]scale=iw/2:-1[left];[1]scale=iw/2:-1[right]`, you would have `[0]scale=iw/2-10:-1,pad=960:ih:0[left];[1]scale=iw/2-10:-1,pad=960:ih:10[right]`. This will add 10 pixels padding on the right of the left video, and 10 pixels padding on the left side of the right video. – Gyan Mar 02 '20 at 11:23