我正在尝试使用Processing设置以下内容:
所以,我到目前为止的代码是这样的:
import processing.video.*;
VideoExport videoExport;
boolean recording = false;
Capture theCap;
Capture cam;
void setup() {
size(400, 300);
frameRate(30);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, cameras[3]);
cam.start();
}
println("Press R to toggle recording");
videoExport = new VideoExport(this, "video.mp4");
}
void draw() {
if (cam.available() == true) {
cam.read();
}
image(cam, 0, 0);
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
//set(0, 0, cam);
if(recording) {
videoExport.saveFrame();
}
}
void keyPressed() {
if(key == 'r' || key == 'R') {
recording = !recording;
println("Recording is " + (recording ? "ON" : "OFF"));
}
}
我已尝试过许多不同的内容,例如videoExport
,如上所示。我试过的只是通过覆盖以前的文件来保存视频,无法正确更新视频。请指教。谢谢。
答案 0 :(得分:0)
您有两个主要问题:
要解决这两个问题,您需要添加一个跟踪正在录制哪个视频索引的变量,然后使用该变量保存视频并播放以前的录制内容。
示例启动如下所示:
import processing.video.*;
VideoExport videoExport;
boolean recording = false;
Capture theCap;
Capture cam;
int index = 0;
void setup() {
size(400, 300);
frameRate(30);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, cameras[3]);
cam.start();
}
println("Press R to toggle recording");
videoExport = new VideoExport(this, "video" + index + ".mp4");
}
void draw() {
if (cam.available() == true) {
cam.read();
}
image(cam, 0, 0);
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
//set(0, 0, cam);
if (recording) {
videoExport.saveFrame();
}
}
void keyPressed() {
if (key == 'r' || key == 'R') {
recording = !recording;
println("Recording is " + (recording ? "ON" : "OFF"));
} else if (key == 'a' || key == 'A') {
index++;
videoExport = new VideoExport(this, "video" + index + ".mp4");
}
}
请注意,我所做的只是添加index
变量,然后在keyPressed()
函数中增加该变量。然后我使用该索引创建一个新的VideoExport
,因此我不会覆盖现有文件。
这样可以将每个视频保存到单独的文件中,因此,如果您还想播放前3个视频,只需播放index-3
,index-2
和index-1