Motion - Uvcvideo Mjpeg Patch
You are here: Foswiki>Motion Web>UvcvideoMjpegPatch (05 Nov 2010, LikelinuxLikelinux)Edit Attach

2 patches to uvcvideo source and motion source to get 2 cameras working

Description of Patch

Because I will probably forget to post this otherwise, here are 2 patches to both (recent SVN) uvcvideo source and motion source to get 2 uvcvideo cameras working with motion.

I had a problem (also reported on the motion mailing lists recently) in that 2 uvcvideo devices would not work together (1 would using YUYV). I don't know why YUYV didn't work - it's USB2 and bandwidth shouldn't be an issue IMHO. I tried forcing MJPEG in the config file as a workaround but "v4l2_palette 2" would never work because priority was given to higher values of v4l2_palette, regardless of config gile.

So I sorta fixed a bug in motion to make sure it is respected (there are probably better ways of fixing that).

Then I discovered that certain ioctls (VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP) were not implemented in the uvcvideo source. Luckily, Jim Studt had posted a patch a while ago on Linux-uvc-devel, which still didn't make it into the SVN version for some reason.

Both changes enabled me to get multiple uvcvideo devices working with MJPEG - I hope this helps others too.

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 revision

Discussion and Comments

You patch for uvcvideo is out of the scope of motion , but could help people ... but why not send it to video4linux mailing list ? So if it's worth will be merged

i 2.6.27.

About v4l2_palette , i don't get your point .. i have tried a uvc webcam :
 *v4l2_palette 8* 
 
[1] Supported palettes:
[1] 0: MJPG (MJPEG)
[1] 1: YUYV (YUV 4:2:2 (YUYV))
[0] motion-httpd/3.2.10.branch-r392 running, accepting connections
[0] motion-httpd: waiting for data on port TCP 8080
[1] index_format 6 Test palette YUYV (320x240)
[1] Using palette YUYV (320x240) bytesperlines 640 sizeimage 2621440 colorspace 0000000

v4l2_palette 2
[1] Supported palettes:
[1] 0: MJPG (MJPEG)
[1] Selected palette MJPG
[0] motion-httpd/3.2.10.branch-r392 running, accepting connections
[0] motion-httpd: waiting for data on port TCP 8080
[1] index_format 2 Test palette MJPG (320x240)
[1] Using palette MJPG (320x240) bytesperlines 0 sizeimage 2621440 colorspace 00000000

So you can see that is working as expected , could you post your output ... could be a bug in uvcvideo ?

About bandwidth look at last line of each , pay attention to bytesperlines value ... , also i read somewhere didn't check that no matter

what resolution you specify to capture uvcvideo always requests highest resolution supported by webcam to usb bus, so i might be a way

to know what is the bandwidth requested by uvcvideo for each paletter/resolutions & number of buffers.

-- AngelCarpintero - 25 Jul 2008


Hi, thanks for your comments. I realise the uvcvideo patch it is out of scope and I will send it (again) to the relevant list - it's not my patch though.

Re: motion; it really is a bug; I added some debugging statements and since the loop in video2.c is performed twice on my webcams (once for every format the webcam supports I think), "i" is already 6 (YUYV) and can never become 2 (MJPEG) again. My fix probably isn't the right one, but it worked for me.

Here's the (unpatched) motion config/output refusing to use MJPEG frown, sad smile :
phobos:/usr/local/bin # su motion -c ./motion-3.2.10.1
[0] Processing thread 0 - config file /usr/local/etc/motion.conf
[0] Processing config file /home/_webcam/philips3/thread3.conf
[0] Processing config file /home/_webcam/philips2/thread2.conf
[0] Processing config file /home/_webcam/philips1/thread1.conf
[0] Motion 3.2.10.1 Started
[0] Motion going to daemon mode

