gst-launch-1.0 -e rtspsrc location="rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1" ! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux ! filesink location=./Users/farshid/src/video_4_1723IPIP.mp4
I can see the video on my computer screen and the mp4 file gets created fine, which I can replay it. All is good so far.
Then I tried to port that command line (the above one) to a sample java code and get it working as a Java APP, which is not working. When I run the app, a window opens up but it's blank and a file gets created but that one is also empty (Zero bytes).
Any help would greatly be appreciated.
Thanks in advance,
Farshid
Here is the code:
public class MultiSinkExample2 {
/**
* @param args the command line arguments
*/
private static Pipeline mainPipe;
//private Logger log = LogUtils.getLogger();
/*
*setupAllElements: creates All the elements and link them together
*
*
*/
private static Pipeline setupAllElements(SimpleVideoComponent argVideoComponent){
//Create a pipeline first
Pipeline myTestPipeLine = new Pipeline("IPCamera");
//This is what I am trying to build in Java, it runs fine on the command line:
//gst-launch-1.0 -e rtspsrc location="rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1" ! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux ! filesink location=./Users/farshid/src/video_4_1723IPIP.mp4
//Creating the source
Element ipCameraSource = ElementFactory.make("rtspsrc", "ipCameraSource" );
ipCameraSource.set("location", "rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1");
//Creating the other elements
Element rtpdepay = ElementFactory.make("rtph264depay", "rtpdepay");
Element h264 = ElementFactory.make("h264parse", "h264");
Element decode = ElementFactory.make("decodebin", "decode");
Element x264 = ElementFactory.make("x264enc", "x264");
Element mux = ElementFactory.make("mp4mux", "mux");
Element fsink = ElementFactory.make("filesink", "fsink");
fsink.set("location","./IPvideoIPIP.mp4" );
//Adding all the elements
myTestPipeLine.addMany(ipCameraSource, rtpdepay, h264, decode, x264, mux, fsink, argVideoComponent.getElement());
//Link all the elements
Element.linkMany(ipCameraSource, rtpdepay, h264, decode, x264, mux, fsink, argVideoComponent.getElement());
ipCameraSource.connect(new Element.PAD_ADDED() {
//I am doing this in case the source pad is not available at start.
@Override
public void padAdded(Element element, Pad pad) {
System.out.println("New Pad " + pad.getName() + " was created");
Element.linkMany(ipCameraSource, rtpdepay, h264, decode, x264, mux, fsink, argVideoComponent.getElement());
}
});
return myTestPipeLine;
}
/*
*
* Main function
*
*/
public static void main(String[] args) {
Gst.init();
//This invokes later
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
SimpleVideoComponent vc = new SimpleVideoComponent();
mainPipe = setupAllElements(vc);
JFrame f = new JFrame("IP Camera Test");
f.add(vc);
vc.setPreferredSize(new Dimension(640, 480));
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainPipe.play();
f.setVisible(true);
f.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
System.out.println("Window is closed I am closing the Pipe!");
mainPipe.stop();
}
});
}
});
}
}
//Adding all the elements
myTestPipeLine.addMany(ipCameraSource, rtpdepay, h264, decode, x264, mux, fsink, argVideoComponent.getElement());
//Link all the elements
Element.linkMany(ipCameraSource, rtpdepay, h264, decode, x264, mux, fsink, argVideoComponent.getElement());
Bin bin = Pipeline.launch("rtspsrc location=\"rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1\" ! rtph264depay ! h264parse ! decodebin "
+ " ! tee name=t t. ! queue ! videoconvert ! autovideosink "
+ " t. ! queue ! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux! filesink location=./farshids1234.mp4 "
+" t. ! queue ! videoconvert ! videoscale ! capsfilter caps=video/x-raw,width=640,height=480 ! appsink name=appsink " , true);
All I get is a blank video box.
If I explicitly set the URI by doing :
playbin.setURI(new URI("rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1"));
and remove the :
rtspsrc location=\"rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1\" ! rtph264depay ! h264parse ! decodebin
(from the above string)
I get to see the camera displaying.
What is going on? WHat is wrong with the code below: What am I doing wrong?
Bin bin = Pipeline.launch("rtspsrc location=\"rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1\" ! rtph264depay ! h264parse ! decodebin "
+ " ! tee name=t t. ! queue ! videoconvert ! autovideosink "
+ " t. ! queue ! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux! filesink location=./farshids1234.mp4 "
+" t. ! queue ! videoconvert ! videoscale ! capsfilter caps=video/x-raw,width=640,height=480 ! appsink name=appsink " , true);
BTW, saving the video (filesink) didn't work in any of the above set up.
Thanks,
Farshid
SimpleVideoComponent vc = new SimpleVideoComponent((AppSink) bin.getElementByName("appsink"));
try{
playbin = new PlayBin("playbin");
playbin.setVideoSink(bin);
playbin.stop();
playbin.setURI(new URI("rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1"));
playbin.play();
}catch(Exception ex){
System.out.println("There was an error" + ex.getMessage());
}
If I explicitly set the URI by doing :
playbin.setURI(new URI("rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1"));
A quick related question. Do you know if there's a way to programatically determine if the pads are dynamic. Obviously gst-inspect can do it but I couldn't figure out how to do it from Java.
I used the MultiSink example and had it working by setting the URI, but my goal is to create a video server that dynamically connects and forward the stream to a UDP link. There could be many cameras that reside on the network and the user should be able to connect to any of them and get a live video or have the video saved (any format, mp4 or others) on the server. That's my ultimate goal for this project.
Bin bin = Bin.launch("tee name=t t. ! queue ! videoconvert ! autovideosink "
+ "t. ! queue ! videoconvert ! videoscale ! capsfilter caps=video/x-raw,width=640,height=480 ! appsink name=appsink"
I would like to add another sink (files ink) to it.
This is the text/string for the new sink;
! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux ! filesink location=./MultiSionkPlayBin.mp4"
I tried many different setups and it didn't work.
For example this one:
Bin bin = Bin.launch("tee name=t t. ! queue ! videoconvert ! autovideosink "
+ "t. ! queue ! videoconvert ! videoscale ! capsfilter caps=video/x-raw,width=640,height=480 ! appsink name=appsink"
+ "t. ! queue ! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux ! filesink location=./MultiSionkPlayBin.mp4", true);
What am I doing wrong?
I like to show and at the same time save the video.
This is the command line that worked for me saving the file:
/gst-launch-1.0 -e rtspsrc location="rtsp://192.168.0.92/axis-media/media.amp?videocodec=h264&camera=1" ! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux ! filesink location=./somevideo.mp4
Thanks,
Farshid
--
You received this message because you are subscribed to the Google Groups "gstreamer-java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gstreamer-jav...@googlegroups.com.
To post to this group, send email to gstream...@googlegroups.com.
Visit this group at https://groups.google.com/group/gstreamer-java.
For more options, visit https://groups.google.com/d/optout.
Bin bin = Bin.launch("tee name=t t. ! queue ! videoconvert ! autovideosink "
+" t. ! queue ! videoconvert ! videoscale ! capsfilter caps=video/x-raw,width=640,height=480 ! appsink name=appsink "
+" t. ! queue ! matroskamux ! filesink location=./MultiSinkPlayBin.mkv"
+ " t. ! queue ! matroskamux ! filesink location=./MultiSinkPlayBinCopy.mkv", true); //Over here I am trying to create a second copy of the video. It's fine and working.
Thanks for your help on this issue.
Take care,
Farshid
--
You received this message because you are subscribed to the Google Groups "gstreamer-java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gstreamer-java+unsubscribe@googlegroups.com.
To post to this group, send email to gstreamer-java@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to gstreamer-jav...@googlegroups.com.
To post to this group, send email to gstream...@googlegroups.com.