Page 1 of 1

RTSP stream reaching EOF

Posted: Thu Mar 06, 2014 5:46 pm
by kristoffer
Hello,

I wish to report a bug.
One of the my cameras i use (a Qihan IP-101) supports only streaming video over RTSP. To get that up and running in ZoneMinder i use the "ffmpeg" source-type.
A few times a day the image go red, and it does not come back until i either restart zoneminder, or deactivate+active the monitor.
It seems random as to when the image fails. Sometimes its ok for a day, sometimes it go red after a few seconds. "Normally" though, the image is ok for a few hours.

The log spams
Unable to read packet from stream 0: error -541478725.
I am using ZoneMinder 1.26.5, and ffmpeg:

Code: Select all

ffmpeg -version
ffmpeg version 2.0.2
built on Oct 27 2013 11:01:22 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-pthreads --enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv --enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --disable-stripping
libavutil      52. 38.100 / 52. 38.100
libavcodec     55. 18.102 / 55. 18.102
libavformat    55. 12.100 / 55. 12.100
libavdevice    55.  3.100 / 55.  3.100
libavfilter     3. 79.101 /  3. 79.101
libswscale      2.  3.100 /  2.  3.100
libswresample   0. 17.102 /  0. 17.102
libpostproc    52.  3.100 / 52.  3.100
I changed zm_ffmpeg_camera.cpp:219 to:

Code: Select all

Error( "Unable to read packet from stream %d: error %d. avErrorString: %s", packet.stream_index, avResult, av_err2str(avResult) );
And the error in the logs is now:
ERR [Unable to read packet from stream 0: error -541478725. avErrorString: End of file]
Some googling suggests that there is no point in trying to read more frames; however this is what ZoneMinder does.

Currently im trying to get the capture daemon to quit itself by changing:

Code: Select all

int avResult = av_read_frame( mFormatContext, &packet );
        if ( avResult < 0 )
        {
           Error( "Unable to read packet from stream %d: error %d.", packet.stream_index, avResult );
            return( -1 );
        }
into:

Code: Select all

int avResult = av_read_frame( mFormatContext, &packet );
        if ( avResult < 0 )
        {
            if (avResult == AVERROR_EOF || (mFormatContext->pb && mFormatContext->pb->eof_reached))
            {
                Fatal("Current stream reached EOF.");
            }
            Error( "Unable to read packet from stream %d: error %d. avErrorString: %s", packet.stream_index, avResult, av_err2str(avResult) );
            return( -1 );
        }
I'm still waiting for the first EOF to see if the code-change has the effect i hope it will have.

Im reporting this before i have any results, because i still think ZoneMinder should handle errors from FFMPEG better than it does now; which is basically to not handle errors at all.

Im also not sure if the correct way to handle the error is to kill the capture daemon; maybe it would be better to just re-open the stream. Im thinking that whatever is the fastest way to get the video back is the best way so i miss as little video as possible.

Oh, and also; a few ppl on the net seems to have similair issues. They seem to fix this by adding "?tcp" to the url to force a TCP-connection. Unfortunately i cannot get a tcp-stream running no matter what i try. Maybe my camera does not do TCP.

Re: RTSP stream reaching EOF

Posted: Fri Mar 07, 2014 10:29 am
by kristoffer
While waiting for the EOF to happen again i thought i'd see what happens if i restart the camera.
The new code did trigger; the log showed "Current stream reached EOF.", and the process exited, and a new process was started. However i never got the video back, so the above codechange is not enough to recover from a lost signal. I will debug this further.

Meanwhile, is anyone else experiencing issues when, for example, restarting cameras that is connected to ZoneMinder using RTSP?

Re: RTSP stream reaching EOF

Posted: Fri Mar 07, 2014 12:47 pm
by kristoffer
So i checked my logs, and it seems I've had some "red-screens" this morning. The difference today is that the video didn't go red!
the zmc daemon quitted itself with the "Current stream reached EOF." message, and afterwards its restarted by zmdc.

So my fix above seems to work for short interruptions to the streaming.

For those interested, i've included my zmc debug logs + /var/log/messages for this interruption; and to me it looks like the system is behaving the way i expected it to.

Ill proceed now to debugging why ZoneMinder looses video when i restart the camera.

Re: RTSP stream reaching EOF

Posted: Tue Mar 11, 2014 3:39 pm
by kristoffer
After testing the code for a few days, it seems my camera now survives red-screens.
I'm still having issues when restarting the camera, but I'll debug that in another thread.

The finished code became

Code: Select all

        int avResult = av_read_frame( mFormatContext, &packet );
        if ( avResult < 0 )
        {
            if (avResult == AVERROR_EOF || (mFormatContext->pb && mFormatContext->pb->eof_reached))
            {
                Fatal("Current stream reached EOF.");
            }
            Error( "Unable to read packet from stream %d: error %d \"%s\".", packet.stream_index, avResult, av_err2str(avResult) );
            return( -1 );
        }

Re: RTSP stream reaching EOF

Posted: Wed Mar 19, 2014 6:19 pm
by kristoffer
To anyone reading this topic and is having similar issues, i made a new thread at http://www.zoneminder.com/forums/viewto ... =9&t=22024 which includes the fix in this topic, and also fixes a few other ffmpeg-issues.