teerytko / python-video4linux2

Automatically exported from code.google.com/p/python-video4linux2
0 stars 0 forks source link

'MJPG only' webcam fails - patch attached #13

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Testing with a couple of Logotech webcams; the code at present fails,
primarily due to not be able to set 'NTSC' (or other) standard.

With attached patch Camera now reports
--
simon@bourne:~/pyv4l/python-video4linux2-local-changes$ ./pyv4l2.py 
Available devices:  ['/dev/video0']
        /dev/video0
Driver:  uvcvideo
Card:  UVC Camera (046d:08c3)
Bus Info:  0000:00:1d.1
Capabilities:
        Capture
        Streaming
Input 0:
                Name:   Camera 1
                Type:   camera
                Standards: []
                Status: []
Pixel formats: 
        MJPG    MJPEG
Resolutions: 
        320x240
        640x480
--

There are also some other quirks, attached below is a set of patches that
get the code talking to the camera capturing to buffer. 

I have not done the required changes to SaveJPEG yet... I just placed a
temporary 'return' at start of function to get the whole thing running.

--
simon@bourne:~/pyv4l/python-video4linux2-local-changes$ ./streampics.py -d
/dev/video0  -p MJPG -x 320 -y 240
Trying to create directory pics
Could not create directory [Errno 17] File exists: 'pics'
Recording /dev/video0:0 with format MJPG at (320, 240)
................................................................................
..........
Keyboard interrupt caught. Quitting...
Saved 90 pictures in 6.15 seconds: 14.63 fps
--

Cheers,
Mungewell

Original issue reported on code.google.com by mungew...@gmail.com on 2 Feb 2009 at 7:10

Attachments:

GoogleCodeExporter commented 8 years ago
Did some buffer code, but get an error " Huffman table 0x00 was not defined"

Code is:
--
                if not buffer:
                        buffer  = self.buffer

                if p == 'MJPG':
                        f = file(filename, 'wb')
                        f.write(buffer)
                        f.close()
                else:
                        img = PILImage.frombuffer('RGB',
                                (self.format.width, self.format.height),
                                buffer,
                                'raw',
                                p,
                                0,
                                1)
                        img.save(filename, 'jpeg', quality = q)
--

Start of the 'JPEG' file looks like:
--
simon@bourne:~/pyv4l/python-video4linux2-local-changes$ hexdump -C 
pics/000000000.jpg
| head
00000000  ff d8 ff e0 00 21 41 56  49 31 00 01 01 01 00 78  |.....!AVI1.....x|
00000010  00 78 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.x..............|
00000020  00 00 00 00 00 ff db 00  43 00 04 02 03 03 03 02  |........C.......|
00000030  04 03 03 03 04 04 04 04  06 0a 06 06 05 05 06 0c  |................|
00000040  08 09 07 0a 0e 0c 0f 0f  0e 0c 0e 0f 10 12 17 13  |................|
00000050  10 11 15 11 0d 0e 14 1a  14 15 17 18 19 1a 19 0f  |................|
00000060  13 1c 1e 1c 19 1e 17 19  19 18 ff db 00 43 01 04  |.............C..|
00000070  04 04 06 05 06 0b 06 06  0b 18 10 0e 10 18 18 18  |................|
00000080  18 18 18 18 18 18 18 18  18 18 18 18 18 18 18 18  |................|
*
--

Original comment by mungew...@gmail.com on 2 Feb 2009 at 11:23

GoogleCodeExporter commented 8 years ago
it looks like VLC can play these 'jpeg' files!

Confirms that the system is actually capturing the image OK.
Mungewell.

Original comment by mungew...@gmail.com on 3 Feb 2009 at 12:02

GoogleCodeExporter commented 8 years ago
Helpful comments in uvcvideo driver source
--
Please note that the MJPEG data have been stripped from their
Huffman tables (DHT marker), you will need to add it back if your JPEG
codec can't handle MJPEG data.
--

Why strip it in the first place?

Original comment by mungew...@gmail.com on 4 Feb 2009 at 4:53

GoogleCodeExporter commented 8 years ago
Python utils to convert MJPEG -> JPEG:
https://svn.berlios.de/viewvc/linux-uvc/uvc-utils/trunk/mjpeg2jpeg.py?view=marku
p

Is this worth including within pyv4l2.py?

Original comment by mungew...@gmail.com on 4 Feb 2009 at 5:55

GoogleCodeExporter commented 8 years ago
Patch was actually simple to do.

Original comment by mungew...@gmail.com on 4 Feb 2009 at 6:43

Attachments:

GoogleCodeExporter commented 8 years ago
Better patch attached. This allows for the user's app to get at the V4L2 
capture as a
PIL image via the 'CaptureImage()' call.

This should make it easier to bring the image into an app without having to 
place a
file on to disk.

Original comment by mungew...@gmail.com on 5 Feb 2009 at 5:15

Attachments: