processing / processing-video

GStreamer-based video library for Processing
274 stars 130 forks source link

Video Capture not Working on MacOS #178

Open makakken opened 3 years ago

makakken commented 3 years ago

Problem: Open Processing, load Example: Libraries/Video/Capture/mirror, start sketch, sketch crashes and prints: Processing video library using GStreamer 1.16.2 Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help → Troubleshooting. Copied to the clipboard. Use shift-click to search the web instead.

Versions: MacOS 11.2 BigSur Processing: 4.0.3a VideoLib: 2.0

Has anyone got the same Problem? How to fix it?

megamattron commented 3 years ago

As best as I can tell it's a camera permissions problem, Processing isn't asking for the permission properly. If your terminal has the camera permission you can run Processing from the terminal and it might work, see #177 for more info there.

makakken commented 3 years ago

i definitely think you're right, but i never get a prompt to give processing the permission to use cam or microphone. How can I manually trigger this prompt? How can i trigger it for terminal (command-line) i've already tried to start processing via CLI but it's also not asking for permission....

highjeans commented 3 years ago

To get the permissions you go to System Settings -> Security & Privacy -> Privacy -> Camera and see if Processing is there. Let me know if its not there for you

megamattron commented 3 years ago

When using the actual Processing app it wouldn't prompt for camera permission, but when using the Processing libs in a Java app it did prompt, so I'm not quite sure what's going on.

makakken commented 3 years ago

I'm sorry, it's not in there.... (System Settings -> Security & Privacy -> Privacy -> Camera)... i've googled, but it seems macos has no way to add apps manually there....

doronby commented 3 years ago

I am using ver 4.0a3 with Video 2.0 library but I am still getting runtime error "A library used by this sketch is not properly installed" (I am trying to run one of the examples) and the cursor is on this line " video = new Capture(this, width, height);" Tried uninstalling and re-installing the video library 2.0 as well as re-install Java but... I get the same error. "UnsatisfiedLinkError: Could not load library: gstreamer" Anyone got it working on Catalina 10.15.6 ? How?

P.S. Processing is not listed in the "Security and Privacy" as an app that has access to the camera.

marcobrianza commented 3 years ago

running Processing from the terminal works for me, asking for permissions. The permission get granted to the terminal not Processing, so it must run from the terminal each time.

infovore commented 3 years ago

+1 to @doronby and others; on Catalina 10.15.7, running Processing 4.0 alpha 3, and latest video library... and still no change. I have had success running Processing from the terminal, and granting permission for the terminal application to access the camera, but I'm not going to be comfortable using that approach with students.

And Processing doesn't appear in the list of applications requesting access to the camera, in Security and Privacy.

owochel commented 3 years ago

I have tried the solution offered in #134, and it wouldn't work. I also manually checked all the .dylib and made sure the string started with 00c1.

Versions: macOS Big Sur 11.2.3 Processing: 4.0.3a VideoLib: 2.0

owochel commented 3 years ago

But this did work for me: http://wiki.iad.zhdk.ch/CV/904626177/Video+Library+2.0

codeanticode commented 3 years ago

Even though Processing's PList file contains the entry <key>NSCameraUsageDescription</key> (https://github.com/processing/processing4/commit/c5baab0b6e2d63a3c82f128b03fae8dc8a63ac34), camera permission is not granted unless using the launch-from-terminal workaround that @owochel mentioned. Maybe the video library or Processing have to execute some native code (through JNI) to request authorization? More info below:

https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos

benfry commented 3 years ago

The prompt comes up automatically, but I wonder if there's a thread issue that's preventing it from showing up… there's macOS weirdness with how event handling is different (the “run on first thread” stuff). That would also be consistent with it working sometimes for me—video was working fine on my machine when I shipped the release.

Otherwise I'm not sure what else would be different about launching from the command line versus double-clicking the app. Then again, using JNA to request authorization from a preferred thread (rather than waiting for the default) might do the trick.

benfry commented 3 years ago

Video and Audio seem to be having similar problems.

Try with this version, it adds more entitlements for the macOS “hardened runtime” setup, which may be helpful. https://download.processing.org/processing-1274-macosx.zip

But even without those, I can get video (and I presume audio) capture working on Big Sur. So I'd like more involvement from the authors of those libraries to debug the problem.

With video, it's slow to start, but I get the prompt:

Screen Shot 2021-06-18 at 3 35 28 PM

This is printed twice to the console, when the prompt is showing:

BaseSrc: [avfvideosrc0] : Device video access permission has just been denied

But if I close the sketch and hit Run again after the first authorization, it's working:

Screen Shot 2021-06-18 at 3 38 03 PM

The fact that it's so slow to start the sketch, and that the error message is printed twice also suggests that there are probably multiple issues inside the video library itself.

To debug, you may also want to use tccutil reset Camera or tccutil reset All org.processing.app to reset the prompts. The former will reset it for your other apps as well. I've not tried the latter (so no guarantees), but it oughta work.

codeanticode commented 3 years ago

@benfry I get the same thing with version 1274 (the duplicate message in the console after showing the permission dialog) but then it works when the running the sketch for a second time. The tccutil command is very handy to reset the permission and debug, thank you!

