<p>I'm trying to do an infinite loop RTMP stream on a CentOS 7 server and it seems like FFmpeg would be the best way to accomplish that.  However, I cannot seem to coax FFmpeg into doing it despite following different variations of parameters I've found on StackExchange and elsewhere. I started by trying to simply have FFmpeg go through a playlist of H.264/AAC MP4 files that are remuxed from OBS Studio. It couldn't cleanly jump from MP4 file to MP4 file, giving errors such as:</p>
<pre><code> [mpegts @ 0x1e5b860] DTS discontinuity in stream 0: packet 30 with DTS 126030, packet 31 with DTS 128970
</code></pre>
<p>After that failed, I converted all the files from MP4 to TS using this command (as mentioned in a few places <a href="https://video.stackexchange.com/questions/12905/repeat-loop-input-video-with-ffmpeg/17389#17389">such as here</a>):</p>
<pre><code>ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
</code></pre>
<p>I can get FFmpeg to stream successfully once through a playlist after doing that, using this command:</p>
<pre><code>ffmpeg -stream_loop -1 -re -f concat -i list.txt -c copy -f flv -flvflags no_duration_filesize -bsf:a aac_adtstoasc -preset veryfast &quot;rtmp://{RTMP Server}/static/{My Streaming Key}&quot;
</code></pre>
<p>However, it still stops after it gets through the playlist once. Is there something I'm missing here? Here's the full output of a session with those parameters:</p>
<pre><code>ffmpeg version 3.4.8 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --disable-encoder=libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[mpegts @ 0x133a100] DTS discontinuity in stream 0: packet 41 with DTS 126041, packet 42 with DTS 129003
[concat @ 0x1330e80] DTS discontinuity in stream 0: packet 41 with DTS -5965, packet 42 with DTS -3003
Input #0, concat, from 'list.txt':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720, 240 fps, 240 tbr, 90k tbn, 60k tbc
    Stream #0:1(und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 265 kb/s
Output #0, flv, to 'rtmp://{RTMP Server}/static/{My Streaming Key}':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 1280x720, q=2-31, 240 fps, 240 tbr, 1k tbn, 90k tbc
    Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 48000 Hz, stereo, fltp, 265 kb/s
Stream mapping:
  Stream #0:0 -&gt; #0:0 (copy)
  Stream #0:1 -&gt; #0:1 (copy)
Press [q] to stop, [?] for help
[mpegts @ 0x1835860] DTS discontinuity in stream 0: packet 30 with DTS 126030, packet 31 with DTS 128970
Error while filtering: Illegal seek90065kB time=00:04:46.19 bitrate=2578.0kbits/s speed=   1x    
[flv @ 0x140b7c0] Failed to update header with correct duration.
[flv @ 0x140b7c0] Failed to update header with correct filesize.
frame= 8658 fps= 30 q=-1.0 Lsize=   90067kB time=00:04:46.22 bitrate=2577.8kbits/s speed=   1x    
video:83684kB audio:5989kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.439653%
</code></pre>
<p>There are a couple of errors you can see during the stream (a few lines up from the bottom), but then it keeps chugging along, streams some more with what you see on the very last line and then appears to exit without an error.</p>
<p>I'd like to not only get it working, but ideally do so in a way that keeps the source files in H.264/AAC or something else that makes the job easy on FFmpeg, so that FFmpeg doesn't have to repeatedly re-transcode the same files each time it loops. (Both to avoid degrading the video more than necessary and also to make the work as light on my server, which has other jobs to do simultaneously.)</p>
<p>I'm open to using something other than FFmpeg if it can run on a headless CentOS 7 server, if I'm missing a more obvious tool to use.</p>

CC BY-SA 4.0
2020-12-13T04:35:17.750Z
Share full log.
Gyan
CC BY-SA 4.0
2020-12-13T05:30:17.643Z
@Gyan I added that above. Thanks for your help!
Timothy R. Butler
<ffmpeg><streaming><rtmp>
Infinite loop RTMP Stream Using FFmpeg or Equivalent
Timothy R. Butler
# Infinite loop RTMP Stream Using FFmpeg or Equivalent

(Asked by: username_0 on 2020-12-13)

I'm trying to do an infinite loop RTMP stream on a CentOS 7 server and it seems like FFmpeg would be the best way to accomplish that.  However, I cannot seem to coax FFmpeg into doing it despite following different variations of parameters I've found on StackExchange and elsewhere. I started by trying to simply have FFmpeg go through a playlist of H.264/AAC MP4 files that are remuxed from OBS Studio. It couldn't cleanly jump from MP4 file to MP4 file, giving errors such as:
 [mpegts @ 0x1e5b860] DTS discontinuity in stream 0: packet 30 with DTS 126030, packet 31 with DTS 128970

After that failed, I converted all the files from MP4 to TS using this command (as mentioned in a few places such as here):
ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts

I can get FFmpeg to stream successfully once through a playlist after doing that, using this command:
ffmpeg -stream_loop -1 -re -f concat -i list.txt -c copy -f flv -flvflags no_duration_filesize -bsf:a aac_adtstoasc -preset veryfast "rtmp://{RTMP Server}/static/{My Streaming Key}"

However, it still stops after it gets through the playlist once. Is there something I'm missing here? Here's the full output of a session with those parameters:
ffmpeg version 3.4.8 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --disable-encoder=libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[mpegts @ 0x133a100] DTS discontinuity in stream 0: packet 41 with DTS 126041, packet 42 with DTS 129003
[concat @ 0x1330e80] DTS discontinuity in stream 0: packet 41 with DTS -5965, packet 42 with DTS -3003
Input #0, concat, from 'list.txt':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720, 240 fps, 240 tbr, 90k tbn, 60k tbc
    Stream #0:1(und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 265 kb/s
Output #0, flv, to 'rtmp://{RTMP Server}/static/{My Streaming Key}':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 1280x720, q=2-31, 240 fps, 240 tbr, 1k tbn, 90k tbc
    Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 48000 Hz, stereo, fltp, 265 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mpegts @ 0x1835860] DTS discontinuity in stream 0: packet 30 with DTS 126030, packet 31 with DTS 128970
Error while filtering: Illegal seek90065kB time=00:04:46.19 bitrate=2578.0kbits/s speed=   1x    
[flv @ 0x140b7c0] Failed to update header with correct duration.
[flv @ 0x140b7c0] Failed to update header with correct filesize.
frame= 8658 fps= 30 q=-1.0 Lsize=   90067kB time=00:04:46.22 bitrate=2577.8kbits/s speed=   1x    
video:83684kB audio:5989kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.439653%

There are a couple of errors you can see during the stream (a few lines up from the bottom), but then it keeps chugging along, streams some more with what you see on the very last line and then appears to exit without an error.
I'd like to not only get it working, but ideally do so in a way that keeps the source files in H.264/AAC or something else that makes the job easy on FFmpeg, so that FFmpeg doesn't have to repeatedly re-transcode the same files each time it loops. (Both to avoid degrading the video more than necessary and also to make the work as light on my server, which has other jobs to do simultaneously.)
I'm open to using something other than FFmpeg if it can run on a headless CentOS 7 server, if I'm missing a more obvious tool to use.

**Tags:** ffmpeg, streaming, rtmp

> **Comments:**
> **username_1**: Share full log.  
> **username_0**: @username_1 I added that above. Thanks for your help!  

---

## 0 answers

