首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用GstRTSP库将GStreamer连接到VLC

使用GstRTSP库将GStreamer连接到VLC
EN

Stack Overflow用户
提问于 2019-05-31 22:41:40
回答 1查看 232关注 0票数 0

我正在尝试写一个C应用程序来连接VLC RTSP (通过RTP)流,并将帧保存为图像。我使用的是GStreamer RTSP库:https://gstreamer.freedesktop.org/documentation/gst-plugins-base-rtsp-1.0/index.html?gi-language=c

我已经写了一些简单的代码如下,但应用程序等待来自VLC的消息。我不确定这是不是一个好的联系方式,但我现在卡住了。也许我应该先向VLC发送一些东西,但我不知道该怎么做。谁可以帮助或指出一些资源/示例如何使用GStreamer RTSP?

代码语言:javascript
运行
复制
#include <gstreamer-1.0/gst/rtsp/rtsp.h>
#include <stdio.h>

int main() 
{
    GstRTSPUrl *gstUrl = NULL;
    const char* url = "rtsp://10.30.1.163:8554/test.sdp";
    if(gst_rtsp_url_parse(url, &gstUrl) == GST_RTSP_OK) {
        printf("URL PARSE");
        GstRTSPConnection *gstRTSPConnection = NULL;
        if(gst_rtsp_connection_create(gstUrl, &gstRTSPConnection) == GST_RTSP_OK) {
            printf("Connection created\n");
            GstRTSPMessage *message = NULL;
            gst_rtsp_message_new(&message);
            GstRTSPResult result = gst_rtsp_connection_connect_with_response(gstRTSPConnection, NULL, message);
            if(result == GST_RTSP_ETIMEOUT){
                printf("Timeout\n");
            } else if(result == GST_RTSP_OK) {
                printf("Connected\n");
                printf("%s\n", gst_rtsp_connection_get_ip(gstRTSPConnection));
                printf("Is tunelled: %d\n", gst_rtsp_connection_is_tunneled(gstRTSPConnection));
                gst_rtsp_connection_receive(gstRTSPConnection, message, NULL);
            }
        }
    }    

    return 0;
}
EN

回答 1

Stack Overflow用户

发布于 2019-05-31 23:08:47

好的。我会处理好的。问题是我需要先根据RTSP协议向服务器发送一些消息。下面的解决方案(带有一些转储消息):

代码语言:javascript
运行
复制
#include <gstreamer-1.0/gst/rtsp/rtsp.h>
#include <stdio.h>

int main() 
{
    GstRTSPUrl *gstUrl = NULL;
    const char* url = "rtsp://10.30.1.163:8554";
    if(gst_rtsp_url_parse(url, &gstUrl) == GST_RTSP_OK) {
        printf("URL PARSE");
        GstRTSPConnection *gstRTSPConnection = NULL;
        if(gst_rtsp_connection_create(gstUrl, &gstRTSPConnection) == GST_RTSP_OK) {
            printf("Connection created\n");
            GstRTSPMessage *message = NULL;
            gst_rtsp_message_new(&message);
            GstRTSPResult result = gst_rtsp_connection_connect_with_response(gstRTSPConnection, NULL, message);
            if(result == GST_RTSP_ETIMEOUT){
                printf("Timeout\n");
            } else if(result == GST_RTSP_OK) {
                printf("Connected\n");
                printf("%s\n", gst_rtsp_connection_get_ip(gstRTSPConnection));
                printf("Is tunelled: %d\n", gst_rtsp_connection_is_tunneled(gstRTSPConnection));

                gst_rtsp_message_new(&message);
                gst_rtsp_message_init_request(message, GST_RTSP_DESCRIBE, "rtsp://10.30.1.163:8554/test.sdp");
                gst_rtsp_message_add_header(message, GST_RTSP_HDR_CSEQ, "1");
                printf("Message Type %d", gst_rtsp_message_get_type(message));


                gst_rtsp_message_dump(message);

                if(gst_rtsp_connection_send(gstRTSPConnection, message, NULL) == GST_RTSP_OK){
                    printf("Message sent");
                }else {
                    printf("Message not sent");
                }
                gst_rtsp_connection_receive(gstRTSPConnection, message, NULL);

                gst_rtsp_message_dump(message);
            }
        }
    }    

    return 0;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56397164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档