Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG: How to stream to multiple outputs with the same encoding independently

Tags:

ffmpeg

How my stream is working right now:

Input: Switcher program that captures the camera and screen shots and make a different layouts. One of the windows from the software is the one used as Input in the ffmpeg command line.

Output: - Facebook (example) - Youtube (example)

At the beginning, i thought that maybe could be better create two different ffmpeg processes to stream independently to each output. The problem was it uses too much CPU. The answer for it, was to encode one time and copy it to different outputs. Ok, great, it solves the problem, but what if one of the output fails? Both fail.

I'm trying to make one encoding to two outputs and if one of these outputs is not available, the other keep going well.

Anybody have any idea to solve it?

Thanks!

like image 905
Lucas Schoch Avatar asked Jan 26 '17 18:01

Lucas Schoch


People also ask

What does Vsync do in FFmpeg?

According to ffmpeg documentation, -vsync 0 is a passthrough, where each frame is passed with its timestamp from the demuxer to the muxer. -vsync 1 duplicates frames and timecode to achieve exactly the requested constant frame rate.

What is Muxer FFmpeg?

Muxers take encoded data in the form of AVPackets and write it into files or other output bytestreams in the specified container format.

What is Probesize FFmpeg?

The use of –probesize and –analyzeduration help FFMPEG to recognize the audio and video stream parameters of a file, and while they are by no means necessary, their use can help reduce input processing errors, especially when moving across codecs.

What is FFmpeg transcoding?

FFmpeg is a software, which uses all formats for media you may need – H. 264, H. 265, Apple ProRes, Avid DNxHD etc, even also used for images like PNG and others – support all type of platform you're on. It is a command-line tool, it is quicker than some other tools which are available for transcoding.


1 Answers

I found the solution following what @LordNeckbeard said.

Here is a sample code to:

  1. Save a local file
  2. Stream to your server
  3. Stream to Facebook server

Every stream is independent from the other and will try to recover itself independently every one second if something happened like internet connection–will save locally and try to recover when internet access came back–or destination server is not available yet and when it came back it will restart the streaming process):

-i ... -f tee "[onfail=ignore]'C:\Users\blablabla.mp4'|
[f=fifo:fifo_format=flv:drop_pkts_on_overflow=1:attempt_recovery=1:recovery_wait_time=1]rtmp://yourServer...|
[f=fifo:fifo_format=flv:drop_pkts_on_overflow=1:attempt_recovery=1:recovery_wait_time=1]"rtmp://facebook..."
like image 128
Lucas Schoch Avatar answered Nov 15 '22 12:11

Lucas Schoch