Skip to main content

How to fix "Internal data stream error" in Processing 4

IntroductionError

TheIn firstProcessing program4, mostyou peoplewill writesee this error often BaseSrc: [avfvideosrc0] : Internal data stream error when learningusing the video library with cameras and a newMAC. programmingTo languagesee ismore one form or another ofabout the infamouscapture function, please see "Hello, World!"here.

Preparation

What you'll needHow to know

fix (12/2024)

To followChange this tutorialline youcam should= 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 familiarinitialized withdirectly the basics of the command-line (also known as Terminal on OS X or Command Prompt on Windows). Below are some resources that will help you get up to speed on this topic:

  • Code Academy short course - Code Academy provide a short course on command line. It hasusing an interactive// prompt in the browser so you can get to grips with the syntax before diving into the CLI.

  • An introduction to Unix and Shell - The Interactive Telecommunications Program at NYU has a very interesting introduction to Unix, which is the precursor and model for Android, Apple iOS, Raspbian (Raspberry Pi), Linux and OSx operating systems. It is also a good overview of the history, philosophy and the anatomy of the shell.

Install NodeJS

You will need to download and install NodeJS. Download the installer for your particular operating system (OSX, Windows or Linux)element from the NodeJSarray websitereturned 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 followis faster when just drawing the instructions.

image

To// testwithout ifany NodeJSadditional hasresizing, been installed successfully:

  1. Open a command line prompt (Terminaltransformations, or Commandtint. Prompt)
  2. //set(0,
  3. And0, typecam); the following: $ node -v

Do not type the `$`. This just tells you that everything following the dollar is a single line in the command line prompt.

You should see the version of NodeJS that you installed. Something like: v4.4.7. If you see an error then you may need to downloading and installing again.

Install other software (optional)

We recommend installing and using Atom text editor, because it is free, cross-platform and good for beginners to advanced programmers.

You will be editing JavaScript files throughout this tutorial, which can be done with almost *any* simple text editor you happen to have on your computer. This excludes Microsoft's Word, Apple's Pages or other word processing software, which don't count as simple and will add other unseen characters to your file.

Tutorial

To create and execute our first NodeJS application we simply (1) create a text file with the .js suffix, (2) edit the file and add some JavaScript and (3) pass this file to NodeJS using the command-line prompt.

(1) Create a directory and file

Our goal is to create a directory called hello-world and within it a file called hello.js. You can create a directory and a file using many methods but below are the instructions and an animation of how this is done using the command line.

$ cd Desktop
$ mkdir hello-world
$ cd hello-world
$ touch hello.js}


The commands above explained:

  • cd [directory-name] - Change the current directory you are in
  • mkdir [directory-name] - Make a new directory in your current location
  • touch [file-name] - Create an empty file

nodejs1-terminal.gif

The result of this should be a directory and file on your desktop in this structure:

Desktop/
   └── hello-world/
      └── hello.js

(2) Edit file and add JavaScript

  • Open the file hello.js in your preferred text editor
  • Add the following code to the top of the file and save:
console.log("Hello, world of NodeJS!");

(3) Execute our hello.js script using NodeJS

  • Open a command-line prompt
  • Change directory so that you are inside Desktop/hello-world/
$ cd ~/Desktop/hello-world

TIP: When changing directory with the `cd` command (or using any command for that matter) you can use the tilde (`~`) to navigate to your home directory. e.g. `cd ~/Desktop`

- Pass your `hello.js` script to the `node` command ``` $ node hello.js ``` You should see the "Hello, world of NodeJS!" message printed out into your CLI prompt.

Below is an animation of this step.

Execute node script