5

(Apologies about the question title, not quite sure how to word it)

So I'm working on a turnkey streaming solution / server for a local LAN party, using the fantastic nginx-rtmp to handle incoming RTMP streams from our main PC's and deliver (hopefully) an uninterrupted signal to Twitch and other such streaming services.

One of the main things I'd like to achieve is having the server switch to, say, a local webcam (or another stream) if we're not sending anything to it, which would perfect the zero-downtime approach that I'm aiming for. I've looked into using ffmpeg for this, with arguments along the line of:

ffmpeg -i "rtmp://127.0.0.1/in/stream" -i "rtmp://127.0.0.1/webcam/stream" -vcodec copy -acodec copy rtmp://127.0.0.1/out/stream

but ffmpeg refuses to start outputting unless it's receiving both inputs, and stops completely if it loses one.

Problem is that I can't think of any alternatives, short of:

  • hooking into nginx-rtmp's on_publish_done hook and firing a script or something to trigger a webcam stream to start after a short delay (and then just stopping that stream using the control interface), or
  • having another system running something like Open Broadcaster Software and handling the mixing

If anyone's got any ideas, no matter how silly, I'd really appreciate it, because I'm stumped!

2
+50

To my knowledge your workflow cannot be done within FFmpeg. That workflow can be done server side on Wowza Streaming Engine using a module called Loop until Live.

https://www.wowza.com/docs/how-to-loop-a-pre-roll-until-a-live-stream-starts-loopuntillive

Basic logic.

  1. Stream 1 is the "backup" stream. This can be a VOD preroll file or a live stream.
  2. Stream 2 is the main stream.
  3. If only stream 1 is running then present stream 1. When stream 2 is present then switch to stream 2 on a keyframe.
  4. If stream 2 is stopped then switch to stream 1 on a keyframe.

I have not found that logic in FFmpeg.

Note that it is ideal that all streams are identical when switching from one to another.

Video: Codec, width, height, FPS, keyframe distance (GOP), and bitrate. Audio: Codec, channels, frequency, and bitrate.

FFmpeg is an order dependent filter chain that takes input, modifies it, and then produces output. You can put in images or video and output images or video. Audio is a similar in that you can put one codec in, modify it, and dump it out in the audio format of your choice.

You can have multiple inputs and multiple outputs. In the case of multiple inputs those can be muxed into a single output stream.

Audio and video coming from different sources to create one output.

ffmpeg -i video.input -i audio.input -[modifications] -output

Audio and video coming from one source but going to multiple outputs. I cover that in a post on my blog.

https://videoblerg.wordpress.com/2016/08/16/how-to-create-abr-content-with-ffmpeg-in-one-pass/

FFmpeg is simple by design and I have found nothing in the code that can support your workflow. Doesn't mean I didn't miss it, though.

I know that this is not the answer that you wanted, however you may be able to either add code to FFmpeg to support this functionality or create a tool to perform this function outside of FFmpeg. Any code created should also be input neutral and support RTSP, RTMP, MPEG-TS, RTP/SDP, HLS, and a looping file. As this does not resolve your issue I have no expectation of receiving your bounty of +50 rep.

| improve this answer | |
  • The main issue with this answer is simply wowza is super expensive. For a server that's only going to be taking in one stream at a time, it's not enough to justify the cost to purchase a license. Thanks again for your reply. – Goodbye StackExchange Apr 13 '17 at 0:23
  • He wasn't suggesting @luaduck purchase Wowza, he was using Wowza as an illustrative example of the behavior being sought. – Michael Mol Apr 13 '17 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.