phobos:/usr/local/bin # su motion -c "./motion-3.2.10.1 -n"
[0] Processing thread 0 - config file /usr/local/etc/motion.conf
[0] Processing config file /home/_webcam/philips3/thread3.conf
[0] Processing config file /home/_webcam/philips2/thread2.conf
[0] Processing config file /home/_webcam/philips1/thread1.conf
[0] Motion 3.2.10.1 Started
[0] ffmpeg LIBAVCODEC_BUILD 3357184 LIBAVFORMAT_BUILD 3411968
[0] Thread 1 is from /home/_webcam/philips3/thread3.conf
[0] Thread 2 is from /home/_webcam/philips2/thread2.conf
[0] Thread 3 is from /home/_webcam/philips1/thread1.conf
[1] Thread 1 started
[1] cap.driver: "uvcvideo"
[1] cap.card: "Hercules Dualpix Exchange"
[1] cap.bus_info: "0000:00:07.2"
[1] cap.capabilities=0x04000001
[1] - VIDEO_CAPTURE
[1] - STREAMING
[1] v4l2_select_input: name = "Camera 1", type 0x00000002, status 00000000
[1] - CAMERA
[1] Device doesn't support VIDIOC_G_STD 
[1] Supported palettes:
[1] 0: YUYV (YUV 4:2:2 (YUYV))
[1] 1: MJPG (MJPEG)
[2] Thread 2 started
[3] Thread 3 started
[1] index_format 6 Test palette YUYV (640x480)
[1] Using palette YUYV (640x480) bytesperlines 1280 sizeimage 614400 colorspace 00000000
[1] found control 0x00980900, "Brightness", range -64,64 
[1]   "Brightness", default 0, current 0
[1] found control 0x00980901, "Contrast", range 0,64 
[1]   "Contrast", default 32, current 32
[1] found control 0x00980902, "Saturation", range 0,128 
[1]   "Saturation", default 54, current 54
[1] found control 0x00980903, "Hue", range -40,40 
[1]   "Hue", default 0, current 0
[1] found control 0x0098090e, "White Balance Red Component", range 1,500 
[1]   "White Balance Red Component", default 100, current 100
[1] found control 0x0098090f, "White Balance Blue Component", range 1,500 
[1]   "White Balance Blue Component", default 100, current 100
[1] found control 0x00980910, "Gamma", range 72,500 
[1]   "Gamma", default 100, current 100
[1] found control 0x00980913, "Gain", range 0,100 
[1]   "Gain", default 0, current 0
[1] mmap information:
[1] frames=4
[1] 0 length=614400
[1] 1 length=614400
[1] 2 length=614400
[1] 3 length=614400
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
[2] cap.driver: "uvcvideo"
[2] cap.card: "Hercules Dualpix Exchange"
[2] cap.bus_info: "0000:00:07.2"
[2] cap.capabilities=0x04000001
[2] - VIDEO_CAPTURE
[2] - STREAMING
[2] v4l2_select_input: name = "Camera 1", type 0x00000002, status 00000000
[2] - CAMERA
[2] Device doesn't support VIDIOC_G_STD 
[2] Supported palettes:
[2] 0: YUYV (YUV 4:2:2 (YUYV))
[2] 1: MJPG (MJPEG)
[2] index_format 6 Test palette YUYV (640x480)
[2] Using palette YUYV (640x480) bytesperlines 1280 sizeimage 614400 colorspace 00000000
[2] found control 0x00980900, "Brightness", range -64,64 
[2]   "Brightness", default 0, current 0
[2] found control 0x00980901, "Contrast", range 0,64 
[2]   "Contrast", default 32, current 32
[2] found control 0x00980902, "Saturation", range 0,128 
[2]   "Saturation", default 54, current 54
[2] found control 0x00980903, "Hue", range -40,40 
[2]   "Hue", default 0, current 0
[2] found control 0x0098090e, "White Balance Red Component", range 1,500 
[2]   "White Balance Red Component", default 100, current 100
[2] found control 0x0098090f, "White Balance Blue Component", range 1,500 
[2]   "White Balance Blue Component", default 100, current 100
[2] found control 0x00980910, "Gamma", range 72,500 
[2]   "Gamma", default 100, current 100
[2] found control 0x00980913, "Gain", range 0,100 
[2]   "Gain", default 0, current 0
[2] mmap information:
[2] frames=4
[2] 0 length=614400
[2] 1 length=614400
[2] 2 length=614400
[2] 3 length=614400
[2] Error starting stream.
[2] VIDIOC_STREAMON: No space left on device
[2] ioctl(VIDIOCGMBUF) - Error device does not support memory map
[2] V4L capturing using read is deprecated!
[2] Motion only supports mmap.
[2] Could not fetch initial image from camera
[2] Motion continues using width and height from config file(s)
[2] Resizing pre_capture buffer to 1 items
[2] Started stream webcam server in port 8882
[2] Resizing pre_capture buffer to 3 items
[3] cap.driver: "uvcvideo"
[3] cap.card: "VF0410 Live! Cam Video IM Pro"
[3] cap.bus_info: "0000:00:07.2"
[3] cap.capabilities=0x04000001
[3] - VIDEO_CAPTURE
[3] - STREAMING
[3] v4l2_select_input: name = "Camera 1", type 0x00000002, status 00000000
[3] - CAMERA
[3] Device doesn't support VIDIOC_G_STD 
[3] Supported palettes:
[3] 0: YUYV (YUV 4:2:2 (YUYV))
[3] 1: MJPG (MJPEG)
[3] index_format 6 Test palette YUYV (640x480)
[3] Using palette YUYV (640x480) bytesperlines 1280 sizeimage 614400 colorspace 00000000
[3] found control 0x00980900, "Brightness", range -64,64 
[3]   "Brightness", default 0, current 0
[3] found control 0x00980901, "Contrast", range 0,64 
[3]   "Contrast", default 32, current 32
[3] found control 0x00980902, "Saturation", range 0,128 
[3]   "Saturation", default 64, current 64
[3] found control 0x00980903, "Hue", range -40,40 
[3]   "Hue", default 0, current 0
[3] found control 0x00980910, "Gamma", range 72,500 
[3]   "Gamma", default 100, current 100
[3] found control 0x00980913, "Gain", range 0,100 
[3]   "Gain", default 0, current 0
[3] mmap information:
[3] frames=4
[3] 0 length=614400
[3] 1 length=614400
[3] 2 length=614400
[3] 3 length=614400
[3] Error starting stream.
[3] VIDIOC_STREAMON: No space left on device
[3] ioctl(VIDIOCGMBUF) - Error device does not support memory map
[3] V4L capturing using read is deprecated!
[3] Motion only supports mmap.
[3] Could not fetch initial image from camera
[3] Motion continues using width and height from config file(s)
[3] Resizing pre_capture buffer to 1 items
[3] Started stream webcam server in port 8881
[3] Resizing pre_capture buffer to 3 items
[1] Started stream webcam server in port 8883
[1] Resizing pre_capture buffer to 3 items
[2] Thread exiting
[3] Thread exiting
[1] Thread exiting
[1] Calling vid_close() from motion_cleanup
[1] Closing video device /dev/video2
[0] Motion terminating

