Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to open capture device (Linux and macOS builds are not compiled with FFmpeg) #14

Closed
cachitas opened this issue Sep 16, 2016 · 17 comments

Comments

@cachitas
Copy link

cachitas commented Sep 16, 2016

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?

@skvark
Copy link
Member

skvark commented Sep 17, 2016

The Linux builds have been built without ffmpeg. I can enable it (and I'm looking into #6), but there remains the GPL/LGPL licensing issue. Statically linking the ffmpeg to the cv2.so is a no go (I don't know if this is even possible). Shipping the shared ffmpeg lib with the package might be possible. Another solution is to build the package with ffmpeg support and then users manually install ffmpeg on their systems.

@cachitas
Copy link
Author

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?

@cancan101
Copy link

Using the wheels built here, I cannot get capture devices to work on either OS X or Linux (Ubuntu).

@cancan101
Copy link

It looks like windows support was added: #15

@skvark
Copy link
Member

skvark commented Nov 8, 2016

Haven't found yet enough time to enable ffmpeg on Linux/OS X. Yes, Windows support was a lot easier to add than for example Linux because precompiled ffmpeg shared libs are provided within OpenCV.

@cancan101
Copy link

https://github.com/opencv/opencv/tree/master/3rdparty/ffmpeg talks about various options around ffmpeg, etc and dealing with licenses. It seems that at least on OS X, oepncv should link against AVFoundation.

It might also be worth looking at how brew builds opencv3: https://github.com/Homebrew/homebrew-science/blob/master/opencv3.rb

@cancan101
Copy link

There is also some flag: WITH_AVFOUNDATION.

@skvark
Copy link
Member

skvark commented Jun 4, 2017

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 program

EDIT: 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 -> remove DT_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 :)

@skvark skvark changed the title Fail to open capture device Fail to open capture device (Linux and macOS builds are not compiled with FFmpeg) Sep 7, 2017
@arthurbarros
Copy link

@skvark is it in progress? are there any rc with it already? Thanks m8

@skvark
Copy link
Member

skvark commented Nov 10, 2017

I'm waiting for pull request for macOS support, see #49. For Linux builds FFmpeg will be added hopefully during this year.

@espadolini
Copy link

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?

@skvark
Copy link
Member

skvark commented Dec 13, 2017

I haven't tried, but I hope it works. I'm just trying to provide consistent and comprehensive packages across different platforms given that Windows builds already use FFmpeg for video I/O and macOS builds will have FFmpeg support hopefully soon.

@skvark
Copy link
Member

skvark commented Dec 15, 2017

Closing in favor of #50 and #56.

@skvark skvark closed this as completed Dec 15, 2017
@fabito
Copy link

fabito commented Dec 20, 2017

As @kerio92 mentioned. We could have webcam video capture enabled without FFMPEG.
Its a totally separate flag and dependency to enable V4L2 support in OpenCV.

@skvark
Copy link
Member

skvark commented Dec 20, 2017

FFmpeg will be supported in the next release. I will try to enable V4L2 also.

@skvark
Copy link
Member

skvark commented Dec 20, 2017

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.

@fabito
Copy link

fabito commented Dec 21, 2017

Once it's released I can help testing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants