processing-video
processing-video copied to clipboard
Delay on play()
I have a sketch that plays several movies in succession; when one is finished, another is loaded and played. When a new movie is played, Processing's entire graphics pipeline appears to hang for a half-second or so. I'm doing other things when the movie starts, so this delay is obvious and pretty ugly.
This modification of the "Loop" example (you'll need transit.mov or your own movie file) reproduces the behavior; just keep moving the mouse over the window and you'll see the delay when the movie is stop()ed and play()ed every 2 seconds.
I'm using a fresh install of Processing 2.2.1, downloaded yesterday, on my Macbook Pro running 10.9.5.
import processing.video.*;
Movie movie;
void setup() {
size(640, 360);
background(0);
// Load and play the video
movie = new Movie(this, "transit.mov");
movie.play();
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
image(movie, 0, 0, width, height);
fill(0, 0, 255);
// Delay is noticeable while trying to draw this following the mouse
ellipse(mouseX, mouseY, 100, 100);
if (movie.time() >= 2) {
// Replacing the lines below with this causes no delay
//movie.jump(0);
// This also causes some delay, but not as much as below
//movie.pause();
//movie.jump(0);
//movie.play();
// This action chokes the pipeline for a half-second
movie.stop();
movie.play();
}
}
- http://forum.processing.org/two/discussion/7852/problem-with-toggling-between-multiple-videos-on-processing-2-2-1
- http://forum.processing.org/two/discussion/8109/prepare-a-second-video-to-play-without-slowing-down-the-first-video
Thanks @GoToLoop, I'll try that stuff with gstreamer. However, I consider that a workaround at best and a hack at worst. Agreed that this is still a bug?
Hmmm... I guess if we just wanna the same video restart itself we should use loop(), not play()!
But this is an issue for anyone trying to play() a movie while other things are happening in the window. The example I give could just as easily load a random movie from a set of hundreds. This doesn't just apply to successive movies, either. My sketch loops through a series of "plugins", some of which load movies, and renders to a 3D scene. The lag when a movie loads is terrible; loading the movies up-front is not sustainable.
I'm still trying to understand your approach with gstreamer; maybe we should take that to the forum thread. Your sketch works for me, but when I try to attach the endOfStream() handler to my own code, it's never called. This may because I'm working within a class, but I would expect to get an exception at least...
Loading resources, especially videos, are very slow! That's why we should preload them in advance! Yea, better go to the forums for it. My "Preloaded Clips" wasn't made w/ classes in mind! :expressionless:
Hello! I think i have a similar problem as Hobzcalvin, and i was wondering if you foun a solution for that problem! I´m working on a project that has multiple videos playing at the same time and every time a new one starts playing the rest stop for a few seconds! Could you help me out? I will leave my code here so that you can have a look!
I´ve read that i should preload all videos but i´m not sure how to go about it and i don´t now if it will actually work!
// libs: import processing.video.*;
// declarations int $winW = 1920; // window int $winH = 1080; int $margin = 20; int $celsW = 20; // numero de celulas horizontal int $celsH = 15; // numero de celulas vertical
int $celW, $celH; int $fps = 25; int $beat = 10; // tempo entre cada video!
//lista de videos String[] $videoFiles = { "1.mov", "2.mov"
};
int $frame = 0; int $vidMax; Movie[] $videos;
/*
- Main proggy */
// // SETUP: // void setup() { size(1920, 1080); background(0); frameRate($fps);
// defenir o tamanho de cada celula $celW = $winW/$celsW; $celH = $celW;
/* Init matrix / $videos = new Movie[$celsW$celsH];
$vidMax = $videoFiles.length; }
// // DRAW: // void draw() { background(0);
// show something new? if ($frame % $beat == 0) { int vid = floor(random(0, $vidMax)); int pos = floor(random(0, $videos.length));
while ($videos[pos] != null) {
pos = floor(random(0, $videos.length));
}
$videos[pos] = new Movie(this, $videoFiles[vid]);
$videos[pos].jump(0);
$videos[pos].noLoop();
$videos[pos].play();
println("loading video " + vid + " at position " + pos);
}
// read videos: for (int i = 0; i < $videos.length; i++) { if ($videos[i] != null) { if ($videos[i].time() < $videos[i].duration() - 0.1) { $videos[i].read(); int x = (i % $celsW) * $celW; int y = (i / $celsW) * ($celH+$celsH/3); // int y = (i / ($celsH+$celsH/2)) * ($celH+$celsH/2); image($videos[i], x, y, $celW, $celH); } else { $videos[i] = null; } } }
$frame++;
}
https://forum.Processing.org/two/discussion/14159/delay-when-playing-multiple-videos-at-the-same-time