jnohlgard / python-v4l2capture Goto Github PK
View Code? Open in Web Editor NEWPython extension to capture video with video4linux2 (fork of https://launchpad.net/python-v4l2-capture)
Python extension to capture video with video4linux2 (fork of https://launchpad.net/python-v4l2-capture)
python-v4l2capture 1.4.x Python extension to capture video with video4linux2 2009, 2010, 2011 Fredrik Portstrom 2011 Joakim Gebart I, the copyright holder of this file, hereby release it into the public domain. This applies worldwide. In case this is not legally possible: I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law. Introduction ============ python-v4l2capture is a slim and easy to use Python extension for capturing video with video4linux2. It supports libv4l to convert any image format to RGB or YUV420. this fork of python-v4l2capture: https://github.com/gebart/python-v4l2capture original python-v4l2capture: http://fredrik.jemla.eu/v4l2capture libv4l: http://freshmeat.net/projects/libv4l Installation ============ v4l2capture requires libv4l by default. You can compile v4l2capture without libv4l, but that reduces image format support to YUYV input and RGB output only. You can do so by erasing ', libraries = ["v4l2"]' in setup.py and erasing '#define USE_LIBV4L' in v4l2capture.c. python-v4l2capture uses distutils. To build: ./setup.py build To build and install: ./setup.py install Example ======= See capture_picture.py, capture_picture_delayed.py and list_devices.py. Change log ========== (see git log for latest changes) 1.4 (2011-03-18) - Added support for YUV420 output. 1.3 (2010-07-21) - Added set of capabilities to the return value of get_info. Updated list_devices.py. 1.2 (2010-04-01) - Forked example script into capture_picture.py and capture_picture_delayed.py. 1.1 (2009-11-03) - Updated URL and documentation. 1.0 (2009-02-28) - Initial release.
Hi,
i added a gui sample using your library. it works quite well and shows basic operation nicely. if you are interested let me know and i create a pull request.
regards, michael
This module won't build under python 3:
v4l2capture.c: In function ‘Video_device_dealloc’:
v4l2capture.c:116:7: error: ‘Video_device’ has no member named ‘ob_type’
If I attempt to work around that my hackily commenting it out, the module builds but can't be imported:
ImportError: ./v4l2capture.so: undefined symbol: PyString_FromStringAndSize
That can be fixed by using PyBytes_* instead of PyString_*, but then:
ImportError: ./v4l2capture.so: undefined symbol: PyInt_FromLong
So I try to change that to PyLong_FromLong as suggested here and here
After fixing that, the next problem is:
ImportError: ./v4l2capture.so: undefined symbol: Py_InitModule3
According to here I should change that to InitModule, not InitModule3 or 4. But:
ImportError: ./v4l2capture.so: undefined symbol: Py_InitModule
So, following a suggestion here to link with --export-dynamic, I tried modifying:
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-armv6l-3.2/v4l2capture.o -lv4l2 -o build/lib.linux-armv6l-3.2/v4l2capture.cpython-32mu.so
to
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,--export-dynamic -Wl,-z,relro build/temp.linux-armv6l-3.2/v4l2capture.o -lv4l2 -o build/lib.linux-armv6l-3.2/v4l2capture.cpython-32mu.so
but the error remains the same:
ImportError: ./v4l2capture.so: undefined symbol: Py_InitModule
At this point, I reached the limit of my ability to hack around with this, and I need an adult. Any ideas for what might be needed to make this module compatible with python 3?
Dear Gerbart,
Thank you for the awesome python wrapper for v4l2!!!
I running into an issue when v4l2capture can not find a device at the specified path. I have a try/catch statement surrounding the opening of the video device in case the user specifies an incorrect path:
import v4l2capture as vc
try:
self.cam = vc.Video_device(self.cnfg['devLoc'])
except:
...
As one might expect, for an incorrect path an IOError is returned:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '/dev/video5/'
However, unexpectedly, python is immediately terminated as well, whether it be a program or python interactive shell. Is there a way to handle this such that the python shell or program is not immediately terminated?
Thanks!!
hi,
i wonder how i can get the features that a webcam supports. if i use my favourite webcam tool guvcview it shows possible resolution and fps settings. did i miss something or does guvcview use a different api for that or is it just not implemented for now?
regards, michael
Hi,
Thank you for the amazing code . I am using it to stream stereo feeds from 2 webcams (logitech c930e) to my laptop from a raspberry pi. It works most times and when it does it rarely stops. However sometimes i get the following error.
libv4l2: error dequeuing buf: Broken pipe
The quick fix is to disconnect the webcams and reconnect them. From debugging i have narrowed it to the following line:
image_data = video.read_and_queue()
Have you encountered this error before ?
Raspberry pi uses Ubuntu Mate 16.0.4 and is connected to my laptop via wifi on a private dedicated network.
Hello,
I implemented your code (from capture_video.py) into my own Python script, I tried a lot of thing to edit the format (from MJPG to something else like avi or mp4). How can we record into the avi format ?
What I tried to edit:
Line 41: video.mjpg > video.avi
Line 26: fourcc='MJPG' > I tried a lot of codecs which were compatible with AVI format but no one was able to work. (from this list: http://www.fourcc.org/codecs.php)
I never succeeded to display the result on VLC
Sorry for my english, I'm French,
Thank you
my code like this:
while True:
# top_cam and bot_cam is camera device
select.select([top_cam,bot_cam],(),())
#select.select([top_cam],(),())
#select.select([bot_cam],(),())
data1= top_cam.read_and_queue()
data2 = bot_cam.read_and_queue()
it will appear error :
libv4l2: error dequeuing buf: Resource temporarily unavailable
Traceback (most recent call last):
File "cam_test2.py", line 105, in <module>
data2 = bot_cam.read_and_queue()
BlockingIOError: [Errno 11] Resource temporarily unavailable
but when i comment select.select([top_cam,bot_cam],(),())
,and replace in select.select([top_cam],(),());select.select([bot_cam],(),())
.
The biggest problem is when i use the latter,it will appear some image is None.
so I want use select.select([top_cam,bot_cam],(),())
,what should I do?
thanks!
I'm getting an error with the image_capture script:
python capture_picture.py
Traceback (most recent call last):
File "capture_picture.py", line 43, in <module>
image_data = video.read()
IOError: [Errno 11] Resource temporarily unavailable
It seems to be installed ok:
python list_devices.py
/dev/video0
driver: STV06xx
card: Camera
bus info: usb-bcm2708_usb-1.2
capabilities: readwrite, streaming, video_capture
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.