processing / processing-video

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

Video capture not working in Mac OS Catalina (and later) #134

Closed grauwald closed 3 years ago

grauwald commented 4 years ago

Running the example file that comes with the Processing video library throws the following error:

libc++abi.dylib: terminating with uncaught exception of type NSException Could not run the sketch (Target VM failed to initialize). Make sure that you haven't set the maximum available memory too high. For more information, read revisions.txt and Help β†’ Troubleshooting.

This issue is also reported here:

https://discourse.processing.org/t/did-macos-catalina-or-something-break-the-video-library/14699

There is some speculation in that thread that the library depends on 32bit compiled code which is no longer supported in Mac OS Catalina as Apple is now requiring applications be 64bit.

Resolving this issue is beyond my expertise but it would be awesome if Mac users could continue to use the video library without having to downgrade to older versions of OS X.

grauwald commented 4 years ago

Some further info on this for anyone willing and able to tackle it. As the Video library is built off GStreamer decided to take a look at that project directly and found a recent commit that adds support of Mac OS X Catalina:

https://github.com/GStreamer/cerbero/commit/2c9fc162f15e68c33b75f287dfa401e27452e3f7

Perhaps this is as simple as integrating this new build?

suyashcjoshi commented 4 years ago

I'm seeing the same problem, even simple Processing Video example Sketch is not working on Mac OS Catalina.

suyashcjoshi commented 4 years ago

Some further info on this for anyone willing and able to tackle it. As the Video library is built off GStreamer decided to take a look at that project directly and found a recent commit that adds support of Mac OS X Catalina:

GStreamer/cerbero@2c9fc16

Perhaps this is as simple as integrating this new build?

I tried to look but can't figure out where to make change in order to integrate the new build of cerbero.

james628 commented 4 years ago

I am looking forward to catch this bug. Please solve and release. Thank you.

grauwald commented 4 years ago

@codeanticode it looks like you are the primary maintainer of this lib. Any chance Mac OS Catalina will be supported in the future?

codeanticode commented 4 years ago

@grauwald Definitely, this is a high-priority issue. I haven't installed Mac OS Catalina yet, so I'm curious if you have tried the latest beta, does it work with it?

vdurnev commented 4 years ago

@codeanticode I can confirm that with latest beta build video examples stat working again. There is another issue with samples - you have to pass camera name to Capture constructor). This code: video = new Capture(this, width, height); generates null pointer exception, but video = new Capture(this,320, 240, "FaceTime HD Camera"); works

codeanticode commented 4 years ago

@vdurnev this is great news, thanks a lot for testing! The other issue you mentioned has been fixed with this PR: https://github.com/processing/processing-video/pull/135

larspai commented 4 years ago

Super news. How does an ordinary user get access to this update? (No update available in install library menu...?)

grauwald commented 4 years ago

@codeanticode was able to successfully run the latest beta of v2 of the video library. Yay!!!

For those coming along trying to do this, had to do some command line to get OS X to give permissions to run the .dylib used by the lib. Based on this hackish solution here: https://github.com/Jackett/Jackett/issues/5589#issuecomment-508560798

Guessing the final release of this lib will be signed and verified so this security issue in Catalina won't be a problem.

ihaveaccount commented 4 years ago

v2 library works on catalina, thank you @codeanticode

How to install

$ xattr -p com.apple.quarantine libavcodec.58.35.100.dylib it will return string like this: 0081;5dc1bfaa;Chrome;78F18F7D-3F71-4E55-8D58-BAB946AB4707

replace 0081 with 00c1 and copy string

then replace STRING in the following command with your string $ xattr -w com.apple.quarantine "STRING" *.dylib it will fix all libraries in this folder

then cd to gstreamer-1.0/ and run command again

larspai commented 4 years ago

Worked for me. Thanks!

easytarget2000 commented 4 years ago

Thanks a lot, @ihaveaccount. That did the trick. There were two parts that I struggled with for a second:

