NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.09k stars 14.08k forks source link

OpenCV videoio Darwin/Mac issue/discussion #97575

Closed jeff-hykin closed 4 years ago

jeff-hykin commented 4 years ago

Describe the issue In the opencv build for mac, why is videoio off by default?

https://github.com/NixOS/nixpkgs/blob/193a6a2307b7b29aa11bee309d4aa41840686ab0/pkgs/development/libraries/opencv/4.x.nix#L258-L261

What needs to be done to enable it? (either development work, dependencies that aren't yet nixpkgs, or, if possible, how to manually override the argument and simply set to =ON)

To Reproduce See above

Expected behavior There may be a good reason it's disabled, so I can't say that I'd expect videoio to be enabled by default.

Notify maintainers @basvandijk

Metadata Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-darwin"`
 - host os: `Darwin 16.7.0, macOS 10.12.6`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.7`
 - channels(root): `"nixpkgs-20.09pre234801.1facbd61b17"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
mjlbach commented 4 years ago

It was removed here 15 months ago: https://github.com/NixOS/nixpkgs/commit/9a0ced7e4502bfd5f835f3a18770fe72efd28e76

See this PR: https://github.com/NixOS/nixpkgs/pull/62752

due to apple removing most of QTkit in 10.12 https://github.com/opencv/opencv/issues/6913

Brew does not use this option. You can use an overlay or a nixpkgs checkout with this patch to build with videoio

diff --git a/pkgs/development/libraries/opencv/4.x.nix b/pkgs/development/libraries/opencv/4.x.nix
index 9dcb9956838..e33ccf0fda7 100644
--- a/pkgs/development/libraries/opencv/4.x.nix
+++ b/pkgs/development/libraries/opencv/4.x.nix
@@ -258,7 +258,7 @@ stdenv.mkDerivation {
   ] ++ lib.optionals stdenv.isDarwin [
     "-DWITH_OPENCL=OFF"
     "-DWITH_LAPACK=OFF"
-    "-DBUILD_opencv_videoio=OFF"
+    "-DBUILD_opencv_videoio=ON"
   ] ++ lib.optionals enablePython [
     "-DOPENCV_SKIP_PYTHON_LOADER=ON"
   ];

The following will drop you into a nix-shell with the patched opencv, which you can use for testing. I'm not sure if it builds. nix-shell -I nixpkgs=/path/to/local/nixpkgs -p opencv4

FWIW, I get the following build failure which indicates the upstream issue might not be resolved, or we're missing some thing in our derivation.

  [ 69%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_avfoundation_mac.mm.o
  [ 69%] Building CXX object modules/text/CMakeFiles/opencv_text.dir/src/text_detectorCNN.cpp.o
  In file included from /tmp/nix-build-opencv-4.3.0.drv-0/source/modules/videoio/src/cap_avfoundation_mac.mm:49:
  In file included from /nix/store/1vjvq0a85blja2z9dnjylplrzn03zl5x-apple-framework-AVFoundation/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:23:
  /nix/store/1vjvq0a85blja2z9dnjylplrzn03zl5x-apple-framework-AVFoundation/Library/Frameworks/AVFoundation.framework/Headers/AVAsset.h:17:9: fatal error: 'CoreMedia/CMTime.h' file not found
  #import <CoreMedia/CMTime.h>
          ^~~~~~~~~~~~~~~~~~~~
  1 error generated.
  make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:200: modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_avfoundation_mac.mm.o] Error 1
  make[1]: *** [CMakeFiles/Makefile2:4541: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
  make[1]: *** Waiting for unfinished jobs....
  [ 69%] Linking CXX shared library ../../lib/libopencv_text.dylib
  [ 69%] Built target opencv_text
jeff-hykin commented 4 years ago

You can use an overlay or a nixpkgs checkout with this patch to build with videoio

I was originally attempting to use an overlay. After getting nowhere, I made a discourse post here, which is what redirected me to the nix build. So if you want to help me close that thread, that'd be awesome 😁 cause both me and the person that helped me still don't know how to access/change the cmakeFlags from an overlay.