如何从 gstreamer 服务器流式传输 4k rtsp url

问题描述 投票:0回答:0

我正在尝试构建一个流式传输 4k rtsp url 链接的简单服务器,我有 2 个服务器 这个为我创建 rtsp 链接和流媒体,一个高清秒 4k

int run(int argc, char* argv[])
{
    gst_init(&argc, &argv);

    GMainLoop* loop = g_main_loop_new(NULL, FALSE);

    GstRTSPServer* server = gst_rtsp_server_new();
    GstRTSPMountPoints* mounts = gst_rtsp_server_get_mount_points(server);

    std::string directory = videoLocation();
    
    std::string video_path = directory + std::string("/4k.mp4");
    std::string pipeline_str = "filesrc location=" + video_path + " ! qtdemux ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! h264parse ! rtph264pay name=pay0 pt=96";
    GstRTSPMediaFactory* stream4K = gst_rtsp_media_factory_new();
    gst_rtsp_media_factory_set_launch(stream4K, pipeline_str.c_str());
    gst_rtsp_mount_points_add_factory(mounts, "/fourk", stream4K);

    video_path = directory + std::string("/hd.mp4");
    pipeline_str = "filesrc location=" + video_path + " ! qtdemux ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! h264parse ! rtph264pay name=pay0 pt=96";
    GstRTSPMediaFactory* streamHD = gst_rtsp_media_factory_new();
    gst_rtsp_media_factory_set_launch(streamHD, pipeline_str.c_str());
    gst_rtsp_mount_points_add_factory(mounts, "/hd", streamHD);

    gst_rtsp_server_attach(server, NULL);


    g_print("RTSP server running at rtsp://127.0.0.1:8554/fourk\n");
    g_print("RTSP server running at rtsp://127.0.0.1:8554/hd\n");

    g_main_loop_run(loop);

    g_object_unref(mounts);
    g_object_unref(stream4K);
    g_object_unref(streamHD);
    g_main_loop_unref(loop);
    g_object_unref(server);

    return 0;
}

服务器正在工作并在 vlc 播放器上播放两个视频

然后我有第二台服务器正在流式传输这些链接:

int main(int argc, char* argv[])
{
    gst_debug_set_default_threshold(GST_LEVEL_INFO);
    gst_init(&argc, &argv);
    GstRTSPMediaFactory* m_factory;
    GMainLoop* m_loop;
    m_loop = g_main_loop_new(NULL, FALSE);
    GstRTSPServer* m_server;
    GstRTSPMountPoints* m_mounts;
    m_server = gst_rtsp_server_new();

    g_object_set(m_server, "address", "127.0.0.1", NULL);
    g_object_set(m_server, "service", "6060", NULL);

    std::string m_pipeline_str = "rtspsrc location =rtsp://127.0.0.1:8554/fourk ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! algo name=algo enabled=true ! videoconvert ! nvh264enc ! rtph264pay name=pay0 pt=96";

    //std::string m_pipeline_str = "rtspsrc location =rtsp://127.0.0.1:8554/hd ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! algo name=algo enabled=true ! videoconvert ! nvh264enc ! rtph264pay name=pay0 pt=96";

    m_mounts = gst_rtsp_server_get_mount_points(m_server);

    m_factory = gst_rtsp_media_factory_new();

    gst_rtsp_media_factory_set_launch(m_factory, m_pipeline_str.c_str());
    //g_signal_connect(m_factory, "media-configure", G_CALLBACK(on_media_configure), this);
    //gst_rtsp_media_factory_set_latency(m_factory, 10000);

    gst_rtsp_mount_points_add_factory(m_mounts, "/stream", m_factory);

    int serverID = gst_rtsp_server_attach(m_server, NULL);

    g_print("RTSP server running at rtsp://%s:%d%s\n", gst_rtsp_server_get_address(m_server), gst_rtsp_server_get_bound_port(m_server), "/stream");

    g_main_loop_run(m_loop);

    g_object_unref(m_mounts);
    g_object_unref(m_server);
    g_source_remove(serverID);
}

所以情况:

rtspsrc location =rtsp://127.0.0.1:8554/hd ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! algo name=algo enabled=true ! videoconvert ! nvh264enc ! rtph264pay name=pay0 pt=96
;正常工作 在 vlc

rtspsrc location =rtsp://127.0.0.1:8554/fourk ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! algo name=algo enabled=true ! videoconvert ! nvh264enc ! rtph264pay name=pay0 pt=96
在 vlc 中不工作

我虽然我创建的插件可能是问题所以我在 cmd 中测试:

gst-launch-1.0 rtspsrc location =rtsp://127.0.0.1:8554/fourk ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! algo name=algo enabled=true ! videoconvert ! autovideosink
它完美地工作, 我可以问一下为什么服务器拒绝将 4k 流式传输到 vlc 播放器吗?

我正在使用 Windows,视觉 2022

我试过多个插件,改变延迟,改变视频

c++ server streaming gstreamer rtsp
© www.soinside.com 2019 - 2024. All rights reserved.