gBroutin / gstreamer-java

Automatically exported from code.google.com/p/gstreamer-java
0 stars 0 forks source link

GStreamer + Java + Webcam #32

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi brothers,

     I am writing out a little application using the gstreamer-java
framework. I would like to know how to initialize gstreamer to enable
capture from my webcam (v4l2 device).

     The code below enables me to read from disk and other but I want to
capture from webcam. Thks !

        args[0]="~/films/12.Rounds.avi";
        args = Gst.init("VideoPlayer", args);
        final PlayBin playbin = new PlayBin("VideoPlayer");
        playbin.setInputFile(new File(args[0]));

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                VideoComponent videoComponent = new VideoComponent();
                playbin.setVideoSink(videoComponent.getElement());

                JFrame frame = new JFrame("VideoPlayer");
                frame.getContentPane().add(videoComponent,
BorderLayout.CENTER);
                frame.setPreferredSize(new Dimension(640, 480));
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                frame.pack();
                frame.setVisible(true);
                playbin.setState(State.PLAYING);
            }
        });
        Gst.main();
        playbin.setState(State.NULL);

Original issue reported on code.google.com by ekoj...@gmail.com on 14 Nov 2009 at 7:27

GoogleCodeExporter commented 8 years ago
Nobody to help me pls ?

Original comment by ekoj...@gmail.com on 30 Dec 2009 at 3:24

GoogleCodeExporter commented 8 years ago
I don't know whether or not you're doing a "good use" of the bug tracking 
system while 
opening that issue (a forum thread or a post over a mailing list would probably 
have 
been better received...) but, to solve this you only have to declare an Element 
grabbing v4l and add it into your pipeline :
Element videosrc = ElementFactory.make("v4l2src", "source");

Original comment by rom1dep on 14 Feb 2010 at 6:25

GoogleCodeExporter commented 8 years ago
rom1dep - you seem to be knowledgable in this, so can you please show me a 
quick sample program with this 
working? I'm having some trouble myself. This is what I have and all I'm 
getting is a black screen...

        final Pipeline pipe = new Pipeline("v4l2src");
        final Element videosrc = ElementFactory.make("v4l2src", "source");
        final Element videofilter = ElementFactory.make("capsfilter", "filter");
        videofilter.setCaps(Caps.fromString("video/x-raw-yuv, width=720, height=576"
                + ", bpp=32, depth=32, framerate=25/1"));
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                VideoComponent videoComponent = new VideoComponent();
                Element videosink = videoComponent.getElement();
                pipe.addMany(videosrc, videofilter, videosink);
                Element.linkMany(videosrc, videofilter, videosink);

                JFrame frame = new JFrame("Swing Video Test");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(videoComponent, BorderLayout.CENTER);
                videoComponent.setPreferredSize(new Dimension(720, 576));
                frame.pack();
                frame.setVisible(true);

                // Start the pipeline processing
                pipe.setState(State.PLAYING);
            }
        });

Original comment by drdaniel...@gmail.com on 18 Mar 2010 at 1:53

GoogleCodeExporter commented 8 years ago
Oh sorry I missed the first line

args = Gst.init("v4l2src", args);

Original comment by drdaniel...@gmail.com on 18 Mar 2010 at 1:57

GoogleCodeExporter commented 8 years ago
i don't have time to go into detail of this issue. but it seems nothing to do 
with 
gstreamer-java. the usual questions are:
- does it work from command line?
- does it work from native gstreamer?
- do you see the examples in test directory?
if both are yes we can look into it.

Original comment by lfar...@gmail.com on 26 Apr 2010 at 12:49

GoogleCodeExporter commented 8 years ago
Hi drdanielfrankc, I was trying to run your code and also got black screen. I 
believe gstreamer just dont know which device should use. In my case webcam 
file was not "/dev/video0", but "/dev/video2". So I've added a line 
"videosrc.set("device", "/dev/video2");" and now it works! ;) Try to run 
command line "gst-launch v4l2src device=/dev/video0 ! xvimagesink" and check if 
it works. If not try other video device files. Run "ls /dev | grep video" to 
get list of all available video devices and check it one by one.

Here is my code:

package com.test;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import org.gstreamer.*;
import org.gstreamer.swing.VideoComponent;

public class App
{

    public App() {
  }

  public static void main(String[] args) {
    Gst.init("v4l2src", args);

    final Pipeline pipe = new Pipeline("v4l2src");
        final Element videosrc = ElementFactory.make("v4l2src", "source");
        videosrc.set("device", "/dev/video2");
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                VideoComponent videoComponent = new VideoComponent();
                Element videosink = videoComponent.getElement();
                pipe.addMany(videosrc, videosink);
                Element.linkMany(videosrc, videosink);
                JFrame frame = new JFrame("Swing Video Test");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(videoComponent, BorderLayout.CENTER);
                videoComponent.setPreferredSize(new Dimension(320, 240));
                frame.pack();
                frame.setVisible(true);
                // Start the pipeline processing
                pipe.setState(State.PLAYING);
            }
        });

  }
}

I'll hope this will help You ;)

Sorry for my english ;)

Original comment by r...@poczta.onet.pl on 5 Nov 2010 at 9:56

GoogleCodeExporter commented 8 years ago
Can I make a similar thing on windows with a directshow device?

Original comment by al...@paranoici.org on 14 Nov 2011 at 4:35