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

Include ffmpeg #74

Open
peterkronenberg opened this issue Apr 27, 2021 · 9 comments
Open

Include ffmpeg #74

peterkronenberg opened this issue Apr 27, 2021 · 9 comments

Comments

@peterkronenberg
Copy link

According to https://forum.opencv.org/t/error-in-java-cant-find-starting-number-in-the-name-of-file/3014/2, I need opencv_videoio_ffmpeg452_64.dll. Is there any reason it's not part of the packaging?

@vonnieda
Copy link
Member

Please see other issues in this repo with regards to ffmpeg. In brief: I don't know of a way to statically link it into the binary, and it is a lot of work to try to include it. I'm open to PRs to the Github Actions scripts that fix this.

@peterkronenberg
Copy link
Author

Thanks. I just saw the other issue. Would be nice if you at least documented this and explained exactly how to set things up and where to get the correct version of ffmpeg. And are these other cavets as well, where the maven version is not complete?

I'm still having a problem and can't get it to work, even if I tried to point to ffmpeg using -Djava.library.path or -Djna.library.path. According to the issue I opened on opencv, these won't work, because Java does not load the file. I need to put the file on the class path, but can't get that working either.

@peterkronenberg
Copy link
Author

Figured out my problem. I thought the dll needed to be on the classpath, but it needs to be on the path (or in the same directory as the application)

@lynnwilliam
Copy link

Figured out my problem. I thought the dll needed to be on the classpath, but it needs to be on the path (or in the same directory as the application)

Can you give a specific example of this please?
I got the dll required and want to know where you placed them relative to the other dlls in the project ?
Could you paste the paths please?

@gevant
Copy link

gevant commented Mar 15, 2023

@vonnieda Just did some testing with interesting results:
in OpenCV 4.60 and 4.70 something changed on a way how opencv_videoio_ffmpeg4xx_64.dll is compiled and/or linked to opencv_java4xx.dll.
I tested with 4.2.0- 4.5.0 all versions do work with a ip camera, your solution to extract binaries out of a jarfile into the temp folder and set java.library.path internally would work when corresponding ffmpeg4 dll would be included, with not much additional effort. BUT 2 latest open cv distributions are compiled differently and it won't work as distributed.
My tests were performed on windows 10pro

@lynnwilliam
Copy link

lynnwilliam commented Mar 25, 2023

I got webcam and RTSP working this morning.
Confirmed in Windows 10 and windows 11.

Step 1
//this did NOT work using a TEMP File.
// I have other code that takes the opencv_videoio_ffmpeg460_64.dll file from my /resources directly and copies it over to the users /documents directory.
So do this first if you need, I did not add the code from copying the file over, since its boiler plate stuff.

Step 2
use the windows driver
opencv_videoio_ffmpeg460_64.dll
from the OpenCV.exe distribution.
Than load that opencv_videoio_ffmpeg460_64.dll file from a folder with system access e.g "c:/users/.../documents/opencv_videoio_ffmpeg460_64.dll"

Step 3
using the code
Path path = // the path to the absolute folder of the opencv_videoio_ffmpeg460_64.dll files
final String normalizedPath = path.normalize().toString();
final Field field = ClassLoader.class.getDeclaredField("usr_paths");
field.setAccessible(true);
final Set userPaths = new HashSet<>(Arrays.asList((String[]) field.get(null)));
userPaths.add(normalizedPath);
field.set(null, userPaths.toArray(new String[userPaths.size()]));
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + normalizedPath);

@vonnieda vonnieda changed the title Maven build missing opencv_videoio_ffmpeg452_64.dll Include ffmpeg Mar 28, 2023
@vonnieda
Copy link
Member

I'm consolidating other requests to include opencv-ffmpeg here, and will point others here in the future. If this is something you'd like to see implemented, please consider submitting or sponsoring a PR to implement it.

@lynnwilliam
Copy link

Yes you can just point others here and they can use this solution for Windows if they need to.
This code does work, and it is just to show that you can get windows DLLS working with your OpenCV project , without any modifications to the repo.
I think adding FFMPEG to OpenCV is a bigger request than it seems ( since you now have to support FFMPEG testing etc)
, I might open a pull request for this feature in the future.

@vonnieda
Copy link
Member

I think adding FFMPEG to OpenCV is a bigger request than it seems ( since you now have to support FFMPEG testing etc) , I might open a pull request for this feature in the future.

I agree. I have avoided it for years because of this. Maintaining this project is already a huge task: Building binaries for so many platforms is a ton of work. Adding more work just isn't something I'm super interested in, but PRs are always welcome!

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

No branches or pull requests

4 participants