Lucas Schoch
Lucas Schoch

Reputation: 131

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

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!

Upvotes: 6

Views: 11905

Answers (2)

Lucas Schoch
Lucas Schoch

Reputation: 131

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..."

Upvotes: 7

llogan
llogan

Reputation: 133743

Example using the tee muxer with the onfail option and also output a local file:

ffmpeg -i input -map 0 -c:v libx264 -c:a aac -maxrate 1000k -bufsize 2000k -g 50 -f tee "[f=flv:onfail=ignore]rtmp://facebook|[f=flv:onfail=ignore]rtmp://youtube|[f=segment:strftime=1:segment_time=60]local_%F_%H-%M-%S.mkv"

Also see:

Upvotes: 4

Related Questions