[FFmpeg-user] Continue encoding even if one input stream as no more data for a short amount of time ?

Moff Tigriss moff.tigriss at gmail.com
Fri Jan 6 19:38:00 EET 2017


For a project, I need to secure the continuity of a live stream output.
The issue is that ffmpeg pause encoding when any input as no new data.
He restart only when the source is reactivated, but the output stream
is now broken for the final client here before the cut.

So, simple question : is there a solution to force ffmpeg to continue
encoding even if one stream input has no data for a short amount of
time (< 5 seconds) ?
Black screen, alternate stream, last frame repeated, weird bash
pipes... Anything.

I can use a buffer, of course. But the general latency increase each
time, and I want to keep it under 10 seconds.

My only actualy working solution is to have OpenBroadcasterSoftware, a
desktop software, reading the stream and encoding it to the front rtmp
server. Wich is insane.

Gstreamer, VLC, MEncoder... hell, I even tested v4l. All of them also
pause when source is down, even if they do overlay/compositing from
multi sources.

---- Technical details

My source is a mpegts stream via udp, from another ffmpeg instance who
convert rtmp to mpegts over udp.
When the rtmp source is down, ffmpeg wait the restart (it work). Here,
I have a script who launch a "standing by image" to the udp stream.
And it switch back to the stream later if RTMP is restarted.
The main ffmpeg restart encoding, and everything is good for a new client.

But every client here before the cut have now a broken playback.

---- Command lines
(I removed a lot of fine tuning, so the second one can fail sometime,
just relaunch it.)

ffmpeg \
 -re -i rtmp://server:1935/live/testlive \
 -c copy -bsf:v h264_mp4toannexb -f mpegts udp://

ffmpeg \
 -fflags +genpts -stream_loop -1 \
 -r 30 -i udp:// \
 -vcodec libx264 -preset veryfast -crf 22 \
 -g 60 -c:a aac -b:a 128k -ar 44100 \
 -f flv -rtmp_live live rtmp://

---- Buildonf (also tested with the current git, nothing different, so
I stick to the stable version)

ffmpeg -buildconf
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/usr/local
--extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
--bindir=/usr/local/bin --disable-doc --disable-static --enable-shared
--enable-ffplay --extra-libs=-ldl --enable-version3
--enable-libfdk_aac --enable-libmp3lame --enable-libopus
--enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264
--enable-libx265 --enable-libxvid --enable-libxcb --enable-pthreads
--enable-gpl --enable-avresample --enable-postproc --enable-nonfree
--disable-debug --enable-small --enable-openssl
  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
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100


Thank you if you have an answer, i'm losing my mind to solve that
specific issue, and it's the last element missing for my project.

More information about the ffmpeg-user mailing list