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

Support local build, support ffmpeg for windows, linux, macos, android #262

Merged
merged 31 commits into from
Oct 23, 2024

Conversation

rainyl
Copy link
Owner

@rainyl rainyl commented Oct 10, 2024

  • local build, download opencv sdk from opencv.full
  • support ffmpeg for windows, linux, android, macos (ios can't embed dylib, which will conflict with LGPL 2.0 license)
  • add DartCvMacOS dependency for macos
  • add DartCvIOS for ios
  • move all dart code to independent plugin dartcv
  • move all C wrappers code to dartcv https://github.com/rainyl/dartcv
  • Merge sync and async C wrappers.
  • macos: support 10.15 and above
  • android: API level 24 and above
  • ios: 12.0 and above
  • Breaking change: highgui, remove Window and Trackbar class, use functions like opencv c++ and python directly, e.g., cv.namedWindow("TestWindow"), more examples refer to: https://github.com/rainyl/opencv_dart/blob/split-dartcv/packages/dartcv/test/highgui_test.dart
  • Breaking change: many asynchronous class constructors, property getters/setters were removed (since no benifits), some APIs were changed.

Pros:

  • build locally invoked by Flutter, dependency will be properly processed by Flutter
  • provide an option to remove unneeded libraries like videoio, highgui via opencv_core
  • remove the dependency of system-wide ffmpeg by custom linked FFMPEG 6.1, in this way, linux users with different distributions can use ffmpeg, and macos libraries don't need to rebuild every time brew update ffmpeg (they update it frequently)

Cons:

  • users will need to download opencv sdk, which is very large (~100M), but we provide an option to downlaod and cache it once, set DARTCV_CACHE_DIR environment variable to cache it, e.g., set DARTCV_CACHE_DIR to C:/Users/<username>/.dartcv on windows, export DARTCV_CACHE_DIR=/home/<username>/.cache/dartcv on unix-like system
  • For those who want to use platform specific backends ONLY, i.e., MSMF on windows, AVFoundation on macos and ios, MediaNDK on android, it's impossible for now, they have to compile opencv by themselves.

@abdelaziz-mahdy
Copy link
Contributor

may i ask why the separation needed? like will we need android and windows and linux libs too?

same as done in media_kit?

are you planning to have configuration with ffmpeg and without it? will that help with the vulkan stuff?

@rainyl
Copy link
Owner Author

rainyl commented Oct 11, 2024

may i ask why the separation needed? like will we need android and windows and linux libs too?

same as done in media_kit?

  1. like i said before, i want to support ffmpeg for all platforms, better with same version.
  2. the previous building of opencv.full relies on system-wide ffmpeg, especially on macos, brew updates ffmpeg actively, so opencv.full has to be recompiled every time they update ffmpeg.
  3. thus, i want to compile opencv with custom linked ffmpeg, for this, i collected/forked some repos, including https://github.com/rainyl/FFmpeg-Builds and https://github.com/wang-bin/avbuild
  4. and, considering the increased app size and the fact that many users doesnt need it, it's better to provide a package without ffmpeg, so opencv_core was born.
  5. considering that the only difference between opencv_dart and opencv_core is the ffmpeg, both for dart and c codes, extracting the dart code and C code seems to be a good choice, right?
  6. so the dart codes were extracted to dartcv, this also benefits those who work without flutter, i.e., pure dart users, since the dependency of flutter is totally removed.
  7. As for C code, it's not necessary to extract them to an independent repo, BUT, CocoaPods requires it, so I have to, oh, and the CocoaPods, I didn't find any elegant way to integrate CMake inside podspec, like detecting the target platform and archtecture dynamically and tell CMake what to do, so I spent much time on developing two packages (DartCvIOS and DartCvMacOS) and published them to CocoaPods, in this way, we can just add s.dependency DartCvIOS to ios/opencv_dart.podspec to introduce the package and let flutter to do the rest things, e.g., produce the correct Info.plist.

To summarize, we do not need platform specific packages like media_kit, but 2 new packages for different users.

are you planning to have configuration with ffmpeg and without it? will that help with the vulkan stuff?

  • For those who need videoio, use opencv_dart
  • For pure dart users, use dartcv
  • For others, use opencv_core
  • Cons. For those who want to use platform specific backends ONLY, i.e., MSMF on windows, AVFoundation on macos and ios, MediaNDK on android, it's impossible for now, they have to compile opencv by themselves.

I am not sure about the vulkan, but I think it's no difference than before.

@abdelaziz-mahdy
Copy link
Contributor

Ok thank you for the explanation

Were the specific backends supported before?

@rainyl
Copy link
Owner Author

rainyl commented Oct 11, 2024

Were the specific backends supported before?

Yes, but they are very limited, there are several issues about this.

@abdelaziz-mahdy
Copy link
Contributor

After seeing the issues, I think your approach is the right approach

Since ffmpeg is heavy and not needed for most cases, let me know If you need any assistance in anything

@rainyl
Copy link
Owner Author

rainyl commented Oct 22, 2024

After seeing the issues, I think your approach is the right approach

Since ffmpeg is heavy and not needed for most cases, let me know If you need any assistance in anything

Thanks! ffmpeg related works have almost been finished, but I am still working on universal APIs, i.e., merge sync and async C wrappers, for better maintainability and uniform dart APIs, by adding empty callbacks to the wrappers needed to be called asynchronously.

this is almost finished too, however, some tests were failed and needs to be fixed. it would be helpful if you can help to fix them.

@abdelaziz-mahdy
Copy link
Contributor

i will look into it, is there is any new steps to running the tests locally?

@rainyl
Copy link
Owner Author

rainyl commented Oct 22, 2024

i will look into it, is there is any new steps to running the tests locally?

for macos, a manually built library is needed, I will add another action to build it in https://github.com/rainyl/dartcv

@rainyl rainyl linked an issue Oct 23, 2024 that may be closed by this pull request
@rainyl
Copy link
Owner Author

rainyl commented Oct 23, 2024

All tests passed now.

@abdelaziz-mahdy You can download prebuilt libs from https://github.com/rainyl/dartcv/releases/tag/4.10.0%2B2 now.

@rainyl rainyl merged commit 9bbf19c into main Oct 23, 2024
9 checks passed
@rainyl rainyl deleted the split-dartcv branch October 23, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants