Problem with caps between v4l2src and autovideosink

Prabhakar Lad prabhakar.csengg at gmail.com
Thu Sep 18 09:42:49 PDT 2014


Hi,

On Thu, Sep 18, 2014 at 5:24 PM, Prabhakar Lad
<prabhakar.csengg at gmail.com> wrote:
> Hello,
>
> On Thu, Sep 18, 2014 at 11:39 AM, Alicia Romero <alromor84 at gmail.com> wrote:
>> Hi people!
>> I have a camera installed in /dev/video0.
>>
>> The pipeline:
>> gst-launch -v v4l2src ! autovideosink
>>
>> works perfectly and I can see which caps between v4l2src and autovideosink
>> are used:
>> /GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0.GstGhostPad:sink:
>> caps = video/x-raw-yuv, format=(fourcc)YUY2, width=(int)1600,
>> height=(int)1200, interlaced=(boolean)false,
>> pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1
>>
>> Now I want to write a small application doing the same:
>>   [...]
>>   source = gst_element_factory_make ("v4l2src", "source");
>>   sink = gst_element_factory_make ("autovideosink", "sink");
>>   caps_filter = gst_element_factory_make("capsfilter", "filter");
>>   [...]
>>  caps = gst_caps_new_simple("video/x-raw",
>>               "framerate", GST_TYPE_FRACTION, 5, 1,
>>               "format", G_TYPE_STRING, "YUY2",
>>               "width", G_TYPE_INT, 1600,
>>               "height", G_TYPE_INT, 1200,
>>               NULL);
>>  g_object_set(G_OBJECT(caps_filter), "caps", caps, NULL);
>>   [...]
>>
>> But it is not working, I get:
>> Error received from element source: Internal data flow error.
>> Debugging information: gstbasesrc.c(2933): gst_base_src_loop ():
>> /GstPipeline:test-pipeline/GstV4l2Src:source:
>> streaming task paused, reason not-negotiated (-4)
>>
> That wont work if you are trying to add capsfilter, you need to
> add videoconvert element after your capsfilter for example try below pipeline,
>
> gst-launch-1.0 -v v4l2src ! video/x-raw, format=YUY2, width=1600,
> height=1200,  framerate=5/1 ! videoconvert ! autovideosink
>
> Implement the above pipeline in your program and should be working!
>
Just try the below code:-

Thanks,
--Prabhakar

#include <stdio.h>
#include <unistd.h>

#include <gst/gst.h>
#include <gst/app/gstappsrc.h>

/* to compile gcc sample.c -o sample -Wall `pkg-config --cflags --libs
gstreamer-1.0` */

GstElement *pipeline = NULL;
static GMainLoop *loop;

static gboolean bus_handler (GstBus *bus, GstMessage *msg, gpointer data)
{
    GMainLoop *loop;

    loop = (GMainLoop*)data;

    switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_EOS:
    g_main_loop_quit (loop);
    break;
    case GST_MESSAGE_ERROR:
    {
        gchar *debug;
        GError *error;

        gst_message_parse_error (msg, &error, &debug);
        g_free (debug);

        g_printerr ("Error: %s\n", error->message);
        g_error_free (error);

        g_main_loop_quit (loop);
        break;
    }
    case GST_MESSAGE_STATE_CHANGED:
    {
        GstState state;

        gst_message_parse_state_changed (msg, NULL, &state, NULL);

        break;
    }
    default:
    break;
    }

    return TRUE;
}

int main(int argc, char *argv[])
{
    GstElement *capsfilter, *sink, *v4l2src;
    GstBus *bus;
    guint bus_id;
    GstCaps *caps;

    gst_init (NULL, NULL);

    loop = g_main_loop_new (NULL, FALSE);

    pipeline = gst_pipeline_new ("test_pipeline");
    v4l2src = gst_element_factory_make ("v4l2src", "v4l2src");
    capsfilter = gst_element_factory_make ("capsfilter", "capsfilter");
    sink = gst_element_factory_make ("autovideosink", "filesink");

    if (!pipeline || !capsfilter || !sink || !v4l2src) {
        printf ("Could not create all gstreamer elements.\n");
        return 0;
    }

    caps = gst_caps_new_simple("video/x-raw",
        "framerate", GST_TYPE_FRACTION, 5, 1,
        "format", G_TYPE_STRING, "YUY2",
        "width", G_TYPE_INT, 1600,
        "height", G_TYPE_INT, 1200,
        NULL);
    g_object_set(G_OBJECT(capsfilter), "caps", caps, NULL);

    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    bus_id = gst_bus_add_watch (bus, bus_handler, loop);
    gst_object_unref (bus);

    gst_bin_add_many (GST_BIN (pipeline), sink, v4l2src, capsfilter, NULL);

    /*gst-launch-1.0 -v v4l2src ! capsfilter caps="video/x-raw,
format=YUY2, width=1600, height=1200,  framerate=5/1" ! autovideosink
*/
    gst_element_link_many (v4l2src, capsfilter, sink, NULL);

    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    g_main_loop_run (loop);

    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (GST_OBJECT (pipeline));
    g_source_remove (bus_id);
    g_main_loop_unref (loop);
    gst_deinit ();

    return 0;
}


More information about the gstreamer-devel mailing list