Capture doesn't work ! (mac M1)

Hello,

I’m trying to use my camera with Capture for the first time and I got some issues… I’m on a MacBook Pro with the M1 chip.
I’ve downloaded the “Video Library for Processing 4” developed by The Processing Foundation and based on GStreamer.

I’m trying to run the most basic example of code:

import processing.video.*;
Capture cam;

void setup() {
  size(640,480);
  background(200,0,0);
  
  String[] cameras = Capture.list();
  cam = new Capture(this,cameras[0]);
  cam.start();
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  image(cam, 0, 0);
}

And every time I run it, or another one, I got this error:

(Processing core video:9266): GStreamer-CRITICAL **: 18:23:28.932: gst_bin_add_many: assertion 'GST_IS_ELEMENT (element_1)' failed
(Processing core video:9266): GStreamer-CRITICAL **: 18:23:28.945: gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (dest)' failed

and sometimes:

Could not run the sketch (Target VM failed to initialize).
For more information, read Help → Troubleshooting.

Sometimes it gets even worse and Java crashes, then I got an error report.
I’ve updated Java, and even downloaded GStreamer from the official website, but I still get this error.
I tried to debug it with printing things to know what could go wrong, and the error seems to appear by the line:

cam = new Capture(this,cameras[0]);

So I guess that’s here we load the camera informations, but I still couldn’t fix the issue since I don’t find any answers on the web…

I thought the issue was about the mac built-in camera, but I also tried with another USB-logitech-camera and it still doesn’t work.

Could you help me please ?

Here is the full message from the terminal when Java crashes:

Processing video library using bundled GStreamer 1.20.3
Scanning GStreamer plugins... Done.

(Processing core video:9619): GStreamer-CRITICAL **: 18:47:33.725: gst_bin_add_many: assertion 'GST_IS_ELEMENT (element_1)' failed
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000147b8a944, pid=9619, tid=66835
#
# JRE version: OpenJDK Runtime Environment Temurin-17.0.2+8 (17.0.2+8) (build 17.0.2+8)
# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (17.0.2+8, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64)
# Problematic frame:
# C  [libgstreamer-1.0.0.dylib+0x9e944]  gst_element_link_pads_full+0x74
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /var/folders/5p/fnpzzwjs79g1jdt8bb32xbbc0000gn/T//hs_err_pid9619.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Could not run the sketch (Target VM failed to initialize).
For more information, read Help → Troubleshooting.

I have also had this issue on my M1 laptop.

Exactly the same GStreamer-CRITICAL error, and sometimes also the full VM crash too.

I have filed an issue on the Processing4 repository. Not much to add except that I could run the same code no problem on an Intel Mac so the problem seems specific to Apple Silicon.

1 Like

Just saw the following workaround suggested on the Github issue.

cam = new Capture(this, 640, 480, "pipeline:avfvideosrc device-index=0 ! video/x-raw, width=640, height=480, framerate=30/1");

This worked for me on macOS 12.5.1 (Monterey) on an M1 Macbook Pro.

1 Like

Amazing! It worked, thanks.