then replace STRING in the following command with your string $ xattr -w com.apple.quarantine "STRING" *.dylib

Don't forget the quotation marks!

then cd to gstreamer-1.0/ and run command again

At first, I skipped over this part, as I thought it was talking about re-running the project at this point. gstreamer-1.0/, however, is a sub-dir of library/macosx/. You're supposed to run the xattr -w command in both directories.

It might have been my lack of reading comprehension, but I figured I'd share this as there will be many users in need of this solution over the next couple of days.

You want to run something like this: $ cd ~/Documents/processing/libraries/video/library/macosx $ xattr -p com.apple.quarantine libavcodec.58.35.100.dylib $ xattr -w com.apple.quarantine "00c1;5dc1bfaa;Chrome;78F18F7D-3F71-4E55-8D58-BAB946AB4707" *.dylib $ cd gstreamer-1.0 $ xattr -w com.apple.quarantine "00c1;5dc1bfaa;Chrome;78F18F7D-3F71-4E55-8D58-BAB946AB4707" *.dylib

Also, be aware that your Processing sketchbook might not be in ~/Documents/processing/, if you have configured the path yourself.

Stuver commented 4 years ago

I have tried this twice and the only difference I can see is that I'm using Safari instead of Chrome. Would this make a difference?

easytarget2000 commented 4 years ago

@Stuver, I don't think the source makes a difference. Did you make sure that you used your result from xattr -p com.apple.quarantine libavcodec.58.35.100.dylib and replaced the first four chars with 00c1? Do you get an error message in Processing or an OS error message regarding insecure libraries?

Stuver commented 4 years ago

Yes. I've done that and manually verified all the packages within the library and still no luck

briangriffith commented 4 years ago

I can also confirm it worked, the manual validation of 200+ lib files is wildly frustrating, aside from that @ihaveaccount and @easytarget2000 give solid instructions.

5knnbdwm commented 4 years ago

Hey, it tried it all and it still isn't working for me. But I also got a different result from running xattr -p com.apple.quarantine libavcodec.58.35.100.dylib. As instead of 0081 I got 0083, changed it anyways to 00c1. The error message that I now receive are Processing video library using GStreamer 1.16.0 and a couple NullPointerException

danieloskarsson commented 4 years ago

I also updated to Catalina and struggled with this and only got it working thanks to comments by @codeanticode @ihaveaccount and @vdurnev. However to get it work on my 2018 Macbook Pro 13" needed to change the name of the camera "FaceTime HD Camera" -> "FaceTime HD Camera (Built-in)".

import processing.video.*;
static final String CAMERA_NAME = "FaceTime HD Camera (Built-in)";
Capture cam;
void setup() {
  size(1080, 720);
  cam = new Capture(this, width, height, CAMERA_NAME);
  cam.start();
}
romya0010 commented 4 years ago

Update: OK, @danieloskarsson thanks, tried your method and it works perfect. You saved my life πŸ₯‡

Hi guys, I'm new here... very exited :) So I got the video library working with your amazing advice and updates, but now, trying to use opencv library for computer vision, I get this error message: Processing video library using GStreamer 1.16.0 NullPointerException...

Help please

Here's the code (from examples of opencv library):

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();
}

void draw() {
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
}

void captureEvent(Capture c) {
  c.read();
}
codeanticode commented 4 years ago

@romya0010 I think that's because of a bug in beta 4 reported here #130. For the time being, the workaround is to add the camera name to the arguments of the Camera constructor.

mariuswex commented 4 years ago

Hello, im new and this is my first day i worked with processing. I hope you can help me. I got the Problem with the FaceTime Camera. I also work with macOS Catalina.

At this point I can't get forward.

  • open console, cd to ~/Documents/processing/libraries/video/library/macosx

Which console? what do you mean with "cd"

And I can't find this file: 0081;5dc1bfaa;Chrome;78F18F7D-3F71-4E55-8D58-BAB946AB4707