However, one (preliminary) observation. I only get the error during the first run of the sketch when using an M1 MacBook Air (and its reproducible, it happens again if I reset the permission). But on an Intel iMac, there is no error, camera capture works in the first attempt (also reproducible).

So better than before for sure :-)

benfry commented 3 years ago

The images I posted were based on alpha 4, which has no changes to the video/audio setup since alpha 3, where folks have been having trouble. The -1274 build at the link has a couple extra entitlements on the notarized build, but it's not clear if they'll do anything.

Bottom line, from the PDE side, things should be in good shape, but the video library needs more testing. If there's anything else I need to add to the PDE, let me know, but this is as far as I can go.

codeanticode commented 3 years ago

The sketch crashes when opening the permission dialog in 4.0a3, so the extra entitlements seem to be making a difference. I'll look into what else could be in the library to handle the initialization issues.

doronby commented 3 years ago

I am still getting the same error:

UnsatisfiedLinkError: Could not load library: gstreamer UnsatisfiedLinkError: Could not load library: gstreamer A library relies on native code that's not available. Or only works properly when the sketch is run as a 32-bit application. UnsatisfiedLinkError: Could not load library: gstreamer UnsatisfiedLinkError: Could not load library: gstreamer UnsatisfiedLinkError: Could not load library: gstreamer UnsatisfiedLinkError: Could not load library: gstreamer Copied to the clipboard. Use shift-click to search the web instead.

codeanticode commented 3 years ago

Sounds like the gstreamer libraries are not loading properly. What version of MacOS are you on? And hardware specs?

doronby commented 3 years ago
Screen Shot - About my mac

Big Sur 11.3.1 Imac (Retina 5k, 27-inch, late 2015).See more in attachment.

-----------------------------------------From: "codeanticode" 

To: "processing/processing-video" Cc: "doron", "Mention" Sent: Sunday June 20 2021 7:29:51PM Subject: Re: [processing/processing-video] Video Capture not Working on MacOS (#178)

Sounds like the gstreamer libraries are not loading properly. What

version of MacOS are you on? And hardware specs?

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [1], or unsubscribe [2].

Links:

[1] https://github.com/processing/processing-video/issues/178#issuecomment-864627414 [2] https://github.com/notifications/unsubscribe-auth/ABPOMLDFP5HVAZJHJA7DUQLTTZ2W5ANCNFSM4XEKQQGQ

infovore commented 3 years ago

Try with this version, it adds more entitlements for the macOS “hardened runtime” setup, which may be helpful. https://download.processing.org/processing-1274-macosx.zip

@benfry so this works out of the box with Video on 10.15.7, with all my weird/wonderful attached cameras, virtual or otherwise; it correctly asks for permission and gets it.

benfry commented 3 years ago

@infovore Thanks for the update. Fingers crossed that it's working; the changes will be in 4.0 alpha 5.

As a separate note, the changes do not affect running from source; these are entitlements that only come into play when using Processing.app from a download.

benfry commented 3 years ago

4.0 alpha 5 is now available: https://github.com/processing/processing4/releases

doronby commented 3 years ago

Running on Big Sur version 11.3.1 and still getting this error: UnsatisfiedLinkError: Could not load library: gstreamerUnsatisfiedLinkError: Could not load library: gstreamerA library relies on native code that's not available.Or only works properly when the sketch is run as a 32-bit application

-----------------------------------------From: "Ben Fry" 

To: "processing/processing-video" Cc: "doron", "Mention" Sent: Tuesday July 6 2021 10:57:03AM Subject: Re: [processing/processing-video] Video Capture not Working on MacOS (#178)

4.0 alpha 5 is now available: 

[1]https://github.com/processing/processing4/releases [2]

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [3], or unsubscribe [4].

Links:

[1] https://github.com/processing/processing4/releases [2] https://github.com/processing/processing4/releases [3] https://github.com/processing/processing-video/issues/178#issuecomment-874834133 [4] https://github.com/notifications/unsubscribe-auth/ABPOMLCDYSL3QR7I3JF2ER3TWMKT5ANCNFSM4XEKQQGQ

doronby commented 3 years ago

Sounds like the gstreamer libraries are not loading properly. What version of MacOS are you on? And hardware specs?

Big Sur 11.3.1 on iMac Retina 5k, late 2015.

my machine
infovore commented 3 years ago

@benfry on 4.0a5, running on osx 10.15.7, I am asked for permission for the camera the first time I try to use it in a Video library example; when I give it permission, it all seems to behave correctly, and I can load the video capture sample sketches. So this is no use for the Big Sur folks, but hope that's of use to know.

doronby commented 3 years ago

I got it to work. I installed both .pkg from the following directory and it's now all WORKING for me with the 4.0a5.... Here is the directory: https://gstreamer.freedesktop.org/data/pkg/osx/1.19.1/

codeanticode commented 3 years ago

@doronby thanks for the update. I will make sure to package gstreamer 1.19 in the next release of the video library.

makakken commented 2 years ago

Processing 4.0beta fixed it for me 👍 works from command Line, works from Processing ide