FFmpeg failed error when recording multiple videos

Hi all, I have a sketch that records multiple videos using hamoid’s video export library. It automatically loads the previous video, and layers it over the current webcam feed using blend(). After recording about 11 videos, my computer’s fan starts going hard and I get this error:
‘VideoExport error: Ffmpeg failed. Study … for more details.’
‘Could not run the sketch (Target VM failed to initialize). Make sure that you haven’t set the maximum available memory too high.’

I thought this might be because the PImage object isn’t releasing its memory (info here: https://forum.processing.org/two/discussion/18762/can-t-release-pimage-memory), but I’m not getting an error that Processing is out of memory. Any thoughts?

Code below just needs one video titled ‘vid0.mp4’ to run.

import processing.video.*;
import com.hamoid.*;

//variables for counter
int currentCycle;
int lastCycle1;

//variables for webcam, movie, video export, video buffer
Capture cam;
Movie mov;
VideoExport videoExport;
PGraphics pg1;

//variable for framerate
int FPS = 10;

//variable for actively recording
boolean recording = false;

//variables for timer
int savedTime;
int totalTime = 6000;


void setup() {
  size(640, 480);
  frameRate(FPS);
  
  //start the counter
  currentCycle = 1;
  
  //init function starts the sketch
  init();
}



void draw() {
  clear();
  //start drawing PGraphics for the video
  pg1.beginDraw();
  //set PGraphics background to transparent
  pg1.background(255, 0);
  
  //wait until webcam and loaded movie are available before doing anything
  if (cam.available()) {
    cam.read();
    recording = true;
      if (mov.available()) {
        mov.read();
        mov.loadPixels();
      
        //set up timer
        int passedTime = millis() - savedTime;
        
        // Loops through every pixel of the recorded video...
        for (int x = 0; x < mov.width; x++) {
          for (int y = 0; y < mov.height; y++) {
      
            // Calculate the 1D location from a 2D grid
            int loc = x + y*mov.width;
      
            // Get the R,G,B,A values from image
            float r, g, b, a;
            r = red  (mov.pixels[loc]);
            g = green(mov.pixels[loc]);
            b = blue (mov.pixels[loc]);
            a = alpha (mov.pixels[loc]);
      
            // Calculate an amount to change brightness based on mouseX position
            float adjustbrightness = map(mouseX, 0, width, 0, 4);
            r *= adjustbrightness;
            g *= adjustbrightness;
            b *= adjustbrightness;
            a *= adjustbrightness;
      
            // Constrain RGBA to make sure they are within 0-255 color range
            r = constrain(r, 0, 255);
            g = constrain(g, 0, 255);
            b = constrain(b, 0, 255);
            a = constrain(a, 0, 255);
      
            // Make a new color and set pixel in the window
            color c = color(r, g, b, a);
            mov.pixels[loc] = c;
          }
        }
        updatePixels();
        
        //draw the movie into the PGraphics variable
        pg1.image(mov, 0, 0, width, height);
        pg1.endDraw();
      
        //Draw the camera image MIRRORED
        pushMatrix();
        scale(-1.0, 1.0);
        image(cam,-cam.width,0);
        popMatrix();
        
        blend(mov, 0, 0, width, height, 0, 0, width, height, DARKEST);
        
        //save a frame for the video export
        videoExport.saveFrame();
        
        //if the timer is up, export the movie
        if (passedTime > totalTime) {
          export();
      }
    } 
  }
}

void init() {
  
  loop();
  
  //update the counter
  currentCycle++;
  lastCycle1 = currentCycle - 1;
  println(currentCycle);

  //variable for timer
  savedTime = millis();

  //initialize Capture object
  cam = new Capture(this, width, height, FPS); 
  cam.start();
  
  //initialize VideoExport object
  videoExport = new VideoExport(this, "./data/vid" + currentCycle + ".mp4", cam);
  videoExport.setFfmpegPath("/usr/local/bin/ffmpeg");
  videoExport.startMovie();

  mov = new Movie(this, "vid" + lastCycle1 + ".mp4");
  mov.loop();
  
  //initialize PGraphics
  pg1 = createGraphics(width, height);
  
  //make the pixel array available for manipulation
  loadPixels();
}



void export() { 
    save("./img/img" + currentCycle + ".jpg");
    videoExport.endMovie();
    noLoop();
}

void keyPressed() {
  if (key == 'q') {
    init();
  }
}

I don’t necessarily have an answer for you but I do know I’ve been running into issues like that too with that library. After some point it crashes and I have to restart to program to get Video Export working again. Wondering if it’s just an issue with the lib not properly garbage collecting.

What’s your hardware like? I’m running it on a mbp mid 2015.

Same, mid-2015 MacBook Pro.
Processor: 2.8 GHz Intel Core i7
Memory: 16 GB 1600 MHz DDR3
Graphics: Intel Iris Pro 1536 MB

I was also having a crashing issue just exporting pngs, not video. I think the issue is that Processing is keeping PImages in its memory, even when they’re not being used. I tried a lot of various tips to force Java to run garbage collection, but none with any success :frowning: