简体   繁体   English

Gstreamer命令行管道到C++代码

[英]Gstreamer command line pipeline to C++ code

I have a gstreamer pipeline that works in the command line and I am trying to convert it to C++ code.我有一个在命令行中工作的 gstreamer 管道,我正在尝试将其转换为 C++ 代码。 I have most of it, except I need to be able to write the -e flag in C++ but I'm not sure how to add it to the pipeline.我有大部分,除了我需要能够在 C++ 中写入 -e 标志,但我不知道如何将它添加到管道中。 Here is the command line这是命令行

gst-launch-1.0 -e udpsrc port=8000 ! application/x-rtp, encoding-name=H264, payload=109 ! tee name=t t. ! rtph264depay ! h264parse ! queue ! avdec_h264 ! videoconvert ! autovideosink t. ! rtph264depay ! h264parse ! queue ! mp4mux ! filesink location=!/camera.mp4"

Here is the C++ code I have.这是我拥有的 C++ 代码。 This works to display a live stream from a camera and write a mp4 file, however it is not readable.这可以显示来自摄像机的实时 stream 并写入 mp4 文件,但它不可读。 The -e flag makes the file able to be played. -e 标志使文件能够被播放。

// [1] Create Elements
pipeline = gst_pipeline_new("xvoverlay");
src = gst_element_factory_make("udpsrc", NULL);
caps = gst_element_factory_make("capsfilter", NULL);
tee = gst_element_factory_make("tee", "tee");

// Display
rtpDepay = gst_element_factory_make("rtph264depay", NULL);
h264Parse = gst_element_factory_make("h264parse", NULL);
displayQueue = gst_element_factory_make("queue", NULL);
decoder = gst_element_factory_make("avdec_h264", NULL);
videoConvert = gst_element_factory_make("videoconvert", NULL);
upload = gst_element_factory_make("d3d11upload", NULL);
sink = gst_element_factory_make("d3d11videosink", NULL);

// Record
recordRtpDepay = gst_element_factory_make("rtph264depay", NULL);
recordH264Parse = gst_element_factory_make("h264parse", NULL);
recordQueue = gst_element_factory_make("queue", "save_queue");
mux = gst_element_factory_make("mp4mux", NULL);
filesink = gst_element_factory_make("filesink", NULL);

// [2] Set element properties
g_object_set(src, "port", port, NULL);
g_object_set(caps, "caps", gst_caps_from_string("application/x-rtp, encoding-name=H264, payload=109"), NULL);
g_object_set(filesink, "location", "camera.mp4", NULL);
//g_object_set(mux, "faststart", true, NULL);

// [3] Add elements to pipeline and link together
//gst_bin_add_many(GST_BIN(pipeline), src, caps, rtpDepay, h264Parse, displayQueue, decoder, videoConvert, upload, sink, NULL);
//gst_element_link_many(src, caps, rtpDepay, h264Parse, displayQueue, decoder, videoConvert, upload, sink, NULL);
gst_bin_add_many(GST_BIN(pipeline), src, caps, tee, rtpDepay, h264Parse, displayQueue, decoder, videoConvert, upload, sink, recordRtpDepay, recordH264Parse, recordQueue, mux, filesink, NULL);
if (!gst_element_link_many(src, caps, tee, NULL)
    || !gst_element_link_many(tee, rtpDepay, h264Parse, displayQueue, decoder, videoConvert, upload, sink, NULL)
    || !gst_element_link_many(tee, recordRtpDepay, recordH264Parse, recordQueue, mux, filesink, NULL))
{
    qDebug() << "Failed to link elements";
}

How do I add a -e flag as a GstElement?如何将 -e 标志添加为 GstElement? I've searched online and I can't find anyone trying to do this programatically with that flag.我在网上搜索过,但找不到任何人试图用该标志以编程方式执行此操作。

The -e flag sends and EOS at the end of the stream. -e标志在 stream 的末尾发送和 EOS。 While processing the EOS message, the video writer will write the header information needed for the video to be playable.在处理 EOS 消息时,视频编写器将写入视频可播放所需的 header 信息。

The solution is to change the way you stop your pipeline.解决方案是改变停止管道的方式。 Instead of however you currently do it (you did not include that code), you should get access to the srcpad of your udpsrc object, and then send a GST_EVENT_EOS .而不是您当前执行此操作(您没有包含该代码),您应该访问 udpsrc object 的 srcpad,然后发送GST_EVENT_EOS This will signal to the application that you have ended the stream.这将通知应用程序您已结束 stream。 Each element will process what it needs to, and then forward that event further down the pipeline.每个元素将处理它需要的内容,然后将该事件进一步转发到管道中。 It will reach the video writer, which will then write the needed header information to your videofile, before entering a paused state.它将到达视频编写器,然后它将所需的 header 信息写入您的视频文件,然后输入暂停的 state。

On shutdown, call关机时,调用

gst_element_send_event(src, gst_event_new_eos ())

This will send EOS event downstream and write the required meta data.这将向下游发送 EOS 事件并写入所需的元数据。

it's easier to use gst_parse_launch and then gst_bin_get_by_name on elements you want to do fancy things with.使用gst_parse_launchgst_bin_get_by_name更容易在你想要做一些花哨的事情的元素上使用。

The -e flags can be given in gst_init -e 标志可以在gst_init中给出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM