4

My BeeCam is a Raspberry Pi3/Raspbian Stretch w/freshly compiled ffmpeg version N-89882-g4dbae00bac running this as a service:

#!/bin/bash
cd /usr/local/bin/
while true
do
./ffmpeg -re -thread_queue_size 512 -rtsp_transport tcp -i \
"rtsp://anonymous:password@192.168.1.11:554" -i WilliamTellOverture.mp3 \
-vcodec copy -acodec copy -t 00:11:51 -f flv \
"rtmp://a.rtmp.youtube.com/live2/my-youtube-streaming-key"
sleep 10s
done

where 192.168.1.11 is my spiffy new Reolink RLC-423S, and -t 00:11:51 is the length of my royalty-free MP3. This normally works quite well:

https://www.youtube.com/user/IAmTheWaterbug/live

and it loops continuously. The YT stream will glitch when it restarts, but the stream resumes with only about 15 seconds of video lost. It ran continuously overnight for at least 8 hours (e.g. many loops) before I started fiddling with it.

I changed the sleep to 5s, and that doesn't seem to bother it.

But on occasion I've done a sudo systemctl stop StreamToYouTube followed by sudo systemctl start StreamToYouTube, within 1-2 seconds (e.g. as fast as I can type Up Up Up and Enter), and sometimes when I do that, the stream fails, and ffmpeg starts dumping:

[rtsp @ 0x302c2f0] RTP: PT=60: bad cseq e680 expected=0b49
[rtsp @ 0x302c2f0] RTP: PT=60: bad cseq 93ab expected=0b49
[rtsp @ 0x302c2f0] RTP: PT=60: bad cseq 93ac expected=0b49
[rtsp @ 0x302c2f0] RTP: PT=60: bad cseq e682 expected=0b49

endlessly.

Rebooting the Pi doesn't fix this (e.g. the YT stream still fails, and sudo systemctl status StreamToYouTube returns the same stream of "bad cseq" errors), but rebooting the camera does fix it. I'm wondering what exactly that error means, and how to report this to Reolink.

During the "failed" state, the camera appears to be working properly from other clients, e.g. I can launch the Reolink.app on my Mac or view the camera's web page from any browser, and the video looks fine.

But for some reason the RTSP stream goes funky in a way that ffmpeg can't resolve.

It's quite repeatable if I stop/start the service quickly, but restarting with a 5 second pause in my script doesn't seem to bother it.

Thanks!

1 Answers1

2

I had a similar issue on my Reolink C2, in a custom NodeJS program that was using ffmpeg as a child-process (on my Windows computer).

Had the same sort of errors ("RTP: PT=60: bad cseq a5b6 expected=4e9b", etc.), and similar high-level symptoms (starting a second stream soon after would fail, but streams would work fine from other devices like my phone).

One difference is that in my case, the issue would resolve as long as I let the camera sit (without trying to start any streams!) for about 30 seconds to a minute. So perhaps it's a firmware difference where my model automatically terminates/cleans-up old streams after a certain time period, whereas yours doesn't.

Anyway, I eventually discovered the fix for my case: https://github.com/agsh/rtsp-ffmpeg/issues/35

Summary: The library I was using to start the ffmpeg stream was not "gracefully terminating" the ffmpeg process when it wanted the stream to end. It was just calling process.kill(), which was causing the issue.

Once I changed that process.kill() line to process.stdin.write("q\r\n"), the problem completely resolved. (apparently some versions of ffmpeg accept the q command through its standard-input to gracefully exit, whereas others don't -- so the solution might be different for Linux and Mac)

I don't know the details of your approach for starting and stopping ffmpeg, but I would suggest taking a close look at the code to terminate the process, and ensuring it allows ffmpeg to "gracefully exit", as that is what solved the problem for me.

Venryx
  • 394
  • 3
  • 10