Cris
Cris

Reputation: 796

Concat 2 videos preserving audio timestamp and add overlay (watermark) in single ffmpeg command

I need to perform multiple actions with ffmpeg, problem is that it seem that for add a watermark and concatenate videos I need to re-encode the video. In three steps it would take ages. So I would like to do everything I need with only one video encoding.

I have a Video #1, it has audio. Also I have a Video #2, with audio too. I would like to concat the #1 and #2 (or play #1 first, and then #2) and then add a watermark in #2 for the rest of the video, preserving audio timestamps.

I have searched a lot o internet, so far I got this:

ffmpeg -i Video1.mp4 -itsoffset 4 -i Video2.mp4 -i watermark.png -filter_complex "overlay=5:5" -codec:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart Out.mp4

The sound from Video #2 disappeared and there's no watermark.

I'm not well-versed in ffmpeg, nor in audio & video terminology, so I apologize for possible horrible misconceptions.

Thanks in advance.

Upvotes: 0

Views: 614

Answers (1)

Gyan
Gyan

Reputation: 93339

Use

ffmpeg -i Video1.mp4 -i Video2.mp4 -i watermark.png
   -filter_complex
       "[1][2]overlay=5:5[v2];
        [0][0:a][v2][1:a]concat=n=2:v=1:a=1"
   -c:v libx264 -crf 21 -c:a aac -b:a 384k -ar 48000 -movflags +faststart Out.mp4

For videos to be joined together, one of the concat methods has to be used. In this case, it's the concat filter. This filter requires that both videos have the same resolution and aspect ratio.

First the watermark is overlaid on the 2nd video, then that result is fed to the concat along with the first video's A/V and 2nd video's A.

Upvotes: 2

Related Questions