【问题标题】:How to capture image from webcam WHILST already streaming from webcam too with Java Gstreamer?如何从网络摄像头捕获图像同时已经使用 Java Gstreamer 从网络摄像头流式传输?
【发布时间】:2012-05-17 10:46:18
【问题描述】:

我正在将 gstreamer 库用于需要能够从网络摄像头捕获图像的 Java 项目。

我已经有了显示网络摄像头流的代码,只是不知道如何通过按下旁边的按钮来捕获图像。

我已经搜索了互联网,但只能找到显示流或捕获图像的代码片段,但没有一个说明两者......我试图合并这些代码片段,但没有也为我工作。

我必须做些什么才能让它工作?

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); 
            }
        });

    }
}

【问题讨论】:

    标签: java webcam gstreamer java-gstreamer


    【解决方案1】:

    你看过camerabin2吗?这将为您实现整个相机工作流程(取景器、图像捕捉、视频捕捉、效果......)。 基本方法是打开第二个流并从中捕获选定的图像(例如,使用阀门!jpegenc!multifilesink 并为选定的图像打开阀门)或使用输出选择器到图像保存管道或使用一个缓冲探针(hacky)。

    【讨论】:

      猜你喜欢
      • 2013-02-09
      • 2020-03-22
      • 1970-01-01
      • 2014-06-18
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多