<p>Set the audio to loop,</p>

<pre><code>-stream_loop -1 -i 1.mp3  \
</code></pre>

<p>If you don't set a duration limit like <code>-t 30 \</code>, add</p>

<pre><code>-fflags +shortest -max_interleave_delta 50000
</code></pre>

CC BY-SA 3.0
2018-02-12T14:27:53.847Z
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
CC BY-SA 3.0
2018-02-12T14:40:22.560Z
What build are you using?
Gyan
CC BY-SA 3.0
2018-02-12T15:12:13.937Z
`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
CC BY-SA 3.0
2018-02-12T16:02:39.257Z
Get the latest git binary. stream_loop had a bug, recently fixed.
Gyan
CC BY-SA 3.0
2018-02-14T09:19:02.557Z
I'll update my ffmpeg version and I'll try! Thanks in advance!
GFCoder977
CC BY-SA 4.0
2020-04-04T00:35:01.970Z
this worked in a stream too, thanks !
Hayden Thring
CC BY-SA 3.0
2018-02-12T13:41:47.827Z
2018-02-12T13:41:47.827Z
Gyan
<p>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?</p>

<p>Thanks in advance!</p>

<p>This is the code:</p>

<pre><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
</code></pre>

<ffmpeg>
ffmpeg - Building video with audio in loop
GFCoder977
# ffmpeg - Building video with audio in loop

(Asked by: username_0 on 2018-02-12)

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

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2018-02-12. Score: 3

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

> **Comments:**
> **username_0**: 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  
> **username_1**: What build are you using?  
> **username_0**: `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 `  
> **username_1**: Get the latest git binary. stream_loop had a bug, recently fixed.  
> **username_0**: I'll update my ffmpeg version and I'll try! Thanks in advance!  
> **username_2**: this worked in a stream too, thanks !  

---

