【问题标题】:GStreamer: Sending string to another pipeline via UDPGStreamer:通过UDP将字符串发送到另一个管道
【发布时间】:2020-03-16 19:45:02
【问题描述】:

我在 C 语言中有一个 Gstreamer 管道,旨在通过 udp 将文件发送到接收管道。

我的发送管道与此类似:

filesrc location=X.mp4 ! decodebin ! videoconvert ! x264enc ! rtph264pay ! udpsink host=X port=5000

我的接收管道是这样的:

udpsrc port=5000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink

我的问题是我需要在每一帧中向接收管道发送一个简单的字符串。 我需要能够动态更改字符串(通过回调),并且我的接收管道需要能够解析这个字符串(也可以通过回调)。

我知道我不能使用 textoverlay,因为文本成为视频像素的一部分,显而易见的解决方案似乎是使用字幕,但是 我不知道如何动态创建字幕流
只是强调一下:我不能使用字幕文件,因为我需要能够“即时”发送字幕。

任何帮助将不胜感激。

【问题讨论】:

    标签: c gstreamer-1.0


    【解决方案1】:

    最终我设法做到了。
    以防将来对任何人有所帮助:

    在我的发件人管道中,我将探针附加到 rtph264pay src 元素:

    rtph264pay_src_pad = gst_element_get_static_pad(rtph264pay_HD, "src");
        gst_pad_add_probe (rtph264pay_src_pad, GST_PAD_PROBE_TYPE_BUFFER,
                           (GstPadProbeCallback) set_x_to_rtp_header, NULL, NULL);
        gst_object_unref (rtph264pay_src_pad);
    

    这是回调“set_x_to_rtp_header”:

    static GstPadProbeReturn set_x_to_rtp_header (GstPad          *pad,
                                                  GstPadProbeInfo *info,
                                                  gpointer         user_data)
    {
        GstBuffer *buffer;
        GstRTPBuffer rtpBuffer = GST_RTP_BUFFER_INIT;
        g_print("%s\n", __func__);
    
        buffer = GST_PAD_PROBE_INFO_BUFFER (info);
        buffer = gst_buffer_make_writable (buffer);
    
        /* Making a buffer writable can fail (for example if it
         * cannot be copied and is used more than once)
         */
        if (buffer == NULL)
            return GST_PAD_PROBE_OK;
    
        if (gst_rtp_buffer_map (buffer,GST_MAP_WRITE, &rtpBuffer)) {
    
            pthread_mutex_lock(&mutex);
            if (gst_rtp_buffer_set_extension_data(&rtpBuffer, setup_data.left_videocrop, sizeof(setup_data.left_videocrop)) != TRUE) {
                g_printerr("cannot add extension to rtp header");
            }
            pthread_mutex_unlock(&mutex);
    
            gst_rtp_buffer_unmap (&rtpBuffer);
        }
    
        return GST_PAD_PROBE_OK;
    }
    
    

    在我的接收器管道中,我将一个探测器附加到 rtph264depay 接收器元素:

     rtph264depay_sink_pad = gst_element_get_static_pad(rtph264depay_HD, "sink");
        gst_pad_add_probe (rtph264depay_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
                           (GstPadProbeCallback) get_x_from_rtp_header, videomixer, NULL);
        gst_object_unref (rtph264depay_sink_pad);
    

    这是回调“get_x_from_rtp_header”:

    static GstPadProbeReturn get_x_from_rtp_header (GstPad          *pad,
                                                    GstPadProbeInfo *info,
                                                    gpointer         user_data)
    {
        GstBuffer *buffer;
        GstRTPBuffer rtpBuffer = GST_RTP_BUFFER_INIT;
        guint16 ret_x;
        gpointer data;
        guint wordlen;
        GstElement* videomixer = (GstElement*)user_data;
        GstPad* videomixer_HD_sink_pad;
    
        g_print("%s\n", __func__);
    
        buffer = GST_PAD_PROBE_INFO_BUFFER (info);
        buffer = gst_buffer_make_writable (buffer);
    
        /* Making a buffer writable can fail (for example if it
         * cannot be copied and is used more than once)
         */
        if (buffer == NULL)
            return GST_PAD_PROBE_OK;
    
        if (gst_rtp_buffer_map (buffer,GST_MAP_READ, &rtpBuffer)) {
            //get x from the rtp header and into ret_x variable
            if (gst_rtp_buffer_get_extension_data(&rtpBuffer, &ret_x, &data, &wordlen) != TRUE) {
                return GST_PAD_PROBE_OK;
            }
    
            gst_rtp_buffer_unmap (&rtpBuffer);
        }
    
        return GST_PAD_PROBE_OK;
    }
    

    【讨论】:

    • 嗨。我有一个非常相似的问题,但是有一个我无法解决的问题。请你看看好吗? stackoverflow.com/q/60800023/6614742
    • @bronstein87 当然,我已经回答了你的问题。
    • 我可以根据 &data 变量中的值将 rtpBuffer 路由到多个应用程序接收器吗?基本上我想在同一个端口上接收来自多个发送者的 rtp 数据包,并根据这个自定义 rtp 扩展数据路由/传输到多个接收器/目的地
    猜你喜欢
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-24
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多