Adding video/ file setups???
in
Core Library Questions
•
2 years ago
Hey I am a very new user to processing I want to play my own video in a sketch rather than capture.
using this code it will play audio but no video
import processing.video.*;
Movie myMovie;
void setup() {
size(600, 600);
myMovie = new Movie(this, "birthday.mov");
myMovie.play();
}
void draw() {
image(myMovie, 600, 600);
}
void movieEvent(Movie m) {
m.read();
}
I am also not sure how my folders need to be setup so that it will access the video properly. Where should the library folder be/ do I need a data folder.
If I want to loop a video within another code do I just add above before the beginning/ how do I integrate???
for example
import processing.video.*;
Movie myMovie;
void setup() {
size(200, 200);
myMovie = new Movie(this, "birthday.mov");
myMovie.loop();
}
void draw() {
image(myMovie, 0, 0);
}
void movieEvent(Movie m) {
m.read();
}
int numPixels;
int blockSize = 10;
Movie myMovie;
int myMovieColors[];
int[] previousFrame;
int TOLERANCE = 50;
boolean go = false;
boolean record = false;
int fake_frame_rate = 0;
MovieMaker mm;
void setup() {
size(626, 352, P3D);
myMovie = new Movie(this, "birthday.mov"); //put movie here
mm = new MovieMaker(this,width,height,"output3.mov", 24, MovieMaker.RAW, MovieMaker.BEST);
numPixels = width*height;
myMovieColors = new int[numPixels];
previousFrame = new int[numPixels];
//myMovie.speed(0.5);
myMovie.loop();
}
void draw() {
loadPixels();
if (!go) {
for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
pixels[i] = myMovieColors[i];
}
} else {
int movementSum = 0; // Amount of movement in the frame
for (int i = 0; i < numPixels; i++) {
color currColor = myMovieColors[i];
color prevColor = previousFrame[i];
// Extract the red, green, and blue components from current pixel
int currR = (currColor >> 16) & 0xFF;
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;
// Extract red, green, and blue components from previous pixel
int prevR = (prevColor >> 16) & 0xFF;
int prevG = (prevColor >> 8) & 0xFF;
int prevB = prevColor & 0xFF;
// Compute the difference of the red, green, and blue values
int diffR = abs(currR - prevR);
int diffG = abs(currG - prevG);
int diffB = abs(currB - prevB);
// Add these differences to the running tally
movementSum = diffR + diffG + diffB;
if (movementSum > TOLERANCE) {
// Render the difference image to the screen
pixels[i] = 0xff000000 | (prevR << 16) | (prevG << 8) | prevB;
}
// Save the current color into the 'previous' buffer
previousFrame[i] = currColor;
}
}
updatePixels();
delay(fake_frame_rate);
if (record) mm.addFrame();
}
/**
* -Space bar grabs a refernece frame and turns on and off
* the effect [the first refernece frame is all black so
* you may want to hit this a few times to get a good one].
* -hit 'r' to start recording.
* -hit 's' to stop recording.
*/
void keyPressed() {
if (key == ' ') go = !go;
else if (key == 'r') record = true;
else if (key == 's') mm.finish();
}
/**
* Read new values from movie
*/
void movieEvent(Movie m) {
if (m.available()) {
m.read();
m.loadPixels();
myMovieColors = m.pixels;
}
}
what does duplicate test field myMovie mean???
Sorry I am so basic but understanding processing is clearly not my strong suit, but I really want to give it a try.
Help Please!
Thanks
1