2012-05-17 87 views
0

我正在使用gstreamer庫進行Java項目,需要能夠從網絡攝像頭捕獲圖像。如何從網絡攝像頭捕獲圖像WHILST也已經使用Java Gstreamer從網絡攝像頭進行流式傳輸?

我已經有顯示攝像頭流的代碼,我只是無法弄清楚如何在按下按鈕旁邊的按鈕來捕捉圖像。

我已經搜索了互聯網,但只能找到顯示流或捕獲圖像的代碼片段,但都沒有說明兩個...我試圖合併這些代碼段,但沒有'我也爲我工作。

我需要做些什麼才能使其發揮作用?

public class WebcamPanel extends JPanel { 

    private static Pipeline pipe; 

    public WebcamPanel(){ 

     String[] args = {}; 
     args = Gst.init("Webcam", args); 

     pipe = new Pipeline("pipeline"); 

     final Element videosrc = ElementFactory.make("dshowvideosrc", "source"); 
     final Element videofilter = ElementFactory.make("capsfilter", "flt"); 
     videofilter.setCaps(Caps.fromString("video/x-raw-yuv, width=320, height=240")); 

     setLayout(new GridBagLayout()); 
     final GridBagConstraints c = new GridBagConstraints(); 

     JButton takePic = new JButton(); 
     takePic.setPreferredSize(new Dimension(50,50)); 

     c.gridx = 0; 
     c.insets = new Insets(0,10,0,0); 
     add(takePic,c); 

     c.gridx = 2; 
     c.gridwidth = GridBagConstraints.REMAINDER; 
     c.insets = new Insets(0,40,0,0); 

     SwingUtilities.invokeLater(new Runnable() { 
      public void run() { 
       VideoComponent videoComponent = new VideoComponent(); 
       Element videosink = videoComponent.getElement(); 
       // This gives 2nd window with stream from webcam 
       // Element videosink = ElementFactory.make("xvimagesink", "sink"); 
       pipe.addMany(videosrc, videofilter, videosink); 
       Element.linkMany(videosrc, videofilter, videosink); 

       videoComponent.setPreferredSize(new Dimension(320, 240)); 
       add(videoComponent,c); 
       videoComponent.setVisible(true); 
       // Start the pipeline processing 
       pipe.setState(State.PLAYING); 
      } 
     }); 

    } 
} 

回答

0

你看看camerabin2嗎?這將爲您實現整個相機工作流程(取景器,圖像捕捉,視頻捕捉,效果...)。 基本方法是開啓第二流並從中捕獲選定的圖像(例如,使用valve!jpegenc!multifilesink並打開所選圖像的閥門),或使用輸出選擇器至圖像保存管道或使用緩衝探針(hacky)。