eroji / rtsp2mjpg

RTSP to MJPEG stream conversion using FFmpeg and FFserver
99 stars 41 forks source link

Stream freezes after ~20 seconds #6

Closed korethegenius closed 3 years ago

korethegenius commented 4 years ago

Thanks for making this great container!

I've been having this issue on my Pi 4 and also iMac where the stream runs fine for ~15-20 seconds and then freezes. At the same time, there seems to be huge CPU demand while it's running. Any ideas about the cause?

eroji commented 4 years ago

CPU usage is going to be high unfortunately due to the nature of video transcoding. In terms of video stream freezing, it could be a number of things and I cannot say for certain what it is for your setup. You can check and see if the container itself logged any errors. It is possible that ffmpeg process died due to some sort of problem. You may need to tweak the ffserver.conf and ffmpeg command parameters.

korethegenius commented 4 years ago

Thanks - any idea what the error is related to?

`rtsp2mjpg_1 | Metadata:

rtsp2mjpg_1 | encoder : Lavc57.107.100 mjpeg

rtsp2mjpg_1 | Side data:

rtsp2mjpg_1 | cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1

rtsp2mjpg_1 | Stream #0:1: Video: mjpeg, yuv420p, 1920x1080, q=1-15, 200 kb/s, 15 fps, 1000k tbn, 2 tbc

rtsp2mjpg_1 | Metadata:

rtsp2mjpg_1 | encoder : Lavc57.107.100 mjpeg

rtsp2mjpg_1 | Side data:

rtsp2mjpg_1 | cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1

rtsp2mjpg_1 | [rtsp @ 0x16ff370] CSeq 12 expected, 0 received.

rtsp2mjpg_1 | [h264 @ 0x171dd50] error while decoding MB 49 65, bytestream -13

rtsp2mjpg_1 | [h264 @ 0x171dd50] concealing 360 DC, 360 AC, 360 MV errors in I frame

rtsp2mjpg_1 | frame= 2731 fps=5.2 q=24.8 Lq=24.8 size= 270852kB time=00:03:02.50 bitrate=12157.9kbits/s dup=0 drop=2365 speed=0.349x

rtsp2mjpg_1 | video:269871kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.363657%`

eroji commented 4 years ago

Looks like there's problem with the source stream. This is something I ran into myself because my wifi network was dropping packets. Video transcoding is very time sensitive. FFmpeg expects the source stream data to arrive as close to realtime as possible and in sequence. If you have packet loss, the packet will need to be resent and will arrive out of sequence. So when FFmpeg is transcoding the frames to mjpeg, it's doing frame 1-2-3-4-5... but the frame arrived as 1-2-??-4-5-3, this will cause it to barf and stop. Disclaimer, I am not an expert on ffmpeg at all, but it is what I found as part of researching into my problem. After I fixed the packet loss (cabling problem) it was far more improved, but wireless camera is nontheless not ideal source feed.