Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 延迟MJPEG流10秒_Java_Html_Processing_Mjpeg - Fatal编程技术网

Java 延迟MJPEG流10秒

Java 延迟MJPEG流10秒,java,html,processing,mjpeg,Java,Html,Processing,Mjpeg,我正在尝试使实时视频馈送延迟10秒。我试过使用delay();但这只是停止和启动代码,我需要它更多的是一个时间转移。我听说可以制作一个帧序列的数组,然后将它们移动一定的时间,但我还没有想出如何做到这一点 我最初是在一个网页上工作的,但我想你很可能不能仅仅用html来延迟一个实时提要(尽管这比处理要好得多) 编辑 我试图根据教程和我从上一次回复中收集的信息添加缓冲区。它运行时没有任何错误,但不会延迟视频。知道我做错了什么吗 import processing.video.*;

我正在尝试使实时视频馈送延迟10秒。我试过使用delay();但这只是停止和启动代码,我需要它更多的是一个时间转移。我听说可以制作一个帧序列的数组,然后将它们移动一定的时间,但我还没有想出如何做到这一点

我最初是在一个网页上工作的,但我想你很可能不能仅仅用html来延迟一个实时提要(尽管这比处理要好得多)




编辑 我试图根据教程和我从上一次回复中收集的信息添加缓冲区。它运行时没有任何错误,但不会延迟视频。知道我做错了什么吗

    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;
        }
      }
    } 
导入处理。视频。*;
导入它。lilik.capturemjpeg.*;
CaptureMJPEG捕获;
PImage next_img=null;
视频缓冲区;
捕获视频;
int w=800;
int h=800;
整数偏移=200;
无效设置(){
帧率(20);
大小(800800);
背景(0);
vb=新的视频缓冲区(200200h);
capture=新CaptureMJPEG(此http://192.168.1.83/smartcam.mjpg" );
//或者,如果您不需要auth
//capture=新CaptureMJPEG(此http://mynetworkcamera.foo/image?speed=20");
capture.startCapture();
}
无效捕获事件(捕获视频)
{
video.read();
video.updatePixels();
PImage blog=video.get(300,0,48,h);
vb.addFrame(blog);
offset++;
如果(偏移量>=200)
偏移量=0;
}
作废提款(){
int yPos=150;
对于(int i=0;i<27;i++)
{
图像(vb.getFrame(200-(i*5)+偏移量),i*48,yPos);
}
if(next_img!=null){
图像(下一个图像,0,0);
}
}
无效捕获事件(PImage img){
next_img=img;
}
类视频缓冲区
{
PImage[]缓冲区;
int inputFrame=200;
int frameWidth=800;
内部框架高度=8000;
/*
参数:
frames—缓冲区中的帧数(fps*持续时间)
宽度-视频的宽度
高度-视频的高度
*/
视频缓冲区(整数帧、整数宽度、整数高度)
{
缓冲区=新的PImage[帧];
对于(int i=0;i=buffer.length)
{
f-=缓冲区长度;
}
返回缓冲区[f];
}
//将新帧添加到缓冲区。
void addFrame(PImage frame)
{
//将新帧复制到缓冲区中。
arraycopy(frame.pixels,0,缓冲区[inputFrame]。像素,0,帧宽*帧高);
//提高投入产出指标
inputFrame++;
//包装这些值。。
if(inputFrame>=buffer.length)
{
inputFrame=0;
}
}
} 

如果以设定的速率传送帧,则添加延迟非常简单。你只需将它们以正常速度“播放”到环形缓冲区中,然后以相同的速度“传送”到另一端。延迟量随后成为缓冲区大小的函数

环形缓冲区本质上只是一个数组。它可以存储帧、字节或任何内容。您只需存储一个“front”和“back”索引。每当你把某个东西推进去时,你就推进“后退”索引。每当你把什么东西拿出来,你就走到前面去

举个简单的例子,我们假设每秒发送1帧。框架标识为A、B、C等

在最初的10秒钟里,你只需将帧推入

A -> [A]
B -> [A B]
C -> [A B C]
...
J -> [A B C D E F G H I J]
现在,数组已满。您可以从前面开始传送帧。此外,“back”必须循环并从顶部开始填充数组

K -> [K B C D E F G H I J] -> A
L -> [K L C D E F G H I J] -> B
M -> [K L M D E F G H I J] -> C
...

20 fps时,您的缓冲区将为200帧。

我尝试添加缓冲区(我在上面发布了更新的代码),但它似乎没有将视频馈送延迟10秒。据我所知,您应该更改
captureMJPEGEvent
以向缓冲区添加帧,并更改
draw
以删除帧(并绘制)。看起来您已经对代码进行了一半的修改,并添加了一个新函数
captureEvent
K -> [K B C D E F G H I J] -> A
L -> [K L C D E F G H I J] -> B
M -> [K L M D E F G H I J] -> C
...