我对处理非常陌生,所以请原谅我,如果这是一个愚蠢的问题。如果有以下代码:'
import processing.video.*;
Movie myVideo;
int video_width = 768;
int video_height = 576;
int video_slice_x = video_width/2;
int window_width = 1000;
int window_height = video_height;
int draw_position_x = 0;
boolean newFrame = false;
void setup() {
myVideo = new Movie(this, "B1.mov");
size(window_width, window_height, P2D);
background(0);
myVideo.loop();
}
void movieEvent(Movie myMovie) {
myMovie.read();
newFrame = true;
}
void draw() {
if (newFrame) {
loadPixels();
for (int y=0; y<window_height; y++){
int setPixelIndex = y*window_width + draw_position_x;
int getPixelIndex = y*video_width + video_slice_x;
pixels[setPixelIndex] = myVideo.pixels[getPixelIndex];
}
updatePixels();
draw_position_x++;
if (draw_position_x >= window_width) {
exit();
}
newFrame = false;
}
}`
然而,我能听到音乐播放,但屏幕保持黑色。有人知道如何解决这个问题吗?提前感谢。
你必须把
image(myVideo, 0, 0);
into draw()
function and delete background 0;
from your setup()
. Obviously, your video must be into program folder. Look at https://processing.org/reference/image_.html to use it properly.
因此,您的代码将类似于:
import processing.video.*;
Movie myVideo;
int video_width = 768;
int video_height = 576;
int video_slice_x = video_width/2;
int window_width = 1000;
int window_height = video_height;
int draw_position_x = 0;
boolean newFrame = false;
void setup() {
myVideo = new Movie(this, "B1.mov");
size(window_width, window_height, P2D);
myVideo.loop();
}
void movieEvent(Movie myMovie) {
myMovie.read();
newFrame = true;
}
void draw() {
image(myVideo, 0, 0);
if (newFrame) {
loadPixels();
for (int y=0; y<window_height; y++){
int setPixelIndex = y*window_width + draw_position_x;
int getPixelIndex = y*video_width + video_slice_x;
pixels[setPixelIndex] = myVideo.pixels[getPixelIndex];
}
updatePixels();
draw_position_x++;
if (draw_position_x >= window_width) {
exit();
}
newFrame = false;
}
}