<p>I have tried the following command to generate output file with repeating audio track and it is working fine</p>

<p>-stream_loop 2 -i input.mp3 -c copy -y output.mp3</p>

<p>it will create output.mp3 output file with repeating input track 3 times</p>

CC BY-SA 4.0
2019-01-08T10:26:49.787Z
2019-01-08T10:26:49.787Z
user24105
<p>I want to mix audio on a video.
The video already has audio stream in it. I'm adding another one.</p>

<p>The new audio I'm adding is shorter than the video. So, I want to loop it as long as the video lasts.</p>

<p>So far, I'm doing this:</p>

<pre><code>ffmpeg -y -i test.mp4 -stream_loop -1 -i bg_sound.mp3 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest[out]" -map 0:v -map [out] output.mp4
</code></pre>

<p>This adds the audio on the video, but does not loop it. I've also tried <code>stream_loop</code> with other integer options with no luck. The audio I'm adding ends and the rest of the video continues.</p>

<p>I need to loop my audio.</p>

<p>Here is the ffprobe result of my video:</p>

<pre><code>   ffprobe version N-76452-ga97f1e7 Copyright (c) 2007-2015 the FFmpeg developers
   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
   configuration: --prefix=/home/alfanso/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/alfanso/ffmpeg_build/include --extra-ldflags=-L/home/alfanso/ffmpeg_build/lib --bindir=/home/alfanso/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
   libavutil      55.  5.100 / 55.  5.100
   libavcodec     57. 14.100 / 57. 14.100
   libavformat    57. 14.100 / 57. 14.100
   libavdevice    57.  0.100 / 57.  0.100
   libavfilter     6. 14.101 /  6. 14.101
   libswscale      4.  0.100 /  4.  0.100
   libswresample   2.  0.100 /  2.  0.100
   libpostproc    54.  0.100 / 54.  0.100
   Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'localtest.mp4':
   Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2avc1mp41
       encoder         : Lavf56.40.101
       Duration: 00:06:53.97, start: 0.033333, bitrate: 179 kb/s
       Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1280x720, 45 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
   Metadata:
      handler_name    : VideoHandler
      Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 128 kb/s (default)
   Metadata:
      handler_name    : SoundHandler
</code></pre>

<p>I've also tried using different video and audio sources with the same result.</p>

CC BY-SA 3.0
2015-12-18T12:23:49.953Z
Try assigning something 5 or 6 to stream loop and change to shortest in filter.
Gyan
CC BY-SA 3.0
2015-12-18T12:32:24.477Z
I had tried with `stream_loop 5`. Just tried that along with shortest in amix. That caused the original audio (already in video) to stop along with the video being added. I hope this makes sense :P
Dhavan Vaidya
CC BY-SA 3.0
2015-12-18T12:33:55.537Z
Ok, I'll check when I have more time.
Gyan
CC BY-SA 3.0
2015-12-21T03:51:44.893Z
Just checking in :)
Should I report this as feature request/bug?
Dhavan Vaidya
CC BY-SA 3.0
2015-12-21T04:43:17.667Z
Sorry. Busy. Give me a day or so.
Gyan
CC BY-SA 3.0
2015-12-21T04:55:03.677Z
Sure! No problem. :)
Dhavan Vaidya
CC BY-SA 3.0
2015-12-31T06:58:49.100Z
Got time for it? For now, I've increased the length of my audio manually to the max value I think I would need in extreme case. Such a hack.
Dhavan Vaidya
<ffmpeg>
Loop and mix audio on video
Dhavan Vaidya
# Loop and mix audio on video

(Asked by: username_0 on 2015-12-18)

I want to mix audio on a video.
The video already has audio stream in it. I'm adding another one.
The new audio I'm adding is shorter than the video. So, I want to loop it as long as the video lasts.
So far, I'm doing this:
ffmpeg -y -i test.mp4 -stream_loop -1 -i bg_sound.mp3 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest[out]" -map 0:v -map [out] output.mp4

This adds the audio on the video, but does not loop it. I've also tried stream_loop with other integer options with no luck. The audio I'm adding ends and the rest of the video continues.
I need to loop my audio.
Here is the ffprobe result of my video:
   ffprobe version N-76452-ga97f1e7 Copyright (c) 2007-2015 the FFmpeg developers
   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
   configuration: --prefix=/home/alfanso/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/alfanso/ffmpeg_build/include --extra-ldflags=-L/home/alfanso/ffmpeg_build/lib --bindir=/home/alfanso/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
   libavutil      55.  5.100 / 55.  5.100
   libavcodec     57. 14.100 / 57. 14.100
   libavformat    57. 14.100 / 57. 14.100
   libavdevice    57.  0.100 / 57.  0.100
   libavfilter     6. 14.101 /  6. 14.101
   libswscale      4.  0.100 /  4.  0.100
   libswresample   2.  0.100 /  2.  0.100
   libpostproc    54.  0.100 / 54.  0.100
   Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'localtest.mp4':
   Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2avc1mp41
       encoder         : Lavf56.40.101
       Duration: 00:06:53.97, start: 0.033333, bitrate: 179 kb/s
       Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1280x720, 45 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
   Metadata:
      handler_name    : VideoHandler
      Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 128 kb/s (default)
   Metadata:
      handler_name    : SoundHandler

I've also tried using different video and audio sources with the same result.

**Tags:** ffmpeg

> **Comments:**
> **username_1**: Try assigning something 5 or 6 to stream loop and change to shortest in filter.  
> **username_0**: I had tried with `stream_loop 5`. Just tried that along with shortest in amix. That caused the original audio (already in video) to stop along with the video being added. I hope this makes sense :P  
> **username_1**: Ok, I'll check when I have more time.  
> **username_0**: Just checking in :) Should I report this as feature request/bug?  
> **username_1**: Sorry. Busy. Give me a day or so.  
> **username_0**: Sure! No problem. :)  
> **username_0**: Got time for it? For now, I've increased the length of my audio manually to the max value I think I would need in extreme case. Such a hack.  

---

## 1 answers

### Answer by username_2 on 2019-01-08. Score: 1

I have tried the following command to generate output file with repeating audio track and it is working fine

-stream\_loop 2 -i input.mp3 -c copy -y output.mp3

it will create output.mp3 output file with repeating input track 3 times


---

