How to fix "Internal data stream error" in Processing 4
Error
In Processing 4, you will see this error often BaseSrc: [avfvideosrc0] : Internal data stream error
when using the video library with cameras and a MAC. To see more about the capture function, please see here.
How to fix (12/2024)
Change this line cam = new Capture(this, cameras[0]);
to "pipeline:avfvideosrc device-index=0"
Full Code
import processing.video.*;
Capture cam;
void setup() {
size(640, 480);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, width, height, "pipeline:avfvideosrc device-index=0", 30);
cam.start();
}
}
void draw() {
if (cam.available() == true) {
cam.read();
}
image(cam, 0, 0);
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
//set(0, 0, cam);
}