opencv-python: Fail to open capture device (Linux and macOS builds are not compiled with FFmpeg)
My system is
Ubuntu 14.04.5 LTS
Python 3.5
I have a virtual environment with
$ pip freeze
numpy==1.11.1
opencv-python==3.1.0.2
Any try on opening a VideoCapture
fails… Any of the following always return False
when I test with cap.isOpened()
cap = cv2.VideoCapture(full_path_to_video_file)
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(-1)
I have ffmpeg
installed and other OpenCV installations from source on my system work fine.
I was now giving a try with your package but it is not working. What am I missing? Do I need to link ffmpeg
in some way?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 17 (8 by maintainers)
I might have figured out a way to include FFmpeg support to the Linux (and maybe MacOS too) builds without actually shipping the library itself within the package. This will of course require a proof of concept first, but this is roughly the idea:1. Find somewhere a fresh dev build of FFmpeg for Cent OS 5 or compile it manually 2. Compile OpenCV against it 3. Patch the resulting binary with PatchELF which comes pre-installed in the manylinux containers - this means that any needed link time dependencies (DT_NEEDED
) related to FFmpeg will be removed 4. Users can install the opencv-python as before and it will import without any issues, BUT: - video I/O is maybe (I have to look at this, not sure about the dynamic linker stuff) supported given that FFmpeg has been separately installed in the system and it is API/ABI compatible with the one that OpenCV was compiled against - trying to use video related functions without FFmpeg will most likely result in undefined symbol / some other error and terminate the programEDIT: I have been thinking about this and the solution above does not probably work correctly. However, the same logic could be applied to__init__.py
if import fails -> removeDT_NEEDED
(with python) entries from the binary and try again.EDIT2: Forget all of the above. We will ship LGPL FFmpeg with the packages like in the Windows wheels. Work in progress.
It will take some time to test this, so do not except video support any time soon. I haven’t forgotten this or the other issues 😃
The Linux wheel built this way is useless to me then. A shame, for this could be an easy way to get OpenCV rolling in my environments. I have gstreamer also installed but it looks like it is of no help.
The lack of ffmpeg codecs could be the reason why I can not read my videos, but what about the camera? Any hints on how I can work through this?
Anyone using this on Linux with success? Can anyone
cv2.VideoCapture(0)
even without ffmpeg enabled?Some of the V4L/V4L2 headers were missing on those Cent OS 5 containers. I ended up adding them there manually since anything else didn’t seem to work. OpenCV detects now both of them and builds fine. Can’t really test if webcams work in reality since I don’t have actual HW for testing but I guess we will see at some point.
FFmpeg will be supported in the next release. I will try to enable V4L2 also.
How is V4L2 (using VideoCapture with webcams) related to FFmpeg in any way? The two are orthogonal (except maybe to support h264 webcams, which are somewhat rare anyway).
Is there a problem building with V4L2 support with the manylinux setup?
I’m waiting for pull request for macOS support, see https://github.com/skvark/opencv-python/issues/49. For Linux builds FFmpeg will be added hopefully during this year.