1

I try to mix audio with video and add a watermark with this code:

ffmpeg -i input.mp4 -i music.mp3 -i watermark.png \
    -filter_complex "[0:v]scale=1280:720;fps=25[v1];\
        [v1][2]overlay=x=main_w-overlay_w-(main_w*0.01):y=main_h-overlay_h-(main_h*0.01)[v2];\
        [v2]fade=t=out:st=$FADE_OUT_START:d=$FADE_OUT_DURATION[outv];\
        [outv][1:a]concat=n=2:v=0:a=1[v][a]" \
    -map "[v]" -map "[a]" -shortest \
    -preset slow -crf 18 \
    output.mp4

Hi have this error:

Cannot create the link fade:0 -> concat:0
Error initializing complex filters.
Invalid argument

Thanks a lot.

1 Answer 1

1

Instead of concatenating the audio and the video, just map the audio and the video:

ffmpeg -i input.mp4 -i music.mp3 -i watermark.png \
    -filter_complex "[0:v]scale=1280:720,setsar=1:1,fps=25[v1];\
        [v1][2]overlay=x=main_w-overlay_w-(main_w*0.01):y=main_h-overlay_h-(main_h*0.01)[v2]\
        ;[v2]fade=t=out:st=$FADE_OUT_START:d=$FADE_OUT_DURATION[v]" \
    -map "[v]" -map 1:a -shortest \
    -vcodec libx264 -preset slow -crf 18 -acodec copy \
    output.mp4

Before fps, it should be , instead of ; (because it's simple filter chaining).
I added setsar=1:1 (just in case input.mp4 aspect ratio is not 16:9).
It is also recommended to set the video codec and audio codec explicitly.


In the above case, automatic mapping also works:

ffmpeg -y -i input.mp4 -i music.mp3 -i watermark.png -filter_complex "[0:v]scale=1280:720,setsar=1:1,fps=25[v1];[v1][2]overlay=x=main_w-overlay_w-(main_w*0.01):y=main_h-overlay_h-(main_h*0.01)[v2];[v2]fade=t=out:st=1:d=1" -shortest -vcodec libx264 -preset slow -crf 18 -acodec copy output.mp4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .