[FIX] ZM 1.24.2 "Error, failed to query crop"

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.
dclarke
Posts: 7
Joined: Wed Feb 10, 2010 3:17 am

[FIX] ZM 1.24.2 "Error, failed to query crop"

Post by dclarke » Wed Feb 10, 2010 3:47 am

A USB camera that doesn't support cropping will produce an error message "Error, failed to query crop: /dev/video0: Invalid argument" from zmu -q -v.

Failures are exhibited in zmu, and other places that rely on LocalCamera::GetCurrentSettings.

The fault is in LocalCamera::GetCurrentSettings.

The error arises from the fact that ioctl VIDIOC_G_CROP returns -1 and errno = EINVAL to indicate that cropping is not supported. (See http://v4l2spec.bytesex.org/spec/r9994.htm). LocalCamera::GetCurrentSettings treats any negative rc from ioctl VIDIOC_G_CROP as grounds for abnormal termination.

The fix is straightforward and short. All changes are in zm_local_camera.cpp as follows:

Code: Select all

911,912c911
< 	    int crop_rc = vidioctl( vid_fd, VIDIOC_G_CROP, &crop );
<             if ((crop_rc  < 0 ) && (errno != EINVAL))
---
>             if ( vidioctl( vid_fd, VIDIOC_G_CROP, &crop ) < 0 )
921,928c920,921
<             if ( verbose ) {
< 		if (crop_rc >= 0) {
< 	                sprintf( output+strlen(output), "  Current: %d x %d\n", crop.c.width, crop.c.height );
< 		}
< 		else {
< 			sprintf( output+strlen(output), "  Current: Cropping is not supported\n");
< 		}
< 	    }
---
>             if ( verbose )
>                 sprintf( output+strlen(output), "  Current: %d x %d\n", crop.c.width, crop.c.height );

whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy » Wed Feb 10, 2010 4:38 am

Don't have any USB cammeras but I bookmaked this thread!!!

Thank you very much... I have seen alot of people with this problem... hope it gets in the new version!!!

User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle
Contact:

Post by cordel » Wed Feb 10, 2010 5:06 am

Thank you for this. Unfortunately we don't use webcams so they don't get the attention they need unless someone loans us one. I have marked this in the developer section to look at patching into the trunk.

Thank you for helping out. :D

jcglt
Posts: 5
Joined: Fri Feb 12, 2010 7:43 am

ZM 1.24.2 "Error, failed to query crop"

Post by jcglt » Sat Feb 13, 2010 4:09 am

dclarke,
Thanks for your post just over. I understand that you give a few lines of code which would correct an error in the "source code" ?
As an ordinary user and quite newbie I don't know if I can correct something and what I should correct and I guess I shall have to wait for an upgraded version of ZM with a corrected packet ?
I posted a new link under the name "Webcam not working" but think it is useless as many other users of webcams are facing the same problem with no easy solution.
Regards, jcglt

dclarke
Posts: 7
Joined: Wed Feb 10, 2010 3:17 am

Post by dclarke » Sat Feb 13, 2010 4:49 am

It is a bug fix in the source code; I don't see any work-around other than rebuilding from source code. If you're relying on a pre-compiled distribution you're going to have to wait for your distro provider to update.

I know that's not what you wanted to hear, but them's the facts. Sorry.

jcglt
Posts: 5
Joined: Fri Feb 12, 2010 7:43 am

ZM 1.24.2 "Error, failed to query crop"

Post by jcglt » Sat Feb 13, 2010 4:54 am

dclarke,
Many thanks again, I can stop fighting this bloody computer and do something more productive. I shall wait for the next release.
Best regards, jcglt

esergim
Posts: 3
Joined: Wed Mar 03, 2010 1:06 pm

Post by esergim » Fri Mar 05, 2010 3:19 pm

Could you please post a patch?
i'll apreciate.

Thanks.

celsian
Posts: 1
Joined: Tue Mar 09, 2010 10:50 pm

Post by celsian » Tue Mar 09, 2010 10:52 pm

I made the changes to zm_local_camera.cpp as the OP has stated. ./configured and make installed. The installation (after having to supply it with many libraries) finally completed successfully. Unfortunately I'm still getting the following when running zmu -d /dev/video0 -q -v:

"Error, failed to query crop capabilities /dev/video0: Invalid argument"

Does getting this error now that I've made the necessary changes mean my camera, Logitech QuickCam Pro 4000 (USB) will not work with Zone Minder?

Btw, if you're curious where this is occurring in the code, it's line 892 in "zm_local_camera.cpp"

dclarke
Posts: 7
Joined: Wed Feb 10, 2010 3:17 am

Post by dclarke » Wed Mar 24, 2010 7:04 pm

Are you sure you ran the changed version of the program? The fix is in a library used in a lot of programs; did all the referencing programs (including zmu) get recompiled and updated?

That "Invalid argument" message comes from perror() on errno=EINVAL, but the fix explicitly catches errno=EINVAL and treats it as a normal condition.

Stick in some fprintf(stderr...)'s and see if what you think you did is actually what you really did.

mick.crane
Posts: 1
Joined: Thu Apr 15, 2010 6:23 pm

Post by mick.crane » Thu Apr 15, 2010 6:32 pm

hi,
I also get this error.
I altered zm_local_camera.cpp as above and added "#include <cstdio>"
to zm_utils.cpp
it compiled ok but I still get the error about cropping.
it's only a creative webcam vista plus.
I'm not a coder but I'd rather change a line than get a better webcam just now.

Abdulrhman
Posts: 1
Joined: Fri May 07, 2010 2:30 pm

Post by Abdulrhman » Fri May 07, 2010 3:31 pm

hey bro

i got 2 usb camera and all of them give that error !


anyway i try to catch up with ur edit .. but i got lost !

so .. could u please provide a copy of zm_local_camera.cpp after modification


regards

carlosecg
Posts: 1
Joined: Thu May 27, 2010 3:51 am
Location: Brazil

Post by carlosecg » Thu May 27, 2010 4:05 am

Hi! Just wanted to say that the ZM install on a Debian Squeeze is easy and painless. Except for this same problem described on the post when trying to use my USB webcam with ZM. On Ubuntu 10.04 I had the same problem. The camera works with Cheese.

Although I'm a programmer, I'm not experienced in linux programming or debian packaging. I tried to rebuild the package from the source on the Debian repository, but it didn't worked. I didn't googled for the errors that appeared because I've been doing this for a few hours, I'll try again later.

My question: is there any forecast on a release that includes this fix? Better yet, a Debian package? If not, how can I help?

willberg
Posts: 2
Joined: Thu Jun 03, 2010 9:51 am

Post by willberg » Thu Jun 03, 2010 10:06 am

Hi there, for anyone also having trouble with getting certain USB/built-in webcams to work because of this cropping issue, but they do work in Cheese/xawtv, you can instead route the camera through a ffmpeg stream. Like so (edited version of http://ubuntuforums.org/showthread.php?t=665607):

Install zoneminder from deb/rpm/whatever is easy. There is a guide on the wiki that works fine.

Install ffmpeg

Code: Select all

sudo apt-get install ffmpeg
Back up old ffmpeg streamer config file

Code: Select all

sudo mv /etc/ffserver.conf /etc/ffserver.conf_backup
Make a new config file

Code: Select all

sudo nano /etc/ffserver.conf
Input the following

Code: Select all

Port 8090 
# bind to all IPs aliased or not 
BindAddress 0.0.0.0 
# max number of simultaneous clients 
MaxClients 1000 
# max bandwidth per-client (kb/s) 
MaxBandwidth 10000 
# Suppress that if you want to launch ffserver as a daemon. 
# NoDaemon 

<Feed> 
File /tmp/feed1.ffm 
FileMaxSize 5M 
</Feed> 

# FLV output - good for streaming 
<Stream> 
# the source feed 
Feed feed1.ffm 
# the output stream format - FLV = FLash Video 
Format flv 
VideoCodec flv 
# this must match the ffmpeg -r argument 
VideoFrameRate 15 
# generally leave this is a large number 
VideoBufferSize 80000 
# another quality tweak 
VideoBitRate 200 
# quality ranges - 1-31 (1 = best, 31 = worst) 
VideoQMin 1 
VideoQMax 5 
VideoSize 352x288 
# this sets how many seconds in past to start 
PreRoll 0 
# wecams don't have audio 
Noaudio 
</Stream> 
Save and exit. (ctrl-x, yes)

Start the ffmpeg streaming video server:

Code: Select all

ffserver
Start the video stream from the webcam. NOTE, I am assuming we're using /dev/video0 - replace that with your video capture device.

Code: Select all

ffmpeg -r 15 -s 352x288 -f video4linux2 -i /dev/video0 http://localhost:8090/feed1.ffm
NOTE: You must specify video4linux2 there, I've not yet made it work with v4l1. This is different to the instructions at the source.

If you get some buffer underflows, don't worry too much. Do worry a little bit, though. Too many can cause it not to work. If you are getting underflows and it doesn't seem to be working, then lower the frame rate (the -r option) or lower the resolution. If you aren't getting underruns, then feel free to mess with those options to improve quality.

Now, open the ZoneMinder console in the web browser, and make a new monitor. Make sure it is an ffmpeg stream, then set the location as follows:

Code: Select all

http://localhost:8090/test.flv
The resolution should be the same as that which you set in the ffmpeg stream command before.

It now works.


This worked for me from a clean ZM install on Ubuntu 10.04 Netbook Remix (!!!), using a built-in webcam on a recently-released eeepc (1005ha) - so it will work for just any damn thing at all which works in Cheese.

This isn't an optimal solution, it would be much better to do the compile from source and fix the two bugs (the non-inclusion of a cstdio somewhere, and the above-mentioned fix). For me, however, I kept getting core dumps (!!!!!!) after trying to compile my own, so this is the next-best thing.

If anyone would find it helpful, I can write a complete empty-box-to-working-video tutorial.


Edit: If the stream doesn't seem to be working, i.e. the monitor source is in red text and no image shows, then see if you can get the stream showing in VLC. Install VLC and then point it at that same stream URL which we put in the config file (not the file name we specify in the command): http://localhost:8090/test.flv. If even that doesn't work, then stop the stream and mess with the frame rate/resolution before starting it again.

RCL
Posts: 1
Joined: Sat Jun 26, 2010 3:14 pm

Post by RCL » Sat Jun 26, 2010 3:42 pm

Thank you for this solution.

I did not manage to get zoneminder to work with ffmpeg streams though, although they are working with VLC (I have two web cameras, so I had to modify your setup). Zoneminder shows monitor names and its sources in orange, but there's no video in monitor windows.

Still, I'm using "raw" ffserver (which config you don't have to replace, just use -f switch) to monitor my pets while I'm at work - and I'm satisfied with this solution even without zoneminder itself ;) (making it work with UVC cameras out of the box would be great, though!)

