Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert audio to video ffmpeg with a gif as the background but keep the audio length

Tags:

ffmpeg

I used this to combine a JPG and MP3 into a video:

ffmpeg -loop 1 -i 1.jpg -i song.mp3 -strict -2 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4

I'm trying to change the .jpg to a .gif, but the gif should loop to the MP3 length

like image 320
akiva Avatar asked Nov 25 '25 00:11

akiva


1 Answers

I was able to do it with

ffmpeg -i song.mp3 -ignore_loop 0 -i 2.gif -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -shortest -strict -2 -c:v libx264 -threads 4 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4

this worked for me

like image 83
akiva Avatar answered Nov 27 '25 13:11

akiva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!