how can I connect "qtdemux" and "ffdec_h264" using c code with Gstreamer ?
demux= gst_element_factory_make("qtdemux", "demux");
dec = gst_element_factory_make ("ffdec_h264", "dec");
I believe you are using 0.10.x? Gst 1.x doesn't have ffmpeg elements.
Here are the steps:
You will have to attach a callback to "pad-added" signal of the qtdemux.
The callback will be invoked from the qtdemux for every stream
(eg. audio,video) present in the source.
The pad connection will have to be done inside the callback.
Go to page 32 on
https://lzy-s-prct.googlecode.com/files/gstreamer-manual.pdf
for the example.
Related
I am running below gstreamer command for live streaming:
gst-launch-1.0 imxv4l2videosrc device=/dev/video0 fps-n=30 imx-capture-mode=0 ! textoverlay name=overlay text=\"Overlay text here\" valignment=top halignment=left font-desc=\"Sans, 22\"! gdkpixbufoverlay name=imageoverlay location=/home/user/LZ_50/CamOverlay.png ! imxg2dvideotransform ! imxg2dvideosink framebuffer=/dev/fb1 use-vsync=true sync=false"
I want to change the text overlay dynamic in the GStreamer pipeline.
How can I get the pipeline object pointer to change the text overlay dynamic?
Thank
I had written an application but I have an issue with crashing the application using the GStreamer pipeline with overlay image & text.
Finally got the issue of crashing the application.more detail can be found at : imx Gstreamer plugins .
This also helps to reduce CPU usage(almost 20% 1 core).
I am using Qt Creator 4.5.2 (Qt 5.9.5, GCC 7.3.0 64-bit) and running on Ubuntu 18.04 I am just trying to get live video stream from a IP camera. I used 'QGraphicsView', 'QGraphicsScene', 'QGraphicsVideoItem' and QMediaPlayer methods.
Right now, the video streaming source is a IP camera and I am using 'QMediaPlayer' with 'RTSP' to get the live video and it works. However, for performance and other reasons, I need to change to gstreamer type command, like 'gst-launch-1.0', to get the live video. I am having trouble to get the correct 'gst pipe' string. Need helps.
In the document for 'QMediaPlayer', it states: Since Qt 5.12.2, the url scheme gst-pipeline provides custom pipelines for the GStreamer backend.
My version is 5.9.5 so I think the GStreamer type command should work.
Related Code and comments:
// Setup GraphicsScene
mpView = ui->gvCam;
mpView->setVisible(true);
mpScene = new QGraphicsScene;
mpView->setScene(mpScene);
mpScene->setSceneRect(0, 0, mpView->width(), mpView->height());
mpView->setSceneRect(QRectF());
// Setup IP camera
mpPlayer1 = new QMediaPlayer;
mpVideoItem1 = new QGraphicsVideoItem;
mpPlayer1->setVideoOutput(mpVideoItem1);
//The following line works and I got the live stream.
mpPlayer1->setMedia(QUrl("rtsp://20.0.2.118:8554/0"));
//However, I need to use GST type command, like:
//gst-launch-1.0 rtspsrc location=rtsp://20.0.2.118:8554/0 ! decodebin ! videoscale \
! 'video/x-raw, width=480, height=270, format=I420' \
! xvimagesink sync=false force-aspect-ratio=false;
//The above GST command worked if I issued from the terminal and I got the live stream.
//But, I don't know how to put it as a 'gst pipeline' string as a parameter for 'setMedia' call.
mpScene->addItem(mpVideoItem1);
QSizeF qf1(mpView->width(), mpView->height());
mpVideoItem1->setSize(qf1);
mpVideoItem1->setAspectRatioMode(Qt::IgnoreAspectRatio);
mpPlayer1->play();
If your Qt version is prior to 5.12.2 then a custom pipeline won't work with QMediaPlayer, because playbin is used instead.
UPDATE::
I want to stream video data (H264) through RTSP in Gstreamer.
gst_rtsp_media_factory_set_launch (factory, "videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 ");
I want "videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96" this pipeline would also be in C programming in place of direct command.
Actually I have custom pipeline, i want to pass this pipeline to GstRTSPMediaFactory.
With launch i am not able to pass my pipline.
source = gst_element_factory_make("videotestsrc", "test-source");
parse = gst_element_factory_make("x264enc", "parse");
sink = gst_element_factory_make("rtph264pay", "sink");
gst_bin_add_many(GST_BIN(pipeline), source, parse, sink, NULL);
gst_element_link_many(source, parse, sink, NULL);
Now, I want to stream this pipeline using RTSP. I can stream with gst_rtsp_media_factory_set_launch,
But i want to pass only pipeline variable, and has to stream the video.
Can it possible, if so How?
I Modified the rtsp-media-factory.c as follows,
Added GstElement *pipeline in struct _GstRTSPMediaFactoryPrivate.
And the Added two more functions get_pipeline & set pipeline
void
gst_rtsp_media_factory_set_launch_pipeline (GstRTSPMediaFactory * factory, GstElement *pipeline)
{
g_print("PRASANTH :: SET LAUNCH PIPELINE\n");
GstRTSPMediaFactoryPrivate *priv;
g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
g_return_if_fail (pipeline != NULL);
priv = factory->priv;
GST_RTSP_MEDIA_FACTORY_LOCK (factory);
// g_free (priv->launch);
priv->pipeline = pipeline;
Bin = priv->pipeline;
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
}
In the Same way get also.
And at last in place of gst_parse_launch in function default_create_element,
added this line
element = priv->pipeline; // priv is of type GstRTSPMediaFactoryPrivate
return element;
but I am not able to receive the data.
When i put pay0 for rtpmp2pay it is working.
But it is working for once only. If Client stops and again starts its not working. To work it, again i am restarting the server.
What is the problem?
** (rtsp_server:4292): CRITICAL **: gst_rtsp_media_new: assertion 'GST_IS_ELEMENT (element)' failed
To have some answer here.
It solves the main problem according to comments discussion, but there is still problem with requesting another stream (when stopping and starting client).
The solution was to add proper name for payloader element as stated in docs:
The pipeline description should contain elements named payN, one for each
stream (ex. pay0, pay1, ...). Also, for increased compatibility each stream
should have a different payload type which can be configured on the payloader.
So this has to be changed to:
sink = gst_element_factory_make("rtph264pay", "pay0");
notice the change in name of element from sink -> pay0.
For the stopping client issue I would check if this works for parse version.
If yes then check if the parse pipeline string (in original source code of rtsp server) is saved anywhere and reused after restart.. you need to debug this.
I am new using g streamer, and i try to use the emit-stats properties in tsdemux
How can I do to use this in my pipeline?
I'm trying to get the program clock reference value of a signal transport stream but no way to get it.
Properties in GStreamer are normally accessed by using the normal GLib APIs : g_object_set and g_object_get. Doing g_object_set (v1_demux, "emit-stats", TRUE, NULL);, supposing that v1_demux is a GstTSDemux*, will start emitting messages containing the PTS and DTS of the packets that flow into the demuxer.
Element messages in GStreamer are emitted by gst_element_post_message. In order to receive them in your application, it needs to set up a bus watch on the main pipeline's GstBus.
Just for the record, you can test how the property works and see the content of the messages by running this example pipeline in gst-launch :
gst-launch-1.0 -m filesrc location="$YOUR_TRANSPORT_STREAM" ! tsdemux emit-stats=1 ! fakesink
Running this with one of the transport streams on my HDD, I can see messages with the PTS and DTS being emitted from the demuxer element :
Got message #77 from element "tsdemux0" (element): tsdemux, pid=(uint)1803, offset=(guint64)266020, pts=(guint64)8429319339;
Got message #78 from element "tsdemux0" (element): tsdemux, pid=(uint)1805, offset=(guint64)273540, pts=(guint64)8429311261;
Got message #79 from element "tsdemux0" (element): tsdemux, pid=(uint)1802, offset=(guint64)282564, dts=(guint64)8429444461;
However, it doesn't look like PCR and OPCR values are emitted. You'll have to add this functionality yourself.
Thanks for the info.
was test commands and see the script and check the values, but is costing me add messages emit-stats in my line.
If I created a bus watch on the main pipeline's GstBus,to see the video duration and as playtime in my line, but can not see messages stats and video simultaneously. I still investigating comohacerlo as storing information pts and dts in some way.
My idea is get stamps of two videos and subtract this to calculate an automatic offset in one video.
I'm looking for the correct technique, if one exists, for dynamically replacing an element in a running gstreamer pipeline. I have a gstreamer based c++ app and the pipeline it creates looks like this (using gst-launch syntax) :
souphttpsrc location="http://localhost/local.ts" ! mpegtsdemux name=d ! queue ! mpeg2dec ! xvimagesink d. ! queue ! a52dec ! pulsesink
During the middle of playback (i.e. GST_STATE_PLAYING is the pipeline state and the user is happily watching video), I need to remove souphttpsrc from the pipeline and create a new souphttpsrc, or even a new neonhttpsource, and then immediately add that back into the pipeline and continue playback of the same uri source stream at the same time position where playback was before we performed this operation. The user might see a small delay and that is fine.
We've barely figured out how to remove and replace the source, and we need more understanding. Here's our best attempt thus far:
gst_element_unlink(source, demuxer);
gst_element_set_state(source, GST_STATE_NULL);
gst_bin_remove(GST_BIN(pipeline), source);
source = gst_element_factory_make("souphttpsrc", "src");
g_object_set(G_OBJECT(source), "location", url, NULL);
gst_bin_add(GST_BIN(pipeline), source);
gst_element_link(source, demuxer);
gst_element_sync_state_with_parent(source);
This doesn't work perfectly because the source is playing back from the beginning and the rest of the pipeline is waiting for the correct timestamped buffers (I assume) because after several seconds, playback picks back up. I tried seeking the source in multiple ways but nothing has worked.
I need to know the correct way to do this. It would be nice to know a general technique, if one exists, as well, in case we wanted to dynamically replace the decoder or some other element.
thanks
I think this may be what you are looking for:
http://cgit.freedesktop.org/gstreamer/gstreamer/tree/docs/design/part-block.txt
(starting at line 115)