2013-05-08 170 views
1

我試圖延遲我的活mjpeg視頻饋送10秒。MJPG Feed的視頻緩衝區延遲

我想修改此代碼,但我無法合併mjpg url。 。 它口口聲聲說 '構造CaptureMJPEG(字符串,INT,INT,INT)是未定義' 當我嘗試把URL中

原線說: 捕獲=新CaptureMJPEG(這一點,capture_xsize,capture_ysize ,capture_frames);我改變它爲: capture = new CaptureMJPEG(「http:/url.com/feed.mjpg」,capture_xsize,capture_ysize,capture_frames);

import processing.video.*; 
    import it.lilik.capturemjpeg.*; 

    Capture myCapture; 

    CaptureMJPEG capture; 
    VideoBuffer monBuff; 

    int display_xsize = 800; // display size 
    int display_ysize = 600; 

    int capture_xsize = 320; // capture size 
    int capture_ysize = 240; 

    int delay_time = 10; // delay in seconds 
    int capture_frames = 20; // capture frames per second 

    void setup() { 

     size(display_xsize,display_ysize, P3D); 

    // Warning: VideoBuffer must be initiated BEFORE capture- or movie-events start 
    monBuff = new VideoBuffer(delay_time*capture_frames, capture_xsize,capture_ysize); 
    capture = new CaptureMJPEG ("http:/url.com/feed.mjpg", capture_xsize, capture_ysize, capture_frames); 

    } 

    void captureEvent(Capture capture) { 
    capture.read(); 
    monBuff.addFrame(capture); 
    } 

    void draw() { 
     PImage bufimg = monBuff.getFrame(); 
     PImage tmpimg = createImage(bufimg.width,bufimg.height,RGB); 
     tmpimg.copy(bufimg,0,0,bufimg.width,bufimg.height,0,0,bufimg.width,bufimg.height); 
     tmpimg.resize(display_xsize,display_ysize); 
     image(tmpimg, 0, 0); 
    } 


    class VideoBuffer 
    { 
    PImage[] buffer; 

    int inputFrame = 0; 
    int outputFrame = 0; 
    int frameWidth = 0; 
    int frameHeight = 0; 

    /* 
     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++) 
     { 
     this.buffer[i] = new PImage(width, height); 
     } 
     this.inputFrame = frames - 1; 
     this.outputFrame = 0; 
     this.frameWidth = width; 
     this.frameHeight = height; 
    } 

    // return the current "playback" frame. 
    PImage getFrame() 
    { 
     int frr; 

     if(this.outputFrame>=this.buffer.length) 
     frr = 0; 
     else 
     frr = this.outputFrame; 
     return this.buffer[frr]; 
    } 

    // Add a new frame to the buffer. 
    void addFrame(PImage frame) 
    { 
     // copy the new frame into the buffer. 
     System.arraycopy(frame.pixels, 0, this.buffer[this.inputFrame].pixels, 0, this.frameWidth * this.frameHeight); 

     // advance the input and output indexes 
     this.inputFrame++; 
     this.outputFrame++; 

     // wrap the values..  
     if(this.inputFrame >= this.buffer.length) 
     { 
     this.inputFrame = 0; 
     } 
     if(this.outputFrame >= this.buffer.length) 
     { 
     this.outputFrame = 0; 
     } 
    } 
    } 

回答

0

讀取參考文檔:

https://bytebucket.org/nolith/capturemjpeg/wiki/api/index.html

這些是僅有的兩個構造函數:

CaptureMJPEG(PApplet父,字符串URL) 創建CaptureMJPEG沒有HTTP認證憑證 CaptureMJPEG (PApplet父項,字符串url,字符串用戶名,字符串密碼) 使用HTTP驗證憑證創建CaptureMJPEG

因此,第一個參數必須始終指向您的處理小程序實例。所以

capture = new CaptureMJPEG (this, "http:/url.com/feed.mjpg", capture_xsize, capture_ysize, capture_frames);