Motion - Linksys WVC 200 Support Patch
You are here: Foswiki>Motion Web>LinksysWVC200SupportPatch (05 May 2011, DcShoecomp)Edit Attach

Patch adding MJPEG-stream support for Linksys WVC200 IP Camera.

Description of Patch

The Linksys WVC200 IP Camera uses a particular system for transmitting MJPEG stream: it uses small MJPEG blocks in which it encapsulates a part of each JPG picture. 3 or so blocks contains one whole JPG image.

This patch is now integrated in motion-trunk, so you may checkout the trunk instead of messing with the patches. It is not included with any version of motion 3.2.x.

For this patch to work, you have to use the following netcam url:

netcam_url mjpg://netcam-ip:port/img/video.mjpeg

Before reporting bugs check the following points:
  • Make sure you are using a version of motion containing this patch (e.g. trunk revision 469)
  • Make sure you specified a netcam port in the url (e.g. 80 in mjpg://192.168.0.1:80/....)
  • Make sure to use MJPEG mode and not MPEG4 mode. (change this using the camera's web interface)
  • Make sure the credentials you are using are the right ones.
Any remarks/comments/improvements are, as always, welcome.

I hope this patch may be of some use to you ^^

Installation of Patch

Download the patch file. If it is packed as a gz or tar.gz unpack it first. Then copy it to the motion source directory and issue the command (assuming the patch file is called filename_of_patch_file.diff)

patch < filename_of_patch_file.diff

Then re-build Motion and test the patch.

Change History of Patch

  • 1.0 Initial release (buggy, do not use)
  • 1.1 Rewrote patch:
    • Separated HTTP/multipart streaming from MJPG streaming, so the code is more clear.
    • Fixed netcam_check_buffsize, because it did not work if buffer augmentation > NETCAM_BUFFER_SIZE.
    • Added special mjpg:// url scheme to enable the MJPG code, to remove brittle Content-Type dependency.
  • 1.2 Corrected a few things:
    • Functions added by the patch are now documented.
    • netcam_check_buffsize now works as expected (ensure the buffer contains at least numbytes free bytes, for any numbytes value).
    • Fixed a bug in netcam_recv(): reading from disconnected camera (sock == -1) caused a segmentation fault.
    • Integrated indentation patch from Angel, only for code impacted by this patch.

Discussion and Comments

I've attached a version of your patch fixing code following CODE_STANDARD rules. I cannot test your code because i haven't access to any of those cameras.

Anyway , will be better to don't use those goto and find a better way to include your approach.

Thanks for your patch !

-- AngelCarpintero - 26 May 2008


Thanks for the fix and the feedback ! I will try to configure my Vim to follow indentation rules.

After some more testing it appears that the patch code generated a good data stream for some time, then, for some reason lost the link to the WVC200, and never restored the link correctly.

I will remove the goto's and make some functions in some days (i have much work to do at this time)

Should i make a separate netcam_wvc200.c to write them ?

-- F00tyNyupi - 26 May 2008


Rather than netcam_mjpeg.c, i'm sure many other network cameras will use same mjpeg format.

Thanks.

-- AngelCarpintero - 26 May 2008


Here's a new version 1.1 for testing. Please check if I didn't break http/multipart streaming or non-streaming mode, as I rewrote a part of this code. Finally I had only 2 external functions, so I didn't find useful to make a new file. But, if you think that's better, i can update the patch.

I hope this time i respected CODE_STANDARD smile

-- F00tyNyupi - 28 May 2008


I've updated your patch again , with some fixes to respect CODE_STANDARD like :
void function ( ... ){
}

to
void function ( ... )
{
}

or
if () 
{
...
}

to
if () {
.... 

} 

So questions about your patch :

1 -. Why did you add mjpg to netcam_url_parse ? do you want to force netcam to use MJPEG instead of detecting stream ?

2 -. You changed also netcam_check_buffsize, any reason for that ?

3 -. Please add to your functions Return values and meaning of each one .

Thanks your patch looks better now smile

Lets try to get more users using MJPEG network cameras that will help to debug any issue.

-- AngelCarpintero - 01 Jun 2008

Thanks for you feedback, Angel.

About the indentation: Sorry for the few errors i made, and thank you for the correction. But you also reindented code i didn't touch. I think that makes the patch harder to read and evaluate, since it contains code visual-only changes unrelated to the patch.

So, unless you want to integrate this patch straight like this in motion (i doubt this, it should still be considered as experimental) i will probably make a patch that includes your indentation fixes in the code i touched, but without them in the code that was not touched by the patch.

About your questions:

1/ The camera i have says the content-type is application/octet-stream. Although it distinguishes this camera from the others supported by Motion, I thunk other cameras can send other protocols as application/octet-stream, and so the detection code will have to be done again when adding these cameras in the future. So, yes, since i can not think of a way to reliably detect this particular protocol, i want the user to specify the stream type, at least for this particular one.

2/ I don't know if this is the intended behavior (perhaps it is), but i saw netcam_check_buffsize as a function which will ensure there is at least numbytes available and not used in the specified buffer.

This function does not do this if numbytes > NETCAM_BUFFSIZE.

The patched one, after re-reading, does not exactly does that neither... (bad patch) ^^'

I will correct it, for it to work when numbytes > NETCAM_BUFFSIZE. If that's not the way it should work (please tell me if it's not), i will make a separate function, or find another workaround.

3/ Yup.

-- F00tyNyupi - 01 Jun 2008

Uploaded a new version of the patch, all is in the ChangeLog smile

-- F00tyNyupi - 02 Jun 2008


Thanks , Commited to svn trunk.

Let see if people with network cameras that has Motion JPEG stream can give us some feedback.

-- AngelCarpintero - 03 Jun 2008


any chance of this getting scheduled into a version?

-- TedTimmons - 12 Jun 2008


Ted , yes if there's no problem will be included in next release once we branch for 3.3.0.

-- AngelCarpintero - 13 Jun 2008


Patch is merged in svn trunk.

-- AngelCarpintero - 10 Jul 2008

Perhaps we can remove this annoying debug-line:

[1] netcam_mjpg_buffer_refill: Refilled buffer with [1448] bytes from the network.

unless we run in a very deep debug mode.

-- F00tyNyupi - 14 Jul 2008


Yes it's in my local copy not commit yet , adding better logging .

-- AngelCarpintero - 14 Jul 2008

it looks like i'm not able to install the trunk version on debian. .deb package works great so far.. so i can't wait getting this included in next version! smile thanks a lot for your great work...

-- DavidSpuler - 17 Jul 2008

is there a .deb package available with wvc200-support? please help..

-- DavidSpuler - 01 Dec 2008


No reason to create a deb of trunk , but you can create yourself :

http://www.lavrsen.dk/twiki/bin/view/Motion/PackagingMotion

Or just get trunk from svn or http://www.lavrsen.dk/sources/motion-daily/motion-daily-last.tar.gz

and compile it.

-- AngelCarpintero - 02 Dec 2008


Just found this thread on the twiki... I have a WVC200 as well, and will be trying to use it again shortly. Will report back. thank you.

-- JimHoward - 07 Dec 2008

simpy doesn't work cry (daily snapshot from 18th dec)

Dec 18 23:11:45 64 motion:[1] motion_init: Started motion-stream server in port 8081
Dec 18 23:11:50 64 motion: [1] motion_loop: Retrying until successful connection with camera
Dec 18 23:11:50 64 motion: [1] netcam_connect: connect returned error: Operation now in progress
Dec 18 23:11:50 64 motion: [1] Failed to open camera - check your config and that netcamera is online
Dec 18 23:11:50 64 motion: [1] netcam_http_request: Failed to read first camera header - giving up for now 
maybe it's because too new firmware? (1.2.1)

-- SzymonSzypulski - 18 Dec 2008


Please run motion with debug and no daemon :

./motion -d 9 -n

Also please paste the relevant config options in you motion.conf ( p.ex all netcam options ).

-- AngelCarpintero - 20 Dec 2008

Ok, since my pvr500 is not going to work on the short term I acquired a Panasonic BB-HCM511CE ip-camera, now i've been pulling my hairs out as why it won't work. tried both .9 & .11 but still fail to receive anything, camera works fine in that other particular operating system and in an explorer browser frown, sad smile

output of motion -d 9 -n
xzae-lm@cygnus:~/motion-3.2.9$ sudo motion -n -d 9 
[0] Processing thread 0 - config file /usr/local/etc/motion.conf 
[0] Motion 3.2.9 Started [0] ffmpeg LIBAVCODEC_BUILD 3355136 LIBAVFORMAT_BUILD 3409664 
[0] Thread 1 is from /usr/local/etc/motion.conf 
[1] Thread 1 started 
[1] entered netcam_start() 
[0] motion-httpd/3.2.9 running, accepting connections 
[1] Camera thread starting... 
[1] Entry netcam_url_parse data http://192.168.0.159 
[0] motion-httpd: waiting for data on port TCP 8080 
[1] Parse case 0 data http://192.168.0.159 
[1] Parse case 1 data http 
[1] Parse case 6 data 192.168.0.159 
[1] Parse case 9 data 
[1] HTTP Result code -1 
[1] Error reading first header - re-trying 
[1] HTTP Result code -1 
[1] Error reading first header - re-trying 
[1] HTTP Result code -1 
[1] Error reading first header - re-trying 
[1] HTTP Result code -1 
[1] Error reading first header - re-trying 
[1] HTTP Result code -1 
[1] Error reading first header - re-trying
[1] Failed to read first camera header - giving up for now 
[1] Could not fetch initial image from network camera 
[1] Motion continues using width and height from config file(s) 
[1] Started stream webcam server in port 8081
[1] vid_return_code 2 
[1] vid_return_code 2 
{1] vid_return_code 2 
[1] vid_return_code 2 
[1] vid_return_code 2 
[1] vid_return_code 2 
[1] vid_return_code 2
[1] vid_return_code 2 
[1] vid_return_code 2
And that goes on for a while. with .11 I also got the following back from the cameras built in server "400 bad request"

How can we fix this and what can I do to assist?

-- XzaeLm - 21 Jan 2009


First you MUST use motion update your motion version 3.2.9 has not been patched and it's not latest stable ... so at least use 3.2.11 patched or

get trunk version of motion . http://www.lavrsen.dk/sources/motion-daily/motion-daily-last.tar.gz

Second you MUST setup motion like patch described :

netcam_url mjpg://IP

-- AngelCarpintero - 22 Jan 2009


Is this patch included in the last version of motion (3.2.11.1) ? Or does this version need to be patched also.

Trying to patch the 3.2.11.1 I got many errors :

patching file netcam.c Hunk #1 FAILED at 155. Hunk #3 FAILED at 403. Hunk #4 FAILED at 449. Hunk #5 FAILED at 627. Hunk #6 FAILED at 660. Hunk #7 FAILED at 695. Hunk #8 FAILED at 782. Hunk #9 FAILED at 990. Hunk #10 FAILED at 1301. Hunk #11 succeeded at 1334 (offset 19 lines). Hunk #12 FAILED at 1904. Hunk #13 FAILED at 1941. Hunk #14 FAILED at 1971. Hunk #15 FAILED at 1999. Hunk #16 FAILED at 2046. Hunk #17 FAILED at 2075. Hunk #18 FAILED at 2216. Hunk #19 FAILED at 2262. Hunk #20 FAILED at 2387. Hunk #21 FAILED at 2462. Hunk #22 FAILED at 2592. Hunk #23 FAILED at 2769. 21 out of 23 hunks FAILED -- saving rejects to file netcam.c.rej patching file netcam.h Hunk #1 succeeded at 102 with fuzz 1. Hunk #2 FAILED at 206. Hunk #3 succeeded at 255 with fuzz 1 (offset 3 lines). 1 out of 3 hunks FAILED -- saving rejects to file netcam.h.rej

-- FlorianManach - 23 Oct 2009

I don't think motion 3.2.11 contains the patch. It was made against the revisions 350 or so of the SVN, so it may require some work to patch 3.2.11. Also, make sure you are using the latest version (v1.2) of the patch. The 1.1 and 1.0 are not correct and may contain many indentation problems and other bugs.

Furthermore, some work has been done since (better logging, etc), so if you can, use the trunk version.

-- F00tyNyupi - 23 Oct 2009

I tried R351 and patch version 1.2.

I setup

netcam_url mjpg://IP-of-my-cam/img/video.mjpeg netcam_userpass login:passwd (actually the real creds of course)

Patch and compilation went fine but motion still reports errors :
[1] netcam_http_request: about to try to connect, time #0
[1] netcam_connect, disconnecting netcam since keep-alive not set.
[1] netcam_connect with no keepalive, new socket created fd 3
[0] motion-httpd testing : IPV4 addr: 127.0.0.1 port: 8080
[1] connect returned error: Operation now in progress
[1] netcam_connect disconnecting netcam (3)
[1] Failed to open camera - check your config and that netcamera is online

The netcam is online, I can see the image via VLC or just a web browser.

-- FlorianManach - 26 Oct 2009

Ok, can you try with to run motion with maximum debug ? I want to see exactly where it fails. Also, i have a WVC200 with the european firmware and MJPEG video-mode set. The patch does not work with mpeg4 streaming. Please tell me if you are not using the same model. Please also note that you can use the trunk version, as some work has been done (better logging, etc) in it.

-- F00tyNyupi - 26 Oct 2009

The camera is a WVC200 with Firmware V1.1.0

Here is the output with motion -d 9

[0] Processing thread 0 - config file /usr/local/etc/motion.conf
[0] Motion trunk-r350 Started
[0] ffmpeg LIBAVCODEC_BUILD 3352064 LIBAVFORMAT_BUILD 3344896
[0] Thread 1 is from /usr/local/etc/motion.conf
[1] Thread 1 started
[1] entered netcam_start()
[1] Camera thread starting...
[1] Entry netcam_url_parse data mjpg://10.192.4.221/img/video.mjpeg
[1] Parse case 0 data mjpg://10.192.4.221/img/video.mjpeg
[1] Parse case 1 data mjpg
[1] Parse case 6 data 10.192.4.221
[1] Parse case 9 data /img/video.mjpeg
[1] netcam_start: Netcam_http parameter '1.0' converts to flags: HTTP1.0:1 HTTP1.1: 0 Keep-Alive OFF.
[1] netcam_start: now calling netcam_setup_mjpg()
[1] netcam_http_build_url: Netcam has flags: HTTP1.0: 1 HTTP1.1: 0 Keep-Alive OFF.
[1] Camera connect string is ''GET /img/video.mjpeg HTTP/1.0
Host: 10.192.4.221
User-Agent: Motion-netcam/trunk-r350
Connection: close
Authorization: Basic YWRtaW46YWRtaW4=

''
[1] End of camera connect string.
[1] netcam_http_request: about to try to connect, time #0
[1] netcam_connect, disconnecting netcam since keep-alive not set.
[1] netcam_connect with no keepalive, new socket created fd 3
[1] connect returned error: Operation now in progress
[1] netcam_connect disconnecting netcam (3
[1] Failed to open camera - check your config and that netcamera is online
[1] Failed to read first camera header - giving up for now
[1] Could not fetch initial image from camera
[1] Motion continues using width and height from config file(s)
[1] Resizing pre_capture buffer to 1 items
[0] motion-httpd testing : IPV4 addr: 127.0.0.1 port: 8080
[1] motion-stream testing : IPV4 addr: 127.0.0.1 port: 801
[0] motion-httpd Binded : IPV4 addr: 127.0.0.1 port: 8080
[0] motion-httpd/trunk-r350 running, accepting connection
[0] motion-httpd: waiting for data on 127.0.0.1 port TCP 8080
[1] motion-stream Binded : IPV4 addr: 127.0.0.1 port: 8081
[1] Started motion-stream server in port 8081
[1] vid_return_code 1
[1] vid_return_code 1
[1] vid_return_code 1
[0] DEBUG-2 threads_running 1 motion_threads_running 1 finish 0
[1] vid_return_code 1
[1] vid_return_code 1
[0] DEBUG-2 threads_running 1 motion_threads_running 1 finish 0
[1] vid_return_code 1
[1] vid_return_code 1
[0] DEBUG-2 threads_running 1 motion_threads_running 1 finish 0
[1] vid_return_code 1
[1] vid_return_code 1
[0] DEBUG-2 threads_running 1 motion_threads_running 1 finish 0
[1] vid_return_code 1
[1] Retrying until successful connection with camera
-- FlorianManach - 28 Oct 2009

Ok, so:

The problem is that the connection to the camera fails. This may be related to a failed select() syscall. This occurs before decoding any data from the network camera, and uses connect methods used by other cameras.

Please try the following steps:

1 - First, checkout a fresh copy of motion at the current revision (r469) as I just tested it with my camera. It works well and does not need the patch.

2 - Please apply the following patch: http://nyu.be/~footy/motion-r469-select-error.patch (I will post it again on the bug report page, so it does not get lost) It may detect a particular error condition.

3 - In my configurations, I always specified a port number, so try mjpg://10.192.4.221:80/img/video.mjpeg (if the port is really 80), with maximum debug.

4 - Please check that the command wget -O /dev/null -S http://10.192.4.221:80/img/video.mjpeg --http-user xxxxxx --http-password yyyyy starts to download data (with of course real credentials)

5 - If all that does not work, please file a Bug Report, with the debug output you get from the step 3 above, and the output from the command of step 4.

Have a nice day.

-- F00tyNyupi - 30 Oct 2009

F00tyNyupi : I first tried by adding :80 in my conf file... and it worked, so I assume the error was here.

Anyway, I compiled and installed r469 and it works great.

Thx a lot for your help.

-- FlorianManach - 30 Oct 2009

Hi @ all, where/How can i get the r469 ? I want to use my wvc200 with the live-mpjg-stream to get highest framerates. I have motion-3.2.11.1 and use the wvc200 with "netcam_url http://CAM_IP/img/snapshot.cgi?size=5&quality=5"; . It works, but i only can get 3 frames/s. The Patch r351 v1.2 don´t work for me. Same issues like Florian

-- SasLeh - 20 Mar 2010


You can get svn trunk where patch is already included :
mkdir motion
cd motion
svn co http://www.lavrsen.dk/svn/motion/trunk/ .

-- AngelCarpintero - 20 Mar 2010


OK, i´ve got r483. I works quiet good with mjpg and now i have the logfile-option thumbsup Very good work.

THX a lot and have a nice day.

-- SasLeh - 21 Mar 2010

EDIT with 3.2.11.1 and netcam_url http://CAM_IP/img/snapshot.cgi?size=3&quality=5 , i got 0,3 fps ! with r483 and netcam_url mjpg://CAM_IP:80/img/video.mjpeg , i get 3 fps

-- SasLeh - 21 Mar 2010

Are there any updates to Conceptronic C54netcam2 problem http://www.lavrsen.dk/foswiki/bin/view/Motion/SupportQuestion2009x10x21x075055 has the soi_fix.diff been included in the latest r526 ?

-- DcShoecomp - 05 May 2011
Topic revision: r37 - 05 May 2011, DcShoecomp
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.