/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package videoplayer.player;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.gstreamer.Caps;
import org.gstreamer.Element;
import org.gstreamer.ElementFactory;
import org.gstreamer.Gst;
import org.gstreamer.Pipeline;
import org.gstreamer.State;
import org.gstreamer.swing.VideoComponent;
/**
*
* @author duo
*/
public class WebcamPlayer {
public WebcamPlayer() {
Gst.init();
pipe = new Pipeline("VideoTest");
final Element videosrc = ElementFactory.make("v4l2src", "source");
final Element videofilter = ElementFactory.make("capsfilter", "filter");
videofilter.setCaps(Caps.fromString("dv1394src ! video/x-dv ! dvdemux ! "
+ "dvdec ! ffmpegcolorspace ! video/x-raw-rgb, width=320, height=240"
+ ", bpp=32, depth=24, 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);
// Now create a JFrame to display the video output
JFrame frame = new JFrame("Duo: webacam com gstreamer.");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(videoComponent, BorderLayout.CENTER);
//videoComponent.setPreferredSize(new Dimension(720, 576));
videoComponent.setPreferredSize(new Dimension(320, 240));
frame.pack();
frame.setVisible(true);
// Start the pipeline processing
pipe.setState(State.PLAYING);
}
});
}
private static Pipeline pipe;
public static void main(String[] args) {
new WebcamPlayer();
}
}