unmanageable CPU cost when a video is loaded using video library

edited June 2018 in Library Questions

I'm trying to do a simple think: when a button is pressed i load a video using the processing video library, each button is associated with a different video, for example button 1 with video 1, button 2 with video 2, and so on. The code works but every time I call a video, also the same i have already load, rewriting the gloabal variable the consume of CPU grows, reaching the 40% after the thrid loading, after 7 video the consume of CPU is near the 100%. An extraction of the code:

import processing.video.*;
Movie movie;
void setup() {
    size(1280, 720, P3D);
    background(0);
}
void draw() {
    //image(movie, 0, 0, width, height);

    if (but1_1==1) {
       println("video 1");
       movie = new Movie(this, "1.mp4"));
       movie.loop();
       movie.volume(0);
  }
  if (but1_2==1) {
       println("video 2");
       movie = new Movie(this, "2.mp4"));
       movie.loop();
       movie.volume(0);
  }
  if (but1_3==1) {
       println("video 3");
       movie = new Movie(this, "3.mp4"));
       movie.loop();
       movie.volume(0);
  }
}

As you can see, it should not be any reason in based on which the CPU consume grows: the instantiated object movie is always rewritten every time a new video (or the same) is loaded. Any suggestions?

Answers

  • edited June 2018

    You are using this in P3D. is this necessary? How do you display your movies?

    Also, if you execute this in draw(), shouldn't it be:

    if (but1_1==1 && !movie.isPlaying()) {
           println("video 1");
           movie = new Movie(this, "1.mp4"));
           movie.loop();
           movie.volume(0);
           but1_1=false;
    }
    

    Kf

  • edited June 2018

    If memory allows, prefer loading all of the resources a sketch is gonna need before draw() starts. L-)

    Why do you create new Movie objects after setup()? :-/
    A Movie object is 1 of the most RAM hungry objects btW, AFAIK! :-S

    Instead, create an array for them, and you pause() & resume() to pick the active 1. *-:)

  • edited June 2018

    ... it should not be any reason in based on which the CPU consume grows:

    The video library is simply a binding wrapper for GStreamer, a framework written in C: :-B
    https://en.Wikipedia.org/wiki/GStreamer

    Java's GC can't touch it! Instead, in order to actually release its hardware resources, we need to explicitly command it via method dispose(). :-$

  • And as @kfrajer already asked: Do you really need an OpenGL-based renderer for it? :-\"

  • Answer ✓

    hi to all! thanks for the answer, i solved the problem just using movie.stop(); before recall a new object! yes i need opengl because this is just a little part of the code! i use a shader to manipulate the sketch!

  • i create a movie object in the draw loop because i need to change the video a lot of time, and i have to use like 100 video, so i can't import all in the setup function, is too much memory expansive.

Sign In or Register to comment.