Reputation: 23
I need your help for an libcamera, gstreamer and java issue.
I trie to display the libcamera video flux from a Pi Cam v3 connected to an Pi Zero 2 W to an Java JFrame on PC to order a rover. Minimal latency is the key !
I found how to do with CLI :
libcamera-vid -t 0 --nopreview --width 1280 --height 720 --framerate 60 --vflip --hflip --autofocus-mode auto --codec mjpeg -o - | gst-launch-1.0 fdsrc fd=0 ! udpsink host=192.168.5.127 port=5000
and for the receiver :
gst-launch-1.0 udpsrc port=5000 ! jpegparse ! jpegdec ! queue ! autovideosink
I have low latency like I desire. Exquisite !
!! BUT !!
Now, I have to integrate the receiver in a java app. And there ... I have a little ... tiny ... problem.
I see on my task manager network activities when I launch the app but the JFrame screen juste stay definitly black.
public class GstreamerFrame {
private static Pipeline pipeline;
private static JFrame frame;
public static void main(String[] args) {
Utils.configurePaths();
Gst.init(Version.BASELINE, "BasicPipeline");
pipeline = (Pipeline) Gst.parseLaunch("udpsrc port=5000 ! jpegparse ! jpegdec ! queue ! appsink name=sink");
AppSink sink = (AppSink) pipeline.getElementByName("sink");
GstVideoComponent vc = new GstVideoComponent(sink);
vc.setSize(1280, 720);
vc.setVisible(true);
frame = new JFrame();
frame = new JFrame("Rover console");
frame.add(vc);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(1280, 720));
frame.pack();
pipeline.play();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
frame.setVisible(true);
}
});
}
}
I tried to :
modify the code like the gstreamer-java example
change udp by tcp
use libcamera gstreamer plugin like
gst-launch-1.0 libcamerasrc ! video/x-raw,colorimetry=bt709,format=NV12,width=1280,height=720,framerate=30/1 ! queue ! jpegenc ! multipartmux ! tcpserversink host=0.0.0.0 port=5000
but nothing change
public class GstreamerFrame {
private static Pipeline pipeline;
public static void main(String[] args) {
Utils.configurePaths();
Gst.init(Version.BASELINE, "BasicPipeline");
EventQueue.invokeLater(() -> {
GstVideoComponent vc = new GstVideoComponent();
Bin bin = Gst.parseBinFromDescription("udpsrc port=5000 ! multipartdemux ! jpegdec", true);
pipeline = new Pipeline();
pipeline.addMany(bin, vc.getElement());
Pipeline.linkMany(bin, vc.getElement());
JFrame f = new JFrame("Camera Test");
f.add(vc);
vc.setPreferredSize(new Dimension(1280, 720));
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
pipeline.play();
});
}
}
I'm not really an expert in gstreamer and video streams. Can somebody have an idea on what's going in there ?
Upvotes: 0
Views: 160