我对处理很新,所以请原谅我这是一个愚蠢的问题。 如果有以下代码:`
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;
}
}`
然而,我可以听到音乐播放,但屏幕保持黑色。有谁知道如何解决这一问题? 提前谢谢。
答案 0 :(得分:1)
你必须把
image(myVideo, 0, 0);
进入draw()
功能并从background 0;
删除setup()
。
显然,您的视频必须是程序文件夹。
请https://processing.org/reference/image_.html正确使用它。
因此,您的代码将类似于:
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;
}
}