gpt4 book ai didi

c - GStreamer : Sending string to another pipeline via UDP

转载 作者:行者123 更新时间:2023-12-04 10:29:52 24 4
gpt4 key购买 nike

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

任何帮助将不胜感激。

最佳答案

最终我设法做到了。
如果它可以帮助将来的任何人:

在我的发件人管道中 ,我将探针附加到 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;
}

关于c - GStreamer : Sending string to another pipeline via UDP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60466760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com