Send output to multiple destinations

0

I'm really new on ffmpeg and have a question where I cannot find a solution. I really hope that somebody from you could help me with that.

On one server I receive a 1080p stream, with ffmpeg I create a new stream with multiple bitrates and resolution and send it afterwards to a rtmp destination on this server. Below CL the command that I use at the moment and it is working.

ffmpeg -i - -copyts -muxdelay 0  -c:a libfaac -ab 128k 
-c:v libx264 -preset faster -profile:v main -level 3.1 -crf 20 -g 50 -b:v 1500k -s:v 1920x1080 -f flv rtmp://localhost/stream/output_stream 
-c:a libfaac -ab 64k -c:v libx264 -preset faster -profile:v main -level 3.1 -crf 23 -g 50 -b:v 1000k -s:v 1280x720 -f flv rtmp://localhost/stream/output_stream 
-c:a libfaac -ab 32k -c:v libx264 -preset faster -profile:v main -level 3.1 -crf 23 -g 50 -b:v 800k -s:v 960x540 -f flv rtmp://localhost/stream/output_stream

Now I have the challenge that I need to send it to multiple servers. Is there anyway to add multiple outputs?

At the end the incoming 1080p stream should get multiple bitrates and should be send to around 10 different RTMP server.

I really hope that somebody can help me with that.

Chris

Posted 2019-03-01T12:03:24.570

Reputation: 1

Answers

1

You can use the tee muxer if any same streams are to be sent to multiple outputs, but that's not the case with your example because each output is receiving a different stream.

However, audio doesn't take up much bitrate compared to video, so you can consider ditching the multiple audio bitrates, encode it only once, and use that same stream for all of the outputs. Basic example:

ffmpeg -i input -filter_complex \
"[0:v]split=2[s0][s1];[s0]scale=1280:-2[v0];[s1]scale=960:-2[v1]" \
-map "[v0]" -map "[v1]" -map 0:a -c:v libx264 -b:v:0 1000k -b:v:1 800k -c:a aac -flags +global_header -f tee \
"[select=\'v:0,a\':f=flv:onfail=ignore]rtmp://localhost/stream/output_stream0|[select=\'v:1,a\':f=flv:onfail=ignore]rtmp://localhost/stream/output_stream1"

Unrelated, but you're using libfaac which means your ffmpeg is ancient. So you really should upgrade.

llogan

Posted 2019-03-01T12:03:24.570

Reputation: 31 929

Many thanks for your help and sorry for my late reply. When I use this command I get below warning, any clue?

Codec for stream 0 does not use global headers but container format requires global headers – Chris – 2019-03-14T09:04:26.787

@Chris Command updated. Forgot the -flags +global_header previously. – llogan – 2019-03-14T17:06:34.603

I added it and it is gone now, but when I stop ffmpeg I get below error Failed to update header with correct duration. Failed to update header with correct filesize. Also onfail=ignore is not working, get always error "Unknown option onfail" – Chris – 2019-03-15T07:43:50.723

@Chris I'm guessing you're using an ancient ffmpeg. As I mentioned in the answer I strongly recommend you update to a recent version. You didn't mention your OS, so I can only recommend taking a look at the links to builds at FFmpeg Download.

– llogan – 2019-03-15T17:14:02.900