RTSP server stream H264 with manual pipeline

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RTSP server stream H264 with manual pipeline

macarons
Hello! I am trying to stream H264 using the a GStreamer RTSP server and a manual pipeline, and it requires changing the format to I420 because of the encoder. I've tried using a capsfilter and using rawvideoparse but I couldn't seem to get either one to work. When I use rawvideoparse, I get a video that flashes green and pink, and when I use capsfilter, I don't get a video stream. Does anyone know how to stream H264 using a manual pipeline and an RTSP server? Thank you!

I have tried linking the elements using
gst_element_link_many (source, videoscale, videoparse, videoconvert, queue, encoder, rtppay, NULL) and
gst_element_link_many (source, videoscale, capsfilter, videoconvert, queue, encoder, rtppay, NULL)

I have also tried linking with variations of
gst_element_link(source,videoscale) && link_elements_with_filter(videoscale,videoconvert) && gst_element_link(videoconvert,queue) && gst_element_link(queue,encoder) && gst_element_link(encoder,rtppay) and
gst_element_link (source, videoconvert) && gst_element_link(videoconvert, videoscale) && link_elements_with_filter (videoscale, encoder) && gst_element_link (encoder, rtppay)
(link_elements_with_filter function definition below)


I'm running the server as follows:
factory = custom_pipeline_factory(pipeline);
// gst_rtsp_media_factory_set_launch (factory, "v4l2src device=/dev/video0 ! videoscale ! capsfilter caps=video/x-raw,format=I420,width=640,height=480 ! videoconvert ! queue ! x264enc ! rtph264pay name=pay0 pt=96");
gst_rtsp_media_factory_set_launch (factory, "v4l2src device=/dev/video0 ! videoscale ! rawvideoparse width=640 height=480 format=2 ! videoconvert ! queue ! x264enc ! rtph264pay name=pay0 pt=96");
   

Here are the elements and function definitions:

GstElement *binPipeline;

GstElement *create_bin_element(GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
{
    return binPipeline;
}

GstRTSPMediaFactory *custom_pipeline_factory(GstElement *bin)
{
    GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new();
    GstRTSPMediaFactoryClass *memberFunctions = GST_RTSP_MEDIA_FACTORY_GET_CLASS(factory);

    // pipeline created somewhere else
    binPipeline = bin;
    memberFunctions->create_element = create_bin_element;
    return factory;
}

static gboolean link_elements_with_filter (GstElement *element1, GstElement *element2)
{
  gboolean link_ok;
  GstCaps *caps;

  caps = gst_caps_from_string("video/x-raw,format=I420,width=640,height=480,framerate=20/1");

  link_ok = gst_element_link_filtered (element1, element2, caps);
  gst_caps_unref (caps);

  if (!link_ok) {
      g_printerr ("Failed to link element1 and element2!");
    }

  return link_ok;
}


source = gst_element_factory_make ("v4l2src", "source");
encoder = gst_element_factory_make ("x264enc", "encoder");
rtppay = gst_element_factory_make ("rtph264pay", "pay0");
videoconvert = gst_element_factory_make("videoconvert", "vidconvert");
videoscale = gst_element_factory_make("videoscale", "vidscale");
queue = gst_element_factory_make("queue", "vidqueue");
videoparse = gst_element_factory_make("rawvideoparse", "vidparse");
capsfilter = gst_element_factory_make("capsfilter", "filter");
pipeline = gst_pipeline_new ("pipeline");
bin = gst_bin_new ("bin");

GstCaps *caps = gst_caps_new_simple ("video/x-raw",
        "format", G_TYPE_STRING, "I420",
        "framerate", GST_TYPE_FRACTION, 30, 1,
        "width", G_TYPE_INT, 640,
        "height", G_TYPE_INT, 480,
        NULL);
Reply | Threaded
Open this post in threaded view
|

Re: RTSP server stream H264 with manual pipeline

Marianna S. Buschle
You need to enable debugging to get some useful information about what is going on.

But without any extra information I would say that using a rawvideoparse makes little sense to me.

As I see it, the conversion to I420 should be taken care of by the the videoconvert you have before the x264enc so you shouldn't need the capsfilter before it (at least not the format part).

So I would suggest trying:
gst_rtsp_media_factory_set_launch (factory, "v4l2src device=/dev/video0 ! videoscale ! capsfilter caps=video/x-raw,width=640,height=480 ! videoconvert ! queue ! x264enc ! rtph264pay name=pay0 pt=96");

Otherwise you need to look at what formats your v4l2src can provide, my guess is that it probably doesn't support I420 since you say you get no video.