sistason / rtmp_stream_delayer

Uses ffmpeg and nginx to delay (buffer) an incoming rtmp-stream for an amount of time.
GNU General Public License v2.0
42 stars 12 forks source link

Only showing backup stream #2

Closed XBase-xOR closed 5 years ago

XBase-xOR commented 7 years ago

I was wondering why the script would never publish my main stream from the file but always the backup stream. I don't know Python but is it correct that the publish_stream function will never set "ret = True" anywhere?

Just for testing I changed line 43 to "ret = True" and and finally my main stream was published. However, now it won't fall back to the backup stream if I end the main stream. The script will just end and delete the .flv file.

sistason commented 7 years ago

The script will never set ret=True, as I haven't found out yet how to distinguish a stop of the video because of an client had an error or because the client has pressed stop. (Which is probably only possible by checking the video-file-end)

I think your problem is with avconv / the command calling avconv. I scripted this a long time ago, so change Line 44 from "except:" to "except Exception as e:" and insert a "print e" in the line below to check if this is where the error was.

On the other hand, your problem doesn't make sense, as the stream gets published before the ret = True. If you set ret = True, the program just stops after playing your stream.flv, but your problem is that the stream doesn't get played in the first place? :)

Anyway, let's see what we can debug ;)

XBase-xOR commented 7 years ago

Yeah you're right, I changed it back to "ret = False" and this time it started the main stream - and it even fell back to the backup stream when I ended the main stream. It seems there is some sort of timing issue which makes it work sometimes and sometimes not.

Anyway, so far, so good. Unfortunately when I started the main stream again this lead to 2 instances of avconv running at the same time: one with file input and one with rtmp input from the backup stream. On the output the backup stream was still visible and the main stream didn't come back. From experimenting I know that you can't send two streams at the same time to one nginx-rtmp application. The second instance will fail to send the stream with the message "Could not find codec parameters for stream 0 (Video: none, none, 2560 kb/s): unknown codec", which is probably what is happening here. I can also see two instances of your python script running.

If I end the main stream again the avconv instance with the file input disappears and a second instance with the backup rtmp stream appears. I assume if I keep on starting and stopping the main stream I will get more and more instances.

I can see that you got code that checks whether an instance of the script is already running but maybe that part isn't working?

XBase-xOR commented 7 years ago

TBH I am not sure whether that script is for me anyway. I don't even need the delay, I just wanted the fallback functionality with the idea in mind that the stream is not interrupted - and by that I mean that the stream really keeps running: no rtmp disconnect for viewers, no new stream session shown by Twitch Inspector, clients aren't dropped from the stream.

But when I manually end one avconv copy process and start another one (trying to be really fast about it) I always get a short interruption and Twitch Inspector shows me the current stream ended and a new one started. I believe a Python script can't change that fact that there is no way to get a smooth transition from one input to another, or am I wrong?

sistason commented 7 years ago

Yeah, you get a disconnect, as it is another source. TBH, I never tested the backup-functionality and never used it, so I would've been surprised if that worked ;) You could write something like that maybe with nginx' record-append... But idk.

I will possibly use this script again in this year, so I will maybe fix the timing issue in the future. But if you need something for a backup-failover-stream, this isn't for you. Good luck on your search.