[WORKAROUND] "Smearing" on H.264 RTSP Cameras

Forum for questions and support relating to the 1.26.x releases only.
User avatar
dvarapala
Posts: 53
Joined: Sat Nov 06, 2010 2:30 pm

[WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dvarapala » Wed Feb 12, 2014 3:14 pm

For some time now I have been trying to get a pair of cheap Swann/Hikvision IP cameras from Costco to work with ZoneMinder. Using the FFMPEG camera type works for the most part; however, there are periodic problems with "smeared" images like this one:

Image

This smearing is caused by "lost" RTP packets , specifically during reception of an I frame. FFMPEG's H.264 decoder does a really good job of concealing the occasional lost packet, but when losses occur during an I frame there's nothing the decoder can do.

Needless to say, this smearing wreaks havoc with ZM's motion detection, causing all sorts of false alarms. In the past, the standard workaround was to append "?tcp" to the end of the RTSP URI in the ZM camera configuration; while this used to work, in recent versions of FFMPEG it no longer has any effect. Now in order to force the RTP packets to be sent over a TCP transport layer, you have to hack the ZM code as described here:
This is what I did in FfmpegCamera::PrimeCapture to fix my issue:
AVDictionary *opts = 0;
av_dict_set(&opts, "rtsp_transport", "tcp", 0);
avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts )
With this modification the lost packets are eliminated and the problem goes away.

But why are the RTP packets being lost in the first place? My cameras are on a gigabit LAN, which should have more than enough capacity for dozens of these cameras. It turns out the packet loss is a bug in FFMPEG itself:
the problem is caused by the OS UDP buffer overflowing
this is because rtpproto.c disabled our ring buffer
without the ring buffer the code depends on the OS having large
enough buffers which it plain doesnt

To fix this you would have to do 2 things
first remove "url_add_option(buf, buf_size, "fifo_size=0");" from
rtpproto.c

and second make the rtp code actually work with the udp code with its
fifo, currently the rtp code hacks into the udp code and extracts
its fd and accesses this directly bypassing the fifo, which cannot
work
Although the issue was identified some 2 years ago, there's no indication of an impending fix to FFMPEG. Hopefully the impending switch to libvlc in the next release of ZM will solve this issue once and for all.

sogood007
Posts: 25
Joined: Tue Oct 26, 2004 6:53 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by sogood007 » Thu Feb 13, 2014 5:45 am

YOu can also add ?tcp after your URL.

See this thread
http://www.zoneminder.com/forums/viewto ... 30&t=21651

User avatar
dvarapala
Posts: 53
Joined: Sat Nov 06, 2010 2:30 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dvarapala » Thu Feb 13, 2014 2:57 pm

sogood007 wrote:YOu can also add ?tcp after your URL.
tl;dr?

dazed
Posts: 66
Joined: Thu Feb 13, 2014 5:32 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dazed » Thu Feb 13, 2014 5:46 pm

This is my exact same problem i'm having!

Im new to ZM and have been trying to get my 2MP videre cameras working for the last month...but only at low resolution.
I even built a newer machine with lots of memory but that aint helping even with 1 camera.