And I don't understand this: then replace STRING in the following command with your string $ xattr -w com.apple.quarantine "STRING" *.dylib it will fix all libraries in this folder

then cd to gstreamer-1.0/ and run command again

Please help me, thanks a lot!

vwls commented 4 years ago

v2 library works on catalina, thank you @codeanticode

How to install

$ xattr -p com.apple.quarantine libavcodec.58.35.100.dylib it will return string like this: 0081;5dc1bfaa;Chrome;78F18F7D-3F71-4E55-8D58-BAB946AB4707

replace 0081 with 00c1 and copy string

then replace STRING in the following command with your string $ xattr -w com.apple.quarantine "STRING" *.dylib it will fix all libraries in this folder

then cd to gstreamer-1.0/ and run command again

Solution worked for me (macOS Catalina 10.15.1 MacBook Pro Retina 13 inch early 2013 edition). Thanks @ihaveaccount and @codeanticode !

dantepfer commented 4 years ago

Installed beta 4 successfully following @ihaveaccount's directions, on Catalina. Video examples work as long as a name is specified for the camera, but the default camera (no name specified) does not, as others have pointed out.

@codeanticode, thanks much for your work on this. FYI, I do camera capture with a BlackMagic interface. For some reason it's never turned up with a name in the "Available Cameras" list, but it does work as the default camera (without specifying a name). So, for now my ability to use it is broken, and I'll be very happy when the previous default camera behavior returns. Thanks again!

codeanticode commented 4 years ago

@dantepfer thanks for your update. I had pause the work on the video library while I take care of other projects but the plan is to come back to it as soon as time permits and finalize the v2 release :-)

gregtreadwell commented 4 years ago

Only partial success for me. I can see the attached cameras when I search for them, and the sketches will run, however the cameras are not activated and I get the following errors. When sketch run in Processing: Processing video library using GStreamer 1.16.0 BaseSrc: [avfvideosrc0] : Internal data stream error.

When sketch run in Sublime Text: Processing video library using GStreamer 1.16.0 Could not run the sketch (Target VM failed to initialize).

Anyone have any insights or alternate steps?

johnbcarpenter commented 4 years ago

oof, this was a tough bug to discover on the first night of class covering computer vision... @codeanticode is there any update on this? might be good to land a beta release or something for classes that are starting this week. [edit: fortunately only 4 or 5 students had catalina installed]

ti84plusprograms commented 4 years ago

Hi everyone,

I've tried mixing this answers without success. It keeps saying: java.lang.NullPointerException at processing.app.Library.getClassPath(Library.java:368) at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:424) at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:155) at processing.mode.java.JavaBuild.build(JavaBuild.java:122) at processing.mode.java.JavaBuild.build(JavaBuild.java:104) at processing.mode.java.JavaMode.handleLaunch(JavaMode.java:122) at processing.mode.java.JavaEditor.lambda$0(JavaEditor.java:1099) at java.lang.Thread.run(Thread.java:748)

What can I do?

Thanks for your help.

Thanks a lot, @ihaveaccount. That did the trick. There were two parts that I struggled with for a second:

then replace STRING in the following command with your string $ xattr -w com.apple.quarantine "STRING" *.dylib

Don't forget the quotation marks!

then cd to gstreamer-1.0/ and run command again

At first, I skipped over this part, as I thought it was talking about re-running the project at this point. gstreamer-1.0/, however, is a sub-dir of library/macosx/. You're supposed to run the xattr -w command in both directories.

It might have been my lack of reading comprehension, but I figured I'd share this as there will be many users in need of this solution over the next couple of days.

You want to run something like this: $ cd ~/Documents/processing/libraries/video/library/macosx $ xattr -p com.apple.quarantine libavcodec.58.35.100.dylib $ xattr -w com.apple.quarantine "00c1;5dc1bfaa;Chrome;78F18F7D-3F71-4E55-8D58-BAB946AB4707" *.dylib $ cd gstreamer-1.0 $ xattr -w com.apple.quarantine "00c1;5dc1bfaa;Chrome;78F18F7D-3F71-4E55-8D58-BAB946AB4707" *.dylib

