mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Updated Movie examples
This commit is contained in:
@@ -10,36 +10,38 @@
|
||||
import processing.video.*;
|
||||
|
||||
Movie movie;
|
||||
int newFrame = 0;
|
||||
int newFrame;
|
||||
PFont font;
|
||||
|
||||
void setup() {
|
||||
size(320, 240);
|
||||
size(320, 240, P2D);
|
||||
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.
|
||||
movie = new Movie(this, "station.mov");
|
||||
|
||||
// Pausing the video at the first frame.
|
||||
movie.play();
|
||||
movie.goToBeginning();
|
||||
movie.pause();
|
||||
|
||||
font = loadFont("DejaVuSans-24.vlw");
|
||||
textFont(font, 24);
|
||||
}
|
||||
|
||||
void movieEvent(Movie movie) {
|
||||
movie.read();
|
||||
movie.read();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (frameCount == 5) {
|
||||
// Trick to force start at frame 0...
|
||||
newFrame = 0;
|
||||
setFrame(newFrame);
|
||||
}
|
||||
|
||||
image(movie, 0, 0, width, height);
|
||||
fill(240, 20, 30);
|
||||
|
||||
text(getFrame() + " / " + (getLength() - 1), 10, 30);
|
||||
text(getFrame() + " / " + (getLength() - 1), 10, 30);
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
@@ -51,18 +53,17 @@ void keyPressed() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setFrame(newFrame);
|
||||
}
|
||||
|
||||
int getFrame() {
|
||||
return ceil(movie.time() * movie.getSourceFrameRate()) - 1;
|
||||
return ceil(movie.time() * movie.frameRate) - 1;
|
||||
}
|
||||
|
||||
void setFrame(int n) {
|
||||
movie.play();
|
||||
|
||||
float srcFramerate = movie.getSourceFrameRate();
|
||||
float srcFramerate = movie.frameRate;
|
||||
|
||||
// The duration of a single frame:
|
||||
float frameDuration = 1.0 / srcFramerate;
|
||||
@@ -82,6 +83,5 @@ void setFrame(int n) {
|
||||
}
|
||||
|
||||
int getLength() {
|
||||
return int(movie.duration() * movie.getSourceFrameRate());
|
||||
return int(movie.duration() * movie.frameRate);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import processing.video.*;
|
||||
Movie movie;
|
||||
|
||||
void setup() {
|
||||
size(640, 480);
|
||||
size(640, 480, P2D);
|
||||
background(0);
|
||||
// Load and play the video in a loop
|
||||
movie = new Movie(this, "station.mov");
|
||||
|
||||
@@ -15,7 +15,7 @@ Movie myMovie;
|
||||
color myMovieColors[];
|
||||
|
||||
void setup() {
|
||||
size(640, 480);
|
||||
size(640, 480, P2D);
|
||||
noStroke();
|
||||
background(0);
|
||||
myMovie = new Movie(this, "station.mov");
|
||||
@@ -28,22 +28,23 @@ void setup() {
|
||||
// Read new values from movie
|
||||
void movieEvent(Movie m) {
|
||||
m.read();
|
||||
m.loadPixels();
|
||||
|
||||
for (int j = 0; j < numPixels; j++) {
|
||||
for (int i = 0; i < numPixels; i++) {
|
||||
myMovieColors[j*numPixels + i] = m.get(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Display values from movie
|
||||
void draw() {
|
||||
myMovie.loadPixels();
|
||||
|
||||
for (int j = 0; j < numPixels; j++) {
|
||||
for (int i = 0; i < numPixels; i++) {
|
||||
myMovieColors[j*numPixels + i] = myMovie.get(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < numPixels; j++) {
|
||||
for (int i = 0; i < numPixels; i++) {
|
||||
fill(myMovieColors[j*numPixels + i]);
|
||||
rect(i*blockSize, j*blockSize, blockSize-1, blockSize-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ Movie myMovie;
|
||||
boolean speedSet = false;
|
||||
|
||||
void setup() {
|
||||
size(320, 240);
|
||||
size(320, 240, P2D);
|
||||
background(0);
|
||||
myMovie = new Movie(this, "balloon.ogg");
|
||||
myMovie.play();
|
||||
@@ -30,18 +30,16 @@ void movieEvent(Movie myMovie) {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (myMovie.ready()) {
|
||||
if (!speedSet) {
|
||||
// Setting the speed should be done only once,
|
||||
// this is the reason for the if statement.
|
||||
speedSet = true;
|
||||
myMovie.goToEnd();
|
||||
// -1 means backward playback at normal speed.
|
||||
myMovie.speed(-1.0);
|
||||
// Setting to play again, since the movie stop
|
||||
// playback once it reached the end.
|
||||
myMovie.play();
|
||||
}
|
||||
if (!speedSet) {
|
||||
// Setting the speed should be done only once,
|
||||
// this is the reason for the if statement.
|
||||
speedSet = true;
|
||||
myMovie.jump(myMovie.duration());
|
||||
// -1 means backward playback at normal speed.
|
||||
myMovie.speed(-1.0);
|
||||
// Setting to play again, since the movie stop
|
||||
// playback once it reached the end.
|
||||
myMovie.play();
|
||||
}
|
||||
image(myMovie, 0, 0, width, height);
|
||||
}
|
||||
@@ -11,14 +11,14 @@ import processing.video.*;
|
||||
Movie movie;
|
||||
|
||||
void setup() {
|
||||
size(640, 480);
|
||||
size(640, 480, P2D);
|
||||
background(0);
|
||||
|
||||
movie = new Movie(this, "station.mov");
|
||||
|
||||
// Pausing the video at the first frame.
|
||||
movie.play();
|
||||
movie.goToBeginning();
|
||||
movie.jump(0);
|
||||
movie.pause();
|
||||
}
|
||||
|
||||
@@ -30,10 +30,8 @@ void draw() {
|
||||
// A new time position is calculated using the current mouse location:
|
||||
float f = constrain((float)mouseX / width, 0, 1);
|
||||
float t = movie.duration() * f;
|
||||
if (movie.ready()) {
|
||||
movie.play();
|
||||
movie.jump(t);
|
||||
movie.pause();
|
||||
}
|
||||
movie.play();
|
||||
movie.jump(t);
|
||||
movie.pause();
|
||||
image(movie, 0, 0, width, height);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import processing.video.*;
|
||||
Movie movie;
|
||||
|
||||
void setup() {
|
||||
size(320, 240);
|
||||
size(320, 240, P2D);
|
||||
background(0);
|
||||
movie = new Movie(this, "balloon.ogg");
|
||||
movie.loop();
|
||||
@@ -32,4 +32,3 @@ void draw() {
|
||||
fill(240, 20, 30);
|
||||
text(nfc(newSpeed, 2) + "X", width - 80, 30);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user