Xhorder
Posts: 1
Joined: Wed Jul 14, 2010 11:07 pm

Re: [FIX] ZM 1.24.2 "Error, failed to query crop"

Post by Xhorder » Wed Jul 14, 2010 11:12 pm

dclarke wrote:A USB camera that doesn't support cropping will produce an error message "Error, failed to query crop: /dev/video0: Invalid argument" from zmu -q -v.

Failures are exhibited in zmu, and other places that rely on LocalCamera::GetCurrentSettings.

The fault is in LocalCamera::GetCurrentSettings.

The error arises from the fact that ioctl VIDIOC_G_CROP returns -1 and errno = EINVAL to indicate that cropping is not supported. (See http://v4l2spec.bytesex.org/spec/r9994.htm). LocalCamera::GetCurrentSettings treats any negative rc from ioctl VIDIOC_G_CROP as grounds for abnormal termination.

The fix is straightforward and short. All changes are in zm_local_camera.cpp as follows:

Code: Select all

911,912c911
< 	    int crop_rc = vidioctl( vid_fd, VIDIOC_G_CROP, &crop );
<             if ((crop_rc  <0>             if ( vidioctl( vid_fd, VIDIOC_G_CROP, &crop ) < 0 )
921,928c920,921
<             if ( verbose ) {
<if>= 0) {
< 	                sprintf( output+strlen(output), "  Current: %d x %d\n", crop.c.width, crop.c.height );
< 		}
< 		else {
< 			sprintf( output+strlen(output), "  Current: Cropping is not supported\n");
< 		}
<if>                 sprintf( output+strlen(output), "  Current: %d x %d\n", crop.c.width, crop.c.height );
I don't understand this 'code'? What do I do with it? do the <and> mean something?

help

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests