我正在尝试使实时视频馈送延迟 10 秒。我试过使用 delay(); 但这只是停止和启动代码,我需要它更多的是时间转移。我听说可以制作一系列帧的数组,然后将它们移动一定的时间,但我还没有弄清楚如何做到这一点。
我最初是在网页上工作,但我认为您很可能不能仅使用 html 来延迟实时提要(尽管这比处理更可取)
import processing.video.*;
import it.lilik.capturemjpeg.*;
CaptureMJPEG capture;
PImage next_img = null;
Capture video;
void setup() {
size(800, 800);
background(0);
capture = new CaptureMJPEG (this, "http://url.com/cam.mjpg" );
// or this if you don't need auth
// capture = new CaptureMJPEG(this, "http://mynetworkcamera.foo/image?speed=20");
capture.startCapture();
frameRate(20);
}
void draw() {
if (next_img != null) {
image(next_img, 0, 0);
}
}
void captureMJPEGEvent(PImage img) {
next_img = img;
}
编辑
我尝试根据教程并根据我从上次回复中收集的内容添加缓冲区。它运行没有任何错误,但它不会延迟视频。知道我做错了什么吗?
import processing.video.*;
import it.lilik.capturemjpeg.*;
CaptureMJPEG capture;
PImage next_img = null;
VideoBuffer vb;
Capture video;
int w = 800;
int h = 800;
int offset = 200;
void setup() {
frameRate(20);
size(800, 800);
background(0);
vb = new VideoBuffer(200, 200, h);
capture = new CaptureMJPEG (this, "http://192.168.1.83/smartcam.mjpg" );
// or this if you don't need auth
// capture = new CaptureMJPEG(this, "http://mynetworkcamera.foo/image?speed=20");
capture.startCapture();
}
void captureEvent(Capture video)
{
video.read();
video.updatePixels();
PImage blog = video.get(300, 0, 48, h);
vb.addFrame( blog );
offset++;
if (offset >= 200)
offset = 0;
}
void draw() {
int yPos = 150;
for (int i = 0; i < 27; i++)
{
image( vb.getFrame( 200 - (i * 5) + offset), i*48, yPos );
}
if (next_img != null) {
image(next_img, 0, 0);
}
}
void captureMJPEGEvent(PImage img) {
next_img = img;
}
class VideoBuffer
{
PImage[] buffer;
int inputFrame = 200;
int frameWidth = 800;
int frameHeight = 8000;
/*
parameters:
frames - the number of frames in the buffer (fps * duration)
width - the width of the video
height - the height of the video
*/
VideoBuffer( int frames, int width, int height )
{
buffer = new PImage[frames];
for (int i = 0; i < frames; i++)
{
buffer[i] = new PImage(width, height);
}
inputFrame = 200;
frameWidth = width;
frameHeight = height;
}
// return the current "playback" frame.
PImage getFrame( int frame )
{
int f = frame;
while (f >= buffer.length)
{
f -= buffer.length;
}
return buffer[f];
}
// Add a new frame to the buffer.
void addFrame( PImage frame )
{
// copy the new frame into the buffer.
arraycopy(frame.pixels, 0, buffer[inputFrame].pixels, 0, frameWidth * frameHeight);
// advance the input and output indexes
inputFrame++;
// wrap the values..
if (inputFrame >= buffer.length)
{
inputFrame = 0;
}
}
}