We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Got video working on a Raspberry Pi 3 after I imported the GLVideo Library - however, my sketch is getting errors now. I get 2 errors both on mov.frameRate at the bottom of this code. Not sure why...
Any help much appreciated!
Errors are: Line 66 - The global variable "frameRate does not exist" Line 66 - Error on ")" Line 82 - The global variable "frameRate does not exist"
/**
* Frames
* by Andres Colubri.
*
* Moves through the video one frame at the time by using the
* arrow keys. It estimates the frame counts using the framerate
* of the movie file, so it might not be exact in some cases.
*/
import gohai.glvideo.*;
import processing.video.*;
GLMovie mov;
int newFrame = 0;
void setup() {
size(640, 360, P3D);
background(0);
// Load and set the video to play. Setting the video
// in play mode is needed so at least one frame is read
// and we can get duration, size and other information from
// the video stream.
mov = new GLMovie(this, "transit.mov");
// Pausing the video at the first frame.
mov.play();
mov.jump(0);
mov.pause();
}
void movieEvent(GLMovie m) {
m.read();
}
void draw() {
background(0);
if (mov.available()) {
mov.read();
}
image(mov, 0, 0, width, height);
text(getFrame() + " / " + (getLength() - 1), 10, 30);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
if (0 < newFrame) newFrame--;
} else if (keyCode == RIGHT) {
if (newFrame < getLength() - 1) newFrame++;
}
}
setFrame(newFrame);
}
int getFrame() {
return ceil(mov.time() * 30) - 1;
}
void setFrame(int n) {
mov.play();
// The duration of a single frame:
float frameDuration = 1.0 / mov.frameRate);
// We move to the middle of the frame by adding 0.5:
float where = (n + 0.5) * frameDuration;
// Taking into account border effects:
float diff = mov.duration() - where;
if (diff < 0) {
where += diff - 0.25 * frameDuration;
}
mov.jump(where);
mov.pause();
}
int getLength() {
return int(mov.duration() * mov.frameRate);
}
Answers
Solution is to use frameRate()