2
I have an IP camera that uses protocol RTSP
to transmit images, the code below uses the gstreamer
to connect, grab these images and show on swing
(works just right).
I want to get the camera frames straight from the Pipeline
of gstreamer
(do not use swing), so that so I can analyze frame by frame the image.
I know you have how to save the image in a folder and then upload it, but it is not feasible for me, I would like that after the start
of Pipeline
I made a loop that captures the image (can be in byte[]
same), the problem is that I find nothing on this.
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.gstreamer.Element;
import org.gstreamer.Gst;
import org.gstreamer.Pipeline;
import org.gstreamer.State;
import org.gstreamer.swing.VideoComponent;
public class Main {
public static void main(String[] args) throws InterruptedException {
args = Gst.init("PipelineLauncher", args);
final String def = "rtspsrc location=rtsp://192.168.25.160/av0_0 latency=0 ! decodebin ! ffmpegcolorspace name=testp";
final Pipeline pipe = Pipeline.launch(def);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// Create the video component and link it in
VideoComponent videoComponent = new VideoComponent();
Element videosink = videoComponent.getElement();
pipe.add(videosink);
pipe.getElementByName("testp").link(videosink);
pipe.setState(State.PAUSED);
if (pipe.isPlaying()) {
System.out.println("Pipeline playing");
} else {
System.out.println("Pipeline not playing");
}
// Start the pipeline processing
pipe.play();
pipe.setState(State.PLAYING);
if (pipe.isPlaying()) {
System.out.println("Pipeline playing");
} else {
System.out.println("Pipeline not playing");
}
// Now create a JFrame to display the video output
JFrame frame = new JFrame("Swing Video Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(videoComponent, BorderLayout.CENTER);
videoComponent.setPreferredSize(new Dimension(800, 600));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
Gst.main();
pipe.setState(State.NULL);
}
}
You can use the 'appsink' element instead of a real Ink video. With appsink you get the frames in a callback that you register. http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-appsink.html
– thiagoss
Try this: http://www.processing.org See references and libraries.
– Airton Gaidys