We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I'm getting some inconsistent behaviour with PImage.width, PImage.height, and PImage.resize() when working with Movie files. Width and height will almost always return 0, though will occasionally return the correct dimensions. PImage.resize() will sometimes throw an error: "Width(0) and Height(0) cannot be <= 0" - even when the dimensions are hardcoded in. I'm posting this here because I'm not sure whether this is a bug or I'm just doing something silly with the code:
macOS 10.12.5; Quicktime 10.4; P3.3.5
import processing.video.*;
Movie m;
PImage mS;
int vScale = 4;
int mW;
int mH;
void setup() {
size(480, 270);
m = new Movie(this, "test.mov"); // original dim: 1920 1080
m.loop();
mW = m.width;
mH = m.height;
// Almost always returns 0 for both values, but occasionally returns the correct dimensions.
println("width: " + mW +" " + "Height: " + mH);
}
void draw() {
mS = m.get();
//This almost never works
//mS.resize(mW/vScale, mH/vScale);
//This works most of the time, but not always!
//mS.resize(1920/vScale, 1080/vScale);
//Again works most of the time, but not always...
mS.resize(480, 270);
image(mS, 0, 0);
}
void movieEvent(Movie m) {
m.read();
}
Answers
IIRC the movie is played in the background so the size won't be available until the first frame has been decoded. Try ignoring the image in draw() until you get one with some dimensions.
That worked, thanks! It seems the simplest method is to just use Movie.available() instead of movieEvent - like this:
And if someone wants to use movieEvent, something like this will work: