I've tried to modify the Swing VideoTest example to use v4l2src as a
source. But then I only get a black window, though I can see from the
LED on my webcam that the webcam is streaming. When using videotestsrc
instead the example works. When using v4l2src and xvimagesink I get
the black Swing windows and a 2nd windows from gstreamer with the
video stream from the webcam.
From what I see setting breakpoints in VideoComponent the render()
method is never called when using v4l2src.
Maybe someone can tell me what I'm doing wrong, here is my code:
package gstreamervideo;
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;
public class Main {
private static Pipeline pipe;
public static void main(String[] args) {
args = Gst.init("SwingVideoTest", args);
pipe = new Pipeline("pipeline");
// This is from VideoTest example and gives test image
// final Element videosrc =
ElementFactory.make("videotestsrc", "source");
// This gives black window with VideoComponent
final Element videosrc = ElementFactory.make("v4l2src",
"source");
final Element videofilter = ElementFactory.make("capsfilter",
"flt");
videofilter.setCaps(Caps.fromString("video/x-raw-yuv,
width=640, height=480"));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
VideoComponent videoComponent = new VideoComponent();
// This gives only black window
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);
JFrame frame = new JFrame("Swing Video Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(videoComponent, BorderLayout.CENTER);
videoComponent.setPreferredSize(new Dimension(640,
480));
frame.pack();
frame.setVisible(true);
// Start the pipeline processing
pipe.setState(State.PLAYING);
}
});
}
}