0

I'm building a video from 3 ( or more ) images, with some effects and with an mp3 in background; my issue is that the mp3 can be shorter than the final video ( whose length dependes from the number of images ) ; is there a way to send audio background in loop, so that when it finish, it restarts and I have no silence during video?

Thanks in advance!

This is the code:

#/bin/bash
ffmpeg -y \
-loop 1 -t 10 -i     img001.jpg  \
-loop 1 -t 10 -i     img002.jpg  \
-loop 1 -t 10 -i     img003.jpg  \
-i 1.mp3  \
-filter_complex \
"\
[0:v]\
format=yuv420p,\
scale=iw*10:ih*10,\
zoompan=z='min(pzoom+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/    zoom/2)':s=640x480,\
drawtext=fontfile='IndieFlower.ttf':enable='between(    t,0,5)':\
text='Caption 1 Scena 1':\
fontsize=60:fontcolor=whit    e:\
x=t*300*lte(t*300\,(w-text_w)/2)+(w-text_w)/2*gt(t*300\,(w-t    ext_w)/2):y=h-line_h-10:\
shadowx=3:shadowy=3:shadow    color=black:\
boxborderw=10:box=1:boxcol    or=red@0.8,\
drawtext=fontfile='IndieFlower.ttf':enable='between(    t,5,10)':\
text='Caption 2 Scena 1':\
fontsize=60:fontcolor=whit    e:\
x=(w-(t-5)*500)*gt(w-(t-5)*500\,(w-text_w)/2)+(w-text_w)/2*lte(w-(t-5)*500\,(w-text_w)/2):y=    h-line_h-10:\
shadowx=3:shadowy=3:shadow    color=black:\
boxborderw=10:box=1:boxcol    or=red@0.8,\
fifo\
[final1];\
[1:v]\
format=yuv420p,\
scale=iw*10:ih*10,\
zoompan=z='min(pzoom+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/    zoom/2)':s=640x480,\
fade=t=in:st=0:d=1,\
drawtext=fontfile='IndieFlower.ttf':enable='between(    t,0,5)':\
text='Caption 1 Scena 2':\
fontsize=60:fontcolor=red:    \
x=t*300*lte(t*300\,(w-text_w)/2)+(w-text_w)/2*gt(t*300\,(w-t    ext_w)/2):y=h-line_h-10:\
shadowx=3:shadowy=3:shadow    color=white:\
boxborderw=10:box=1:boxcol    or=black@0.8,\
drawtext=fontfile='IndieFlower.ttf':enable='between(    t,5,10)':\
text='Caption 2 Scena 2':\
fontsize=60:fontcolor=red:    \
x=(w-(t-5)*500)*gt(w-(t-5)*500\,(w-text_w)/2)+(w-text_w)/2*lte(w-(t-5)*500\,(w-text_w)/2):y=    h-line_h-10:\
shadowx=3:shadowy=3:shadow    color=white:\
boxborderw=10:box=1:boxcol    or=black@0.8,\
fifo\
[final2];\
[2:v]\
format=yuv420p,\
scale=iw*10:ih*10,\
zoompan=z='min(pzoom+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/    zoom/2)':s=640x480,\
fade=t=in:st=0:d=1,\
drawtext=fontfile='IndieFlower.ttf':enable='between(    t,0,5)':\
text='Caption 1 Scena 3':\
fontsize=60:fontcolor=red:    \
x=t*300*lte(t*300\,(w-text_w)/2)+(w-text_w)/2*gt(t*300\,(w-t    ext_w)/2):y=h-line_h-10:\
shadowx=3:shadowy=3:shadow    color=white:\
boxborderw=10:box=1:boxcol    or=black@0.8,\
drawtext=fontfile='IndieFlower.ttf':enable='between(    t,5,10)':\
text='Caption 2 Scena 3':\
fontsize=60:fontcolor=red:    \
x=(w-(t-5)*500)*gt(w-(t-5)*500\,(w-text_w)/2)+(w-text_w)/2*lte(w-(t-5)*500\,(w-text_w)/2):y=    h-line_h-10:\
shadowx=3:shadowy=3:shadow    color=white:\
boxborderw=10:box=1:boxcol    or=black@0.8,\
fifo\
[final3];\
[final1][final2][final3]    concat=n=3:v=1:a=0\
" \
-c:v libx264 \
-r 25 \
-pix_fmt yuv420p \
-t 30 \
o.mp4
0

Set the audio to loop,

-stream_loop -1 -i 1.mp3  \

If you don't set a duration limit like -t 30 \, add

-fflags +shortest -max_interleave_delta 50000
  • mm I have added -stream_loop -1 -i 1.mp3 to my command; apparently it does not work well. When I reproduce the final video ( its duration is 30 seconds ), the audio ( its duration is 12 seconds ) is not in loop, and, another strange thing, the timing of the video stops at 12 seconds ( the duration of the audio )... Thanks – GFCoder977 Feb 12 '18 at 14:27
  • What build are you using? – Gyan Feb 12 '18 at 14:40
  • 16:11 $ ffmpeg -version ffmpeg version 3.2.4-1build2 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 6.3.0 (Ubuntu 6.3.0-8ubuntu1) 20170221 – GFCoder977 Feb 12 '18 at 15:12
  • Get the latest git binary. stream_loop had a bug, recently fixed. – Gyan Feb 12 '18 at 16:02
  • I'll update my ffmpeg version and I'll try! Thanks in advance! – GFCoder977 Feb 14 '18 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.