<p>The loop option can't be used if you're ingesting multiple streams via the filter.</p>

<p>Use</p>

<pre><code>ffmpeg -re -f lavfi -i "movie=filename=ShortLoop.mpg:loop=0"
       -re -f lavfi -i "amovie=filename=ShortLoop.mpg:loop=0"
       -vf setpts=N/FRAME_RATE/TB -af asetpts=N/SR/TB     test1.mpg
</code></pre>

CC BY-SA 3.0
2017-06-22T14:55:34.747Z
Thank you. That does add audio, but it is not in sync from the first loop onward. Could it be that video and audio are not of the exact same length? Unfortunately (and that is another issue), FFmpeg reports N/A for both so that's not very helpful.
Mike Versteeg
CC BY-SA 3.0
2017-06-22T15:31:42.177Z
Run `ffprobe Shortloop.mpg -show_entries stream=duration -of compact -v 0` to check. You can then remux `ffmpeg -i in.mpg -c copy -shortest out.mpg`.
Gyan
CC BY-SA 3.0
2017-06-23T08:28:29.893Z
There is a 14 ms difference, not enough to explain the sync issue I am seeing. Running your remux does not change anything either.
Mike Versteeg
CC BY-SA 3.0
2017-06-23T08:32:11.790Z
BTW: ffmpeg -stream_loop -1 -i ShortLoop.mpg out.mpg maintains perfect sync, is a lot faster, but unfortunately has the pause bug. It seems someone fixing that bug is the best solution for me. I have no idea how to make that happen though.
Mike Versteeg
CC BY-SA 3.0
2017-06-23T08:33:41.927Z
Post to the ffmpeg-devel mailing list and reference the ticket. You may get ignored, but maybe not :)
Gyan
CC BY-SA 3.0
2017-06-24T13:56:42.320Z
I did and I wasn't ignored. But the answer was "Nope." so not very helpful. They did inquire after this bug.
Mike Versteeg
CC BY-SA 3.0
2017-06-24T14:24:56.897Z
Try with avconv. The code for this was grafted from there. It may have been fixed there since the time of borrowing. If so, great. If not, post to their devel list.
Gyan
CC BY-SA 3.0
2017-06-22T14:21:07.933Z
2017-06-22T14:21:07.933Z
Gyan
<p>If I loop a video like below the audio is missing from test 1. If I omit the loop, it is there. What am I doing wrong?</p>

<pre><code>E:\Videos\Loops&gt;ffmpeg -re -f lavfi -i "movie=filename=ShortLoop.mpg:loop=0, set
pts=N/(FRAME_RATE*TB)" test1.mpg
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-dxva2 --enable-libmfx -
-enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei
0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-li
bbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --en
able-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-li
bopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --e
nable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable
-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --e
nable-lzma --enable-decklink --enable-zlib
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, lavfi, from 'movie=filename=ShortLoop.mpg:loop=0, setpts=N/(FRAME_RATE
*TB)':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720 [SAR 1:1
 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 90k tbc
[mpeg @ 00000000002df920] VBV buffer size not set, using default size of 130KB
If you want the mpeg file to be compliant to some specification
Like DVD, VCD or others, make sure you set the correct buffer size
Output #0, mpeg, to 'test1.mpg':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: mpeg1video, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31
, 200 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 mpeg1video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -&gt; #0:0 (rawvideo (native) -&gt; mpeg1video (native))
Press [q] to stop, [?] for help
[mpeg1video @ 0000000003786d40] [mpeg1video @ 0000000003786d40]
</code></pre>

<ffmpeg>
Using FFmpeg loop filter makes audio disappear
Mike Versteeg
# Using FFmpeg loop filter makes audio disappear

(Asked by: username_0 on 2017-06-22)

If I loop a video like below the audio is missing from test 1. If I omit the loop, it is there. What am I doing wrong?
E:\Videos\Loops>ffmpeg -re -f lavfi -i "movie=filename=ShortLoop.mpg:loop=0, set
pts=N/(FRAME_RATE*TB)" test1.mpg
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-dxva2 --enable-libmfx -
-enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei
0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-li
bbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --en
able-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-li
bopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --e
nable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable
-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --e
nable-lzma --enable-decklink --enable-zlib
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, lavfi, from 'movie=filename=ShortLoop.mpg:loop=0, setpts=N/(FRAME_RATE
*TB)':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720 [SAR 1:1
 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 90k tbc
[mpeg @ 00000000002df920] VBV buffer size not set, using default size of 130KB
If you want the mpeg file to be compliant to some specification
Like DVD, VCD or others, make sure you set the correct buffer size
Output #0, mpeg, to 'test1.mpg':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: mpeg1video, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31
, 200 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.64.101 mpeg1video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg1video (native))
Press [q] to stop, [?] for help
[mpeg1video @ 0000000003786d40] [mpeg1video @ 0000000003786d40]

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2017-06-22. Score: 2

The loop option can't be used if you're ingesting multiple streams via the filter.
Use
ffmpeg -re -f lavfi -i "movie=filename=ShortLoop.mpg:loop=0"
       -re -f lavfi -i "amovie=filename=ShortLoop.mpg:loop=0"
       -vf setpts=N/FRAME_RATE/TB -af asetpts=N/SR/TB     test1.mpg

> **Comments:**
> **username_0**: Thank you. That does add audio, but it is not in sync from the first loop onward. Could it be that video and audio are not of the exact same length? Unfortunately (and that is another issue), FFmpeg reports N/A for both so that's not very helpful.  
> **username_1**: Run `ffprobe Shortloop.mpg -show_entries stream=duration -of compact -v 0` to check. You can then remux `ffmpeg -i in.mpg -c copy -shortest out.mpg`.  
> **username_0**: There is a 14 ms difference, not enough to explain the sync issue I am seeing. Running your remux does not change anything either.  
> **username_0**: BTW: ffmpeg -stream_loop -1 -i ShortLoop.mpg out.mpg maintains perfect sync, is a lot faster, but unfortunately has the pause bug. It seems someone fixing that bug is the best solution for me. I have no idea how to make that happen though.  
> **username_1**: Post to the ffmpeg-devel mailing list and reference the ticket. You may get ignored, but maybe not :)  
> **username_0**: I did and I wasn't ignored. But the answer was "Nope." so not very helpful. They did inquire after this bug.  
> **username_1**: Try with avconv. The code for this was grafted from there. It may have been fixed there since the time of borrowing. If so, great. If not, post to their devel list.  

---