-- GerritHannaert - 25 Jul 2008


Gerrit Thanks , nevermind about that issue ... going to take a fix it in trunk and backport to 3.2.10 branch

-- AngelCarpintero - 25 Jul 2008


Committed to svn trunk.

-- AngelCarpintero - 28 Jul 2008

Hi everybody,

thanks for the patches. After some painful days I finally got motion running with my Quickcam. Unfortunately the patch does not work (anymore) without a small tweak. Why is it not becoming merged into the uvc code?

I summarized my experiences here: http://www.yeap.de/blog2.0/archives/165-Logitech-Quickcam-on-Ubuntu-Linux.html

-- JoernSchimmelpfeng - 06 Jan 2009

My cam zc301 which only support a v4l device! how can i set the palette format is JPEG! can you help me!

-- LikelinuxLikelinux - 05 Nov 2010

I Attachment Action Size Date Who Comment
motion.MJPEG.diffdiff motion.MJPEG.diff manage 1 K 23 Jul 2008 - 21:32 UnknownUser Make sure motion respects "v4l2_palette 2" in motion config
trunk.232.JPEGCOMP.diffdiff trunk.232.JPEGCOMP.diff manage 4 K 23 Jul 2008 - 21:34 UnknownUser Enable VIDIOC_G_JPEGCOMP and VIDIOC_S_JPEGCOMP (needed by motion) in uvcvideo driver
Topic revision: r8 - 05 Nov 2010, LikelinuxLikelinux
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.