Also, be aware that your Processing sketchbook might not be in ~/Documents/processing/, if you have configured the path yourself.

I also updated to Catalina and struggled with this and only got it working thanks to comments by @codeanticode @ihaveaccount and @vdurnev. However to get it work on my 2018 Macbook Pro 13" needed to change the name of the camera "FaceTime HD Camera" -> "FaceTime HD Camera (Built-in)".

import processing.video.*;
static final String CAMERA_NAME = "FaceTime HD Camera (Built-in)";
Capture cam;
void setup() {
  size(1080, 720);
  cam = new Capture(this, width, height, CAMERA_NAME);
  cam.start();
}
danieloskarsson commented 4 years ago

TDLR: Verify that the exact name of your camera is used in your code.

@AryCuber If I remember correctly NullPointerException is what I saw before changing the name of the camera as indicated in my previous post that you have quoted last in your post.

In more detail what I did to get my camera name was to go to "About This Mac" > "System Report..." > "Hardware" > "Camera" and copy all before the ":". I.e. the "FaceTime HD Camera (Built-in)" part from "FaceTime HD Camera (Built-in):" and use that as the value of CAMERA_NAME. If you have not already I would make sure that you send in a matching camera name as the forth parameter to the Camera constructor.

static final String CAMERA_NAME = "FaceTime HD Camera (Built-in)";
cam = new Capture(this, width, height, CAMERA_NAME);
ti84plusprograms commented 4 years ago

Thanks, really helpful, it started. working.

elsameyer commented 4 years ago

Hi everyone, I've also tried everything listed here and I still get this result.

[Processing video library using GStreamer 1.16.2
Available cameras:
[0] "FaceTime HD Camera"
BaseSrc: [avfvideosrc0] : Device video access permission has just been denied
BaseSrc: [avfvideosrc0] : Device video access permission has just been denied
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help β†’ Troubleshooting.

Is there anything else I can try? Thank you.

danieloskarsson commented 4 years ago

@elsameyer looks like Processing is not allowed to use the Camera. Try going to "System Preferences > Security & Privacy > Camera" and make sure that Processing is checked.

elsameyer commented 4 years ago

@danieloskarsson When I go to settings, processing isn't even listed as an option for the camera to open.

danieloskarsson commented 4 years ago

@danieloskarsson When I go to settings, processing isn't even listed as an option for the camera to open.

Then something has gone wrong. Upon first use of the Camera on Catalina (e.g. running a sketch that wants to use it) there should be a popup dialog asking you to confirm access to the Camera.

Edit: Please note that this is just something that I had to make sure of was correct when making accessing the camera work in Processing on Catalina. Your result may of course be because of something else.

elsameyer commented 4 years ago

@danieloskarsson When I load the code in Processing, before it prompts me to confirm camera access, the code crashes and gives the above result instead.

danieloskarsson commented 4 years ago

@elsameyer If not already I would try a minimal working example sketch instead of the one that crashes.

toyoxx commented 4 years ago

I have the same issue as @elsameyer. Which version of Catalina are you in? I'm in 10.15.2. Apparently in Catalina, when an app is going to use the camera, a popup should show. The problem is that this popup never shows in Processing. It might be due to the lack of the key NSCameraUsageDescription on their Info.plist. I tried to add it manually but PDE just stopped opening altogether. I have no idea what to do anymore.

gregtreadwell commented 4 years ago

Update Processing today, still can't camera sketches to run,though I am getting a new error. Seems to be Java Core Dump disabled?

BaseSrc: [avfvideosrc0] : Internal data stream error. OpenCV for Processing 0.5.4 by Greg Borenstein http://gregborenstein.com Using Java OpenCV 2.4.5.0 sceneCount.get(i): 0 sceneCount.get(i): 1 sceneCount.get(i): 2 sceneCount.get(i): 3 sceneCount.get(i): 4 sceneCount.get(i): 5 #

A fatal error has been detected by the Java Runtime Environment:

#

SIGSEGV (0xb) at pc=0x00007fff66815029, pid=1695, tid=0x000000000001140f

#

JRE version: Java(TM) SE Runtime Environment (8.0_202-b08) (build 1.8.0_202-b08)

Java VM: Java HotSpot(TM) 64-Bit Server VM (25.202-b08 mixed mode bsd-amd64 compressed oops)

Problematic frame:

C [libobjc.A.dylib+0x6029] objc_msgSend+0x29

#

Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

gregtreadwell commented 4 years ago

So a quick update: sketches using the video library will work, it's now limited to any sketch using OpenCV (haven't tried Open Kinect). OpenCV can produce a list of attached cameras, but cannot activate them.

