gstreamergstreamer-1.0rtsp-server

Stream a web camera using Gst-Rtsp (GStreamer) server


I'm trying to build a Gst-RTSP Server which can stream the web camera via RTSP server of G streamer but I'm facing a error that the pipeline is not working properly. basically the pipeline doesn't seem to work.

my code

#include <gstreamer-1.0/gst/gst.h>
#include <gstreamer-1.0/gst/rtsp-server/rtsp-server.h>
#include <iostream>

static gboolean
timeout (GstRTSPServer * server)
{
  GstRTSPSessionPool *pool;

  pool = gst_rtsp_server_get_session_pool (server);
  gst_rtsp_session_pool_cleanup (pool);
  g_object_unref (pool);

  return TRUE;
}

int main(){
    gst_init(NULL, NULL);

    GstRTSPServer *server; 
    GstRTSPMediaFactory *factory; 
    GMainLoop *loop; 
    GstRTSPAddressPool *pool; 
    GstRTSPMountPoints *mounts;

    loop = g_main_loop_new(NULL, false);
    server = gst_rtsp_server_new();
    mounts = gst_rtsp_server_get_mount_points(server);
    factory = gst_rtsp_media_factory_new();

    gst_rtsp_media_factory_set_launch (factory, "(v4l2src device=/dev/video0 ! videoconvert ! video/x-raw, width=640, height=480, format=I420 ! x264enc ! rtph264pay name=pay0 pt=96)");
    gst_rtsp_media_factory_set_shared(factory, true); 

    pool = gst_rtsp_address_pool_new();
    gst_rtsp_address_pool_add_range(pool, "192.168.0.92", "192.168.0.92", 5000, 9000, 16);

    gst_rtsp_media_factory_set_address_pool(factory, pool); 
    gst_rtsp_media_factory_set_protocols (factory, GST_RTSP_LOWER_TRANS_UDP_MCAST);
    g_object_unref (pool);

    /* attach the test factory to the /test url */
    gst_rtsp_mount_points_add_factory (mounts, "/test", factory);

    /* don't need the ref to the mapper anymore */
    g_object_unref (mounts);

    /* attach the server to the default maincontext */
    if (gst_rtsp_server_attach (server, NULL) == 0)
        goto failed;

    g_timeout_add_seconds (2, (GSourceFunc) timeout, server);

    /* start serving */
    g_print ("stream ready at rtsp://192.168.0.92:8554/test\n");
    g_main_loop_run (loop);

    return 0;

    /* ERRORS */
    failed:
    {
        g_print ("failed to attach the server\n");
        return -1;
    }
}

error message:

stream ready at rtsp://192.168.0.92:8554/test

(rtsp_server:5974): GStreamer-RTSP-Server-CRITICAL **: 16:53:20.791: could not parse launch syntax ((v4l2src device=/dev/video0 ! videoconvert ! video/x-raw, width=640, height=480, format=I420 ! x264enc ! rtph264pay name=pay0 pt=96)): could not set property "pt" in element "pay0" to "96)"
(rtsp_server:5974): GStreamer-RTSP-Server-CRITICAL **: 16:53:20.791: could not create element
(rtsp_server:5974): GStreamer-RTSP-Server-CRITICAL **: 16:53:20.816: could not parse launch syntax ((v4l2src device=/dev/video0 ! videoconvert ! video/x-raw, width=640, height=480, format=I420 ! x264enc ! rtph264pay name=pay0 pt=96)): could not set property "pt" in element "pay0" to "96)"
(rtsp_server:5974): GStreamer-RTSP-Server-CRITICAL **: 16:53:20.816: could not create element
(rtsp_server:5974): GStreamer-RTSP-Server-CRITICAL **: 16:53:57.666: could not parse launch syntax ((v4l2src device=/dev/video0 ! videoconvert ! video/x-raw, width=640, height=480, format=I420 ! x264enc ! rtph264pay name=pay0 pt=96)): could not set property "pt" in element "pay0" to "96)"
(rtsp_server:5974): GStreamer-RTSP-Server-CRITICAL **: 16:53:57.666: could not create element

Solution

  • I solved the problem by adding some space in the pipeline and now its works fine for me:

    " (v4l2src device=/dev/video0 ! videoconvert ! video/x-raw, width=640, height=480, format=I420 ! x264enc ! rtph264pay name=pay0 pt=96) ");