全网首发:gstreamer如何接入RTSP流(IP摄像头)的代码范例

简介: 全网首发:gstreamer如何接入RTSP流(IP摄像头)的代码范例

其实也是运气好,找到了网上的代码。之后反复测试,排列组合,跟自己的代码整合起来了。


这里把有用的部分共享出来。


有朋友说跑不起来,这个时候先看看有哪些插件,参考:


https://blog.csdn.net/quantum7/article/details/84723053


//

static void on_pad_added (GstElement *element, GstPad *pad, gpointer data)
{
    GstPad *sinkpad;
    GstElement *decoder = (GstElement *) data;
    /* We can now link this pad with the rtsp-decoder sink pad */
    g_print ("Dynamic pad created, linking source/demuxer\n");
    sinkpad = gst_element_get_static_pad (decoder, "sink");
    gst_pad_link (pad, sinkpad);
    gst_object_unref (sinkpad);
}
static void cb_new_rtspsrc_pad(GstElement *element, GstPad*pad, gpointer data)
{
    gchar *name;
    GstCaps * p_caps;
    gchar * description;
    GstElement *p_rtph264depay;
    name = gst_pad_get_name(pad);
    g_print("A new pad %s was created\n", name);
    // here, you would setup a new pad link for the newly created pad
    // sooo, now find that rtph264depay is needed and link them?
    p_caps = gst_pad_get_pad_template_caps (pad);
    description = gst_caps_to_string(p_caps);
    printf("%s\n", p_caps, ", ", description,"\n");
    g_free(description);
    p_rtph264depay = GST_ELEMENT(data);
    // try to link the pads then ...
    if (!gst_element_link_pads(element, name, p_rtph264depay, "sink"))
    {
        printf("Failed to link elements 3\n");
    }
    g_free(name);
}
int main(int argc, char *argv[])
{
    /* Initialize GStreamer */
    gst_init(NULL, NULL);
    /* Build Pipeline */ 
    pipel.pipeline = gst_pipeline_new("CSDN");
    source    = gst_element_factory_make ( "rtspsrc", "source");
    g_object_set (G_OBJECT (pipel.source), "latency", 2000, NULL);
    rtppay    = gst_element_factory_make ( "rtph264depay", "depayl");
    parse     = gst_element_factory_make ( "h264parse",    "parse");
    decodebin = gst_element_factory_make ( "openh264dec",  "decode");
    sink      = gst_element_factory_make ( "d3dvideosink", "sink");
    g_object_set (G_OBJECT (pipel.sink), "sync", FALSE, NULL);
    //create_uri(url,url_size, ip_address, port);
    g_object_set(GST_OBJECT(pipel.source), "location", RTSP_SOURCE, NULL);
    //"rtsp://<ip>:554/live/ch00_0"
    //无必要
    filter1    = gst_element_factory_make("capsfilter", "filter");
    filtercaps = gst_caps_from_string("application/x-rtp");
    g_object_set (G_OBJECT (pipel.filter1), "caps", filtercaps, NULL);
    gst_caps_unref(filtercaps);
    gst_bin_add_many (GST_BIN (pipel.pipeline), source, rtppay, NULL);
    // listen for newly created pads
    g_signal_connect(source, "pad-added", G_CALLBACK(cb_new_rtspsrc_pad), rtppay);
    gst_bin_add_many (GST_BIN (pipeline), parse,NULL);
    if (!gst_element_link(rtppay, parse))
    {
        printf("\nNOPE\n");
    }
    gst_bin_add_many (GST_BIN (pipeline), decodebin, sink, NULL);
    if (!gst_element_link_many(parse, decodebin, sink, NULL))
    {
        printf("\nFailed to link parse to sink");
    }
    //不是必须 
    //g_signal_connect(rtppay, "pad-added", G_CALLBACK(on_pad_added), parse);
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    GstBus* bus = gst_element_get_bus(pipeline);
    GstMessage* msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
    if (msg != NULL)
    {
        gst_message_unref(msg);
    }
    gst_object_unref (bus);
    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(pipeline);
}


目录
相关文章
|
编解码 算法 Ubuntu
Gstreamer 硬解码Rtsp流及代码实现
Gstreamer 硬解码Rtsp流及代码实现
全网首发:gstreamer如何接入RTSP流(IP摄像头)的代码范例
全网首发:gstreamer如何接入RTSP流(IP摄像头)的代码范例
1088 0
|
计算机视觉 Python
Jetson 学习笔记(六):cv2调用CSI摄像头(jetson nx/nano)、打开海康摄像头、打开电脑摄像头
这篇文章介绍了在不同平台上接入并显示摄像头视频流的方法,包括海康摄像头的RTSP连接、电脑内置摄像头的直接读取、Jetson NX/Nano通过CSI接口和USB接口的操作,以及Jetson Nano通过Gstreamer管道和jetcam库的使用,并提供了相应的代码示例。
1405 1
|
Ubuntu 开发工具 计算机视觉
RK3588 RGA 图像操作
RK3588 RGA 图像操作
|
网络协议 Linux
音视频学习之rtsp推拉流学习2(流媒体服务器ZLMediaKit)
音视频学习之rtsp推拉流学习2(流媒体服务器ZLMediaKit)
2735 0
|
网络协议 C++ iOS开发
C++项目实战-UDP服务器
C++项目实战-UDP服务器
334 0
|
5月前
|
监控 Linux 调度
【赵渝强老师】Docker容器的资源管理机制
本文介绍了Linux CGroup技术及其在Docker资源管理中的应用。通过实例演示了如何利用CGroup限制应用程序的CPU、内存和I/O带宽使用,实现系统资源的精细化控制,帮助理解Docker底层资源限制机制。
569 6
|
监控 Java Linux
Jetson 学习笔记(十二):CSI摄像头实现rtsp流的传输并对动态获取多路流进行探索
本文是关于如何在Jetson设备上使用CSI摄像头实现RTSP流传输的详细教程,包括安装依赖、编译gst-rtsp-server、测试、源代码介绍以及如何动态获取多路流的RTSP服务器。
1392 2
Jetson 学习笔记(十二):CSI摄像头实现rtsp流的传输并对动态获取多路流进行探索
|
应用服务中间件 Linux nginx
FFmpeg学习笔记(一):实现rtsp推流rtmp以及ffplay完成拉流操作
这篇博客介绍了如何使用FFmpeg实现RTSP推流到RTMP服务器,并使用ffplay进行拉流操作,包括在Windows和Linux系统下的命令示例,以及如何通过HTML页面显示视频流。
3735 0

热门文章

最新文章