Dady
Dady

Reputation: 113

Multiple sounds + watermark overlay not working with ffmpeg

I have a problem with an ffmpeg command.

I want to add the same sound several times in the final video and then add a watermark above.

When I do the full command, it doesn't work correctly because the sound is only played once (the first reference):

ffmpeg -i "assets/frame%05d.png" -i "assets/sound.mp3" -loop 1 -i "assets/watermark.png" -filter_complex "[1:a]adelay=1000|1000[s1];[1:a]adelay=3000|3000[s2];[s1][s2]amix=2[a];[0:v][2:v]overlay=shortest=1[outv]" -map "[outv]" -map "[a]" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -y "result.mp4"

When I don't add the watermark, it works correctly:

ffmpeg -i "assets/frame%05d.png" -i "assets/sound.mp3" -filter_complex "[1:a]adelay=1000|1000[s1];[1:a]adelay=3000|3000[s2];[s1][s2]amix=2[a]" -map 0:v -map "[a]" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -y "result.mp4"

Upvotes: 0

Views: 133

Answers (2)

Dady
Dady

Reputation: 113

I found the problem was that the different frames that make up the video were not all correctly encoded which caused the problem with the sounds.

ffmpeg can't read indexed PNG correctly.

You must therefore use this option (for those like me who use imagick):

$imagick->setOption('png:color-type', 6);
$imagick->writeImage('frame00000.png');

Upvotes: 0

kesh
kesh

Reputation: 5533

Try this:

ffmpeg -i "assets/frame%05d.png" \
       -stream_loop -1 -i "assets/sound.mp3" \
       -loop 1 -i "assets/watermark.png" \
       -filter_complex "[1:a]adelay=1000|1000[s1];\
                        [1:a]adelay=3000|3000[s2];\
                        [s1][s2]amix=2[a];\
                        [0:v][2:v]overlay=shortest=1[outv]" \
       -map "[outv]" -map "[a]" -shortest \
       -c:v libx264 -pix_fmt yuv420p -preset ultrafast -y "result.mp4"

-stream_loop -1 input option loops the input infinitely and -shortest output option stops the audio when video is done.

p.s., I think an aecho filter can combine the 2nd adelay and amix filters.

Upvotes: 0

Related Questions