mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Removed jump to frame, length and frame methods from Movie, modified Frame example accordingly.
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
* by Andres Colubri
|
||||
*
|
||||
* Moves through the video one frame at the time by using the
|
||||
* arrow keys.
|
||||
* arrow keys. It estimates the frame counts using the framerate
|
||||
* of the movie file, so it might not be exact in some cases.
|
||||
*/
|
||||
|
||||
import processing.video.*;
|
||||
@@ -38,7 +39,7 @@ void draw() {
|
||||
image(movie, 0, 0, width, height);
|
||||
fill(240, 20, 30);
|
||||
|
||||
text(movie.frame() + " / " + (movie.length() - 1), 10, 30);
|
||||
text(getFrame() + " / " + (getLength() - 1), 10, 30);
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
@@ -46,11 +47,41 @@ void keyPressed() {
|
||||
if (keyCode == LEFT) {
|
||||
if (0 < newFrame) newFrame--;
|
||||
} else if (keyCode == RIGHT) {
|
||||
if (newFrame < movie.length() - 1) newFrame++;
|
||||
if (newFrame < getLength() - 1) newFrame++;
|
||||
}
|
||||
}
|
||||
|
||||
movie.play();
|
||||
movie.jump(newFrame);
|
||||
movie.pause();
|
||||
|
||||
setFrame(newFrame);
|
||||
}
|
||||
|
||||
int getFrame() {
|
||||
return ceil(movie.time() * movie.getSourceFrameRate()) - 1;
|
||||
}
|
||||
|
||||
void setFrame(int n) {
|
||||
movie.play();
|
||||
|
||||
float srcFramerate = movie.getSourceFrameRate();
|
||||
|
||||
// The duration of a single frame:
|
||||
float frameDuration = 1.0 / srcFramerate;
|
||||
|
||||
// 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 = movie.duration() - where;
|
||||
if (diff < 0) {
|
||||
where += diff - 0.25 * frameDuration;
|
||||
}
|
||||
|
||||
movie.jump(where);
|
||||
|
||||
movie.pause();
|
||||
}
|
||||
|
||||
int getLength() {
|
||||
return int(movie.duration() * movie.getSourceFrameRate());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user