Reputation: 11
I have to reflect and mirror the half of the left video with the right one. I tried this code but when I activate the effect the video shows only the first frame and does not play. The video freezes and i hear the sound. How can I play the video with the effect? thanks!
import processing.video.*;
boolean flipVideo = false;
Movie movie;
PGraphics flippedBuffer; // PGraphics buffer for the flipped video
PImage leftHalf;
void setup() {
size(640, 480);
frameRate(30);
movie = new Movie(this, "movie.mov");
movie.loop();
movie.read();
flippedBuffer = createGraphics(movie.width, movie.height); // Initialize the buffer
}
void draw() {
if (movie.available() && overlay.available()) {
movie.read();
}
movie.loadPixels();
// Create the flipped video and store it in the PGraphics buffer
if (flipVideo) {
flippedBuffer.beginDraw();
leftHalf = get(0, 0, width/2, height);
flippedBuffer.translate(width, 0);
flippedBuffer.scale(-1, 1);
flippedBuffer.image(leftHalf, 0, 0);
flippedBuffer.endDraw();
} else {
flippedBuffer.beginDraw();
flippedBuffer.image(movie, 0, 0); // Use the original video
flippedBuffer.endDraw();
}
}
void movieEvent(Movie m) {
m.read();
}
void addTuioObject(TuioObject tobj) {
...
}
void removeTuioObject(TuioObject tobj) {
...
}
Upvotes: 0
Views: 58
Reputation: 2713
The following source code will play the same movie side by side with the right movie a mirror image of the left. Movie dimension was 480 x 270; adjust code accordingly if you test some other size.
import processing.video.*;
Movie movie;
void setup() {
size(960, 270); // width should be twice movie width
movie = new Movie(this, "xxxx.mp4"); // file in 'data' sketch folder
movie.loop(); // Use play() to play just once.
}
void movieEvent(Movie movie) {
movie.read(); // Read new frames from the movie.
}
void draw() {
image(movie, 0, 0); // Display side by side
image(movie, width/2, 0);
// mirror image
pushMatrix(); // so nothing else is affected
scale(-1, 1);
image(movie, -480, 0); // movie width = 480
popMatrix();
}
Upvotes: 1