costaponto commented 4 years ago

Unfortunately, still don't get any solution, I already did all solutions on this page but video captures still don't work. I already downloaded Processing 4 but there is the same problem, however I will wait for some good news! Thanks for all the support.

shuuteng commented 4 years ago

I have tried with V2, but the camera still didn't work . also, I cannot access the camera list with Capture.list(). Same as this issue , my macbook is the new one, 16 inch , late 2019, macOS 10.15.2(Catalina). There`s another problem with the new Mac , when I run the processing .such as window stuck occurs, when I using P3D, and the console will show some bug message which I could not understand.

vertexi commented 4 years ago

I have tried to use the beta version of processing-video and the correct camera name. But when I run the example sketch, it still doesn't work. This is my result: Processing video library using GStreamer 1.16.0 Available cameras: [0] "FaceTime HD Camera" Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help β†’ Troubleshooting. I thought maybe the processing can't prompt me to confirm camera access. I have tried to run the example in Linux in a virtual machine, and it will prompt me to confirm camera access to the virtual machine software. Then it works properly.

dkgrieshammer commented 4 years ago

I have tried to use the beta version of processing-video and the correct camera name. But when I run the example sketch, it still doesn't work. This is my result: Processing video library using GStreamer 1.16.0 Available cameras: [0] "FaceTime HD Camera" Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help β†’ Troubleshooting. I thought maybe the processing can't prompt me to confirm camera access. I have tried to run the example in Linux in a virtual machine, and it will prompt me to confirm camera access to the virtual machine software. Then it works properly.

same here; tried the above workaround, also get a no such xattr com.apple.quarantine somehow. Currently doing a project with students it's pretty sad I can't get it work. Thanks for your great work btw :)

fdb commented 4 years ago