I want to try the fix you listed for FfmpegCamera::PrimeCapture but I cant locate that file.
Not sure if its supposed to be zm_ffmpeg_camera.cpp file (which i also cant locate still learning as i go on how to linux, and is listed in log as
Unable to open input *rtsp://admin:admin@192.168.*.*:554/0 due to: Operation now in progress).

If that doesnt work im gonna have to try either going to an earlier release of ZM or finding an older ffmpeg converter.

Any help would be much appreciated...I really wanted a linux solution instead of a windows one for my home security.


Im using ZM 1.2.6.5 and unbuntu Server x63 12.05 LTS

dazed
Posts: 66
Joined: Thu Feb 13, 2014 5:32 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dazed » Fri Feb 14, 2014 7:08 pm

Still trying to figure this out...all I came up with so far is apparently the file I'm looking for is
zm_ffmpeg_camera.cpp whish i can still not find. Ive tried locate and find but to no avail.

This is also the file error that appears in my log as
Unable to open input *rtsp://admin:admin@192.*.*.*:554/0 due to: Operation now in progress
zm_ffmpeg_camera.cpp




I think this is the file I think im looking for because it has some of the Code posted above in it that i found searching google.
I tried posting url of link i found, but board says since im newbie it looks like spam
*https://github.*/ZoneMinder/ZoneMinder/blob/master/src/zm_ffmpeg_camera.cpp add com after github

dazed
Posts: 66
Joined: Thu Feb 13, 2014 5:32 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dazed » Sat Feb 15, 2014 12:07 am

Okay I've got it working somehow with the ?tcp at the end, after trying just for the heck of it again.
I think it may be because I upgraded the ffmpeg from this page https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
(sorry about link because im newbie, and board thinks im spam)

So far picture is fine at full 1920*1080 resolution ...need to check FPS...
Last edited by dazed on Mon May 05, 2014 4:00 pm, edited 2 times in total.

dazed
Posts: 66
Joined: Thu Feb 13, 2014 5:32 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dazed » Tue Feb 25, 2014 12:08 am

WORKS BETTER...but still getting smearing every now and then...guess I'll have to wait until 1.27 gets done with beta since i cant figure out how to install over it.

User avatar
dvarapala
Posts: 53
Joined: Sat Nov 06, 2010 2:30 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dvarapala » Sat Mar 01, 2014 5:31 pm

dazed wrote:I want to try the fix you listed for FfmpegCamera::PrimeCapture but I cant locate that file.
Did you install ZoneMinder from source or from a package using apt-get? If you installed from a package, you may not have the source installed on your machine. In order to make this fix you would need to download the source tarball and build ZoneMinder from scratch.

mikb
Posts: 404
Joined: Mon Mar 25, 2013 12:34 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by mikb » Sat Mar 01, 2014 7:47 pm

dazed wrote:Still trying to figure this out...all I came up with so far is apparently the file I'm looking for is
zm_ffmpeg_camera.cpp whish i can still not find. Ive tried locate and find but to no avail.
FFmpegCamera::PrimeCamera() isn't a filename, it's a C++ class (FFmpegCamera) and a function name (PrimeCamera())

You've got the right filename, and it should be in your zoneminder's "src" directory -- if you installed the source!

You did install from source, right?

dazed
Posts: 66
Joined: Thu Feb 13, 2014 5:32 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dazed » Sat Mar 22, 2014 1:03 am

dvarapala wrote:
dazed wrote:I want to try the fix you listed for FfmpegCamera::PrimeCapture but I cant locate that file.
Did you install ZoneMinder from source or from a package using apt-get? If you installed from a package, you may not have the source installed on your machine. In order to make this fix you would need to download the source tarball and build ZoneMinder from scratch.
Sorry for the untimely response (need to turn on Board notification).

I installed following the wiki...so after adding repository I used apt-get, so i guess it was a package (still learning). As far as doing it from source without copying and pasting, well its past my aged learning curve so far...

Did you get your smearing fixed? I did ask the people you linked in your initial post, and was advised to use the beta...but again I still have not got past that learning curve of compiling short of copy and paste routines, such as the wiki install....I hope they release another version soon.

I have yet to get it to work properly without smearing...

dazed
Posts: 66
Joined: Thu Feb 13, 2014 5:32 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dazed » Sat Mar 22, 2014 1:05 am

mikb wrote:
dazed wrote:Still trying to figure this out...all I came up with so far is apparently the file I'm looking for is
zm_ffmpeg_camera.cpp whish i can still not find. Ive tried locate and find but to no avail.
FFmpegCamera::PrimeCamera() isn't a filename, it's a C++ class (FFmpegCamera) and a function name (PrimeCamera())

You've got the right filename, and it should be in your zoneminder's "src" directory -- if you installed the source!

You did install from source, right?
I fear I installed from package....im not that smart yet....I am old Noob....

mikb
Posts: 404
Joined: Mon Mar 25, 2013 12:34 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by mikb » Sat Mar 22, 2014 7:42 pm

dazed wrote:I fear I installed from package....im not that smart yet....I am old Noob....
Then you will never find zm_ffmpeg_camera.cpp, as that's where it will be ... in the source :(

Either try building from source (if you feel brave enough) or wait for an upgraded package that may or may not fix the problem.

dazed
Posts: 66
Joined: Thu Feb 13, 2014 5:32 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by dazed » Tue Mar 25, 2014 5:06 pm

Well I searched wiki and i see that a page is up for 1.27 and Ubuntu.Also apt-get dist-upgrade worked and upgraded my ZM...THANK YOU!

All seems to be working good in the first 30 mins I havent recorded any more Smeared Images as the OP shows.

hre1
Posts: 2
Joined: Mon Apr 14, 2014 2:50 pm

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by hre1 » Mon Apr 14, 2014 3:05 pm

after cloning the git (1.27.1) and apply the patch i tried to compile the source but i get the following error:

Code: Select all

arm-linux-gnueabi-g++ -DHAVE_CONFIG_H -I. -I..  -I/usr/include -I/usr/include -D__STDC_CONSTANT_MACROS -Wall -finline-functions -fomit-frame-pointer -I/usr/include -D__STDC_CONSTANT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_CONSTANT_MACROS -DHAVE_LIBCRYPTO -MT zm_ffmpeg_camera.o -MD -MP -MF .deps/zm_ffmpeg_camera.Tpo -c -o zm_ffmpeg_camera.o zm_ffmpeg_camera.cpp
zm_ffmpeg_camera.cpp: In member function ‘virtual int FfmpegCamera::Capture(Image&)’:
zm_ffmpeg_camera.cpp:128:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
zm_ffmpeg_camera.cpp:133:17: error: ‘av_err2str’ was not declared in this scope
zm_ffmpeg_camera.cpp:136:17: error: ‘av_err2str’ was not declared in this scope
make[3]: *** [zm_ffmpeg_camera.o] Error 1
make[3]: Leaving directory `/usr/local/src/zoneminder/ZoneMinder/src'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/usr/local/src/zoneminder/ZoneMinder'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/local/src/zoneminder/ZoneMinder'
dh_auto_build: make -j1 returned exit code 2
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
What do i'm missing to compile the code successfully? :?

motion2082
Posts: 18
Joined: Thu Mar 13, 2014 1:21 am

Re: [WORKAROUND] "Smearing" on H.264 RTSP Cameras

Post by motion2082 » Mon May 05, 2014 1:07 am

Hey guys,

I just purchased some Hikvision 2032 Bullet Cameras.

Having the same smearing issues with my cameras on Zoneminder, image looks grainy and monitor turns read after a few seconds. I'm going to try this link when I get home https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests