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

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
kristoffer
Posts: 15
Joined: Thu Mar 06, 2014 5:18 pm

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

Post 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 :)
Attachments
ffmpeg_eof_fix.zip
patch file
(3.1 KiB) Downloaded 453 times
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

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

Post 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
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
kristoffer
Posts: 15
Joined: Thu Mar 06, 2014 5:18 pm

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

Post by kristoffer »

I've been thinking that. Thanks for the startup pointers.
scooter217
Posts: 4
Joined: Tue Dec 09, 2008 10:51 pm

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

Post 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.
kristoffer
Posts: 15
Joined: Thu Mar 06, 2014 5:18 pm

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

Post 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?
scooter217
Posts: 4
Joined: Tue Dec 09, 2008 10:51 pm

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

Post 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
kristoffer
Posts: 15
Joined: Thu Mar 06, 2014 5:18 pm

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

Post 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 :)
scooter217
Posts: 4
Joined: Tue Dec 09, 2008 10:51 pm

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

Post 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.
Post Reply