Here's my solution, adapted from https://github.com/processing/processing-video/issues/134#issuecomment-550000519:

  1. Download the latest video release from from the releases page.
  2. Unzip the folder into ~/Documents/Processing/libraries. (Remove the existing video folder if it's there)
  3. Open the Terminal, type cd, a space, and dragging in the video folder. Then press enter. It should look like this:
    cd /Users/YOUR_USER_NAME/Documents/Processing/libraries/video
  4. Delete the quarantine flag β€” this fixes the "gstreamer is not signed" error.
    xattr -r -d com.apple.quarantine *
  5. Restart Processing.
  6. The basic GettingStartedCapture example should work out of the box. All other examples require an extra step.
  7. In each example, the Capture constructor requires the name of the camera. Adapt each example like so:
  // old code
  video = new Capture(this, 640, 480);

  // new code
  String[] cameras = Capture.list();
  video = new Capture(this, 640, 480, cameras[0]);
yaserg555 commented 4 years ago

Thanks All for trying to solve this issue! Tried all the solutions , but no result:(

Catalina 10.15.3 Using the basic GettingStartedCapture example, also tried to include camera name.

The best that I got is the next.

Processing video library using GStreamer 1.16.0 Available cameras: [0] "USB Camera #2" [1] "FaceTime HD Camera (Built-in)" Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help β†’ Troubleshooting.

tried to add the second usb camera. Also, I don't see in Security & Privacy Processing thing.

Hope OpenCV , Processing, And apple developers will fix this bug.


Update. manually installed streamer 1.16.2 from here

now new language

Processing video library using GStreamer 1.16.2 Available cameras: [0] "USB Camera" [1] "FaceTime HD Camera (Built-in)" BaseSrc: [avfvideosrc0] : Device video access permission has just been denied

Checked Security &Privacy - nothing about processing in the Camera tab

C0T0N commented 4 years ago

I just updated to Catalina and I have exactly the same problem as @elsameyer. I have replaced the video library with the beta one and the .dylib don't seem to be quarantined, when I run the command xattr -p com.apple.quarantine libavcodec.58.35.100.dylib it returns xattr: libavcodec.58.35.100.dylib: No such xattr: com.apple.quarantine

However when I try to run the GettingStartedCapture example, the sketch crashes and I get this in the console: Processing video library using GStreamer 1.16.0 Available cameras: [0] "FaceTime HD Camera" Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help β†’ Troubleshooting.

I have checked into my security preferences and under camera, Processing doesn't show up. I've never had a window pop up asking if I wanted to allow Processing to use the camera. I tried to use Xcode to add the NSCameraUsageDescription key to the Processing Info.plist file but after that Processing wouldn't open without crashing…

fdb commented 4 years ago

@C0T0N the correct invocation is:

xattr -r -d com.apple.quarantine *

Or if you want to remove the quarantine flag just on the single dylib:

xattr -d com.apple.quarantine libavcodec.58.35.100.dylib
C0T0N commented 4 years ago

@fdb I tried to run that command while in the video directory and both the macos and gstreamer-1.0 directories. Restarted Processing each time and I'm still getting the same error: Processing video library using GStreamer 1.16.0 Available cameras: [0] "FaceTime HD Camera" Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help β†’ Troubleshooting.

I'm not sure it's a quarantine problem. Processing never asked to access my webcam and it doesn't show up in the camera tab in Security & Privacy in my System Preferences.

Real-John-Cheung commented 4 years ago

I tried the method @fdb used(Thank you very much for that) but still the sketch crashes and this error occur Could not run the sketch (Target VM failed to initialize). very similar to the situation that @C0T0N met I guess that's because the access to the built in camera still blocked by macOS for some reason. I don't have a usb camera so I don't know if usb camera can work... and my system is in Traditional Chinese so the built in camera name have Chinese characters, I don't know if that matter...

lucidprojects commented 4 years ago

This process is working for me and a few others as a work around. Not the best but it does allow to permanently add camera access. This is working on both Mojave and Catalina. (Catalina needs to have the Video 2.0-beta3 lib installed).

1) turn off SIP a.) reboot/restart in safe mode - hold cmd R on restart b.) from the menu bar go to utilities/terminal c.) enter cmd - csrutil disable d.) restart computer

2) in terminal navigate to ~/Library/ApplicationSupport/com.apple.TC a.)cd /Users/##YOUR_USER##/Library/Application Support/com.apple.TC

3) open sqlite db - sqlite3 TCC.db (as extra precaution maybe copy TCC.db to back up (cp TCC.db TCC_BACKUP_DATE.db) )

4) OPTIONAL modify view (this just makes it easier to look at) a) .mode columns b) .headers on

5) OPTIONAL - see everything with access select * from access;

6) ADD camera access for processing - run this insert query - this will add a camera access entry for Processing to the TCC database INSERT INTO access (service, client, client_type, allowed, prompt_count) VALUES ('kTCCServiceCamera','org.processing.app',0,1,0);

7) TEST - open processing & check camera access - also you can test that Processing shows up in SystemPrefs/privacy/camera

8) If success quit sqlite - ctrl-d

9) Turn SIP back on (REVERSE of STEP 1 - restart back into safe mode) but instead run csrutil enable

10) After restart you may need to re-install Processing.app. It kept crashing, re-installing fixed it

Hope it helps some.