Page 1 of 1

FFMPEG stability fixes. (video going red, "red-screen")

Posted: Wed Mar 19, 2014 6:18 pm
by kristoffer
I'm using FFMPEG to stream video from a IP-camera to ZoneMinder using rtsp.
I had issues with this; screen is going red at random times. It also goes red if i restart my camera.
And it stays red. Forever (even though i didn't verify that :D)

At first i changed the code to just exit the capture daemon if certain errors occured; however that had side-effects. One thing i noticed was that; if i'm watching the monitor and restart the camera; the image freezes (or goes blank, cant remember). When the capture daemon has restarted, the monitor doesnt come live again. So that kinda sucked even though the recording still worked again.

I've improved my patch now, and instead of exiting the capture daemon it silently re-opens the stream instead. By silently i mean that it logs some errors, and then closes and reopens the stream. The good part is that the capture daemon never restart.

While this is going on the red-screen is generated as it should.

What the patch does is:
  • Timeout when opening stream after 10 seconds
    Sometimes when restarting the camera ffmpeg hung itself in some state, when calling avformat_open_input, which seemed to last forever.
  • Reopen stream if av_read_frame returns EOF
    Sometimes ffmpeg starts returning an EOF error when calling av_read_frame. Once this happens it seems no more images will ever be captured.
  • Reopen stream if av_read_frame returns -110
    Means something like Connection failed; cant remember. Anyway. Once this happens it seems no more images will ever be captured.


Please try out the patch if you have stability issues when using ffmpeg sources.

I've applied the patch to the 1.27.0 version.
However it seems the affected files has not changed since 1.26.5, so the patch *should work* on 1.26.5 too.

Apply the patch by going to the ZoneMinder source directory and do:

Code: Select all

patch -p1 < ./ffmpeg_eof_fix.patch
ps. had to zip the file to be allowed to upload it, so unzip it first :)

Re: FFMPEG stability fixes. (video going red, "red-screen")

Posted: Thu Mar 20, 2014 1:26 pm
by knight-of-ni
Nice work. May I suggest you bring this over to github where it will get better visibility.
Create a github account, fork the zonemidner repo, apply your patch, and then generate a pull request.
https://help.github.com/articles/fork-a-repo

Re: FFMPEG stability fixes. (video going red, "red-screen")

Posted: Fri Mar 21, 2014 9:00 am
by kristoffer
I've been thinking that. Thanks for the startup pointers.

Re: FFMPEG stability fixes. (video going red, "red-screen")

Posted: Tue Apr 01, 2014 3:11 pm
by scooter217
When i run the patch, its asking for "File to patch". I am assuming it needs the location of the file to patch but i am not certain of the location. I am running ubuntu 12.04 64 bit server. I think my main install is /usr/share/zoneminder but i could be wrong. Still learning my way around linux.

Re: FFMPEG stability fixes. (video going red, "red-screen")

Posted: Tue Apr 01, 2014 3:56 pm
by kristoffer
The patch is intended to modify the source-code of ZoneMinder.

Did you download the source of ZoneMinder and compiled it yourself, or did you install some package?

Re: FFMPEG stability fixes. (video going red, "red-screen")

Posted: Tue Apr 01, 2014 4:32 pm
by scooter217
I installed zoneminder a few days ago following the wiki. Would i need to recompile my install to get the patch to work?

http://www.zoneminder.com/wiki/index.ph ... e_easy_way

Re: FFMPEG stability fixes. (video going red, "red-screen")

Posted: Tue Apr 01, 2014 4:51 pm
by kristoffer
That guide would install a pre-compiled package, so yes you'd need to uninstall that.
If you value your existing videos, i'd recommend you to setup a test-environment to begin with.

http://www.zoneminder.com/wiki/index.ph ... n#Building describes how to compile zoneminder; however, to me that guide looks old. Then again maybe it's for pre-1.27.

I'm using 1.27 (well, actually the master branch on github) myself.

The above url + README + INSTALL files in source directory should get you started :)

Re: FFMPEG stability fixes. (video going red, "red-screen")

Posted: Tue Apr 01, 2014 6:44 pm
by scooter217
Thanks, I am going to build a vm this week to test it out. I will snapshot the vm because i am sure I will mess up a few times compiling.