[FFmpeg-user] fault-tolerant streaming and local saving at the same time

Daniel Tisch tisch.daniel at gmail.com
Fri Dec 2 13:30:37 EET 2016


Hi Folks,

I am trying to achieve what the subject says, and I would like to get some
feedback on my setup and a bit of help.

The problem: if I use a single ffmpeg command line to read the raw frames
from my Blackmagic Decklink capture card, encode it and A) stream over RTMP
to a remote server and B) save a local copy, then in case of either network
error or file write error (e.g. disk full), the whole process stops, so not
only the live stream fails, but I get no backup as well.

My intended solution: use 3 processes instead of one: 1) for capturing from
the decklink card and passing the media to 2 outputs, 2) for streaming and
3) for saving to file. But as far as I connect them through pipes, the
problem remains. Now I think the best option would be to connect the
processes with udp://127.0.0.1:xxxx style targets, because it is reliable
enough on the localhost, but the sender will not get stuck if any of the
receiver processes get stuck or die. For this to work, I need to use a
muxer in 1), that ensures audio-video sync, and that enables 2) and 3) to
demux the content even after they restart, so when they do not have the
full output, just start to listen to it somewhere in the middle. I am
trying to use mpegts for that.

My first question: is it the way to go, or am I missing something that
would enable a lot simpler setup?

My second question: how to open the input in 2) and 3), if 1) looks
something like this:
ffmpeg -i some_source -acodec pcm_u16le -vcodec yuv4 -f mpegts udp://
127.0.0.1:20000
I have tried more things like this:
ffmpeg -f mpegts -f rawvideo -s 1280x720 -pix_fmt yuv420p -f u16le -ar
44100 -ac 2 -i udp://127.0.0.1:20000 some_output
but I always get "Option video_size not found."

Thank you very much for your insights! The full ffmpeg commands and outputs
are below.

Thanks,
Daniel


sender:

user at host:~$ ffmpeg -i ~/Videos/Moments_of_Everyday_Life.mp4 -acodec
pcm_u16le -vcodec yuv4 -f mpegts udp://127.0.0.1:20000
ffmpeg version 2.8.8-0ubuntu0.16.04.1 Copyright (c) 2000-2016 the FFmpeg
developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1
--build-suffix=-ffmpeg --toolchain=hardened
--libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu
--cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping
--disable-decoder=libopenjpeg --disable-decoder=libschroedinger
--enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa
--enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca
--enable-libcdio --enable-libflite --enable-libfontconfig
--enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm
--enable-libmodplug --enable-libmp3lame --enable-libopenjpeg
--enable-libopus --enable-libpulse --enable-librtmp
--enable-libschroedinger --enable-libshine --enable-libsnappy
--enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora
--enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack
--enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi
--enable-openal --enable-opengl --enable-x11grab --enable-libdc1394
--enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264
--enable-libopencv
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'/home/dani/Videos/Moments_of_Everyday_Life.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2012-03-13 03:50:30
  Duration: 00:01:07.94, start: 0.000000, bitrate: 7994 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,
bt709), 1280x720 [SAR 1:1 DAR 16:9], 7804 kb/s, 23.98 fps, 23.98 tbr, 23976
tbn, 47.95 tbc (default)
    Metadata:
      creation_time   : 2012-03-13 03:50:30
      handler_name    : Mainconcept MP4 Video Media Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 189 kb/s (default)
    Metadata:
      creation_time   : 2012-03-13 03:50:30
      handler_name    : Mainconcept MP4 Sound Media Handler
Output #0, mpegts, to 'udp://127.0.0.1:20000':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf56.40.101
    Stream #0:0(eng): Video: yuv4, yuv420p, 1280x720 [SAR 1:1 DAR 16:9],
q=2-31, 200 kb/s, 23.98 fps, 90k tbn, 23.98 tbc (default)
    Metadata:
      creation_time   : 2012-03-13 03:50:30
      handler_name    : Mainconcept MP4 Video Media Handler
      encoder         : Lavc56.60.100 yuv4
    Stream #0:1(eng): Audio: pcm_u16le, 44100 Hz, stereo, s16, 1411 kb/s
(default)
    Metadata:
      creation_time   : 2012-03-13 03:50:30
      handler_name    : Mainconcept MP4 Sound Media Handler
      encoder         : Lavc56.60.100 pcm_u16le
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> yuv4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_u16le (native))
Press [q] to stop, [?] for help
frame=  930 fps=188 q=-0.0 Lsize= 1360964kB time=00:00:38.83
bitrate=287120.2kbits/s
video:1255500kB audio:6684kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 7.826142%


receiver:

user at host:~$ ffmpeg -f mpegts -f rawvideo -s 1280x720 -pix_fmt yuv420p -f
u16le -ar 44100 -ac 2 -i udp://127.0.0.1:20000 -vcodec mpeg4 -acodec mp3 -y
Videos/output.flv
ffmpeg version 2.8.8-0ubuntu0.16.04.1 Copyright (c) 2000-2016 the FFmpeg
developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1
--build-suffix=-ffmpeg --toolchain=hardened
--libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu
--cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping
--disable-decoder=libopenjpeg --disable-decoder=libschroedinger
--enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa
--enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca
--enable-libcdio --enable-libflite --enable-libfontconfig
--enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm
--enable-libmodplug --enable-libmp3lame --enable-libopenjpeg
--enable-libopus --enable-libpulse --enable-librtmp
--enable-libschroedinger --enable-libshine --enable-libsnappy
--enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora
--enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack
--enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi
--enable-openal --enable-opengl --enable-x11grab --enable-libdc1394
--enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264
--enable-libopencv
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Option video_size not found.


More information about the ffmpeg-user mailing list