Trying translate working gst-launch command to the API

Matthew Waters ystreet00 at gmail.com
Mon Aug 24 07:36:01 UTC 2020


On 24/8/20 5:12 am, Kelly Wiles wrote:
> I am getting a segment fault when I try and convert the following,
> which works into the C API.
>
> gst-launch-1.0 -e -v v4l2src !
> 'video/x-raw,width=1280,height=720,framerate=30/1,format=UYVY' ! tee
> name=t ! queue ! v4l2h264enc
> extra-controls="controls,h264_profile=4,h264_level=10,video_bitrate=500000;"
> ! h264parse ! filesink location=foo1.h264 t. ! queue ! v4l2h264enc
> extra-controls="controls,h264_profile=4,h264_level=10,video_bitrate=2000000;"
> ! h264parse ! filesink location=foo2.h264
>
> I run the v4l2-ctl commands before executing the gst command.
>
> v4l2-ctl --set-edid=file=edid5.txt --fix-edid-checksums
> v4l2-ctl -v pixelformat=UYVY
> v4l2-ctl --set-dv-bt-timings query
>
> The edid5.txt is.
>
> 00,FF,FF,FF,FF,FF,FF,00,52,62,88,88,00,88,88,88,1C,15,01,03,80,00,00,78,0A,EE,91,A3,54,4C,99,26,0F,50,54,00,00,00,01,01,01,01,01,0
>
> 1,01,01,01,01,01,01,01,01,01,01,01,1D,00,72,51,D0,1E,20,6E,28,55,00,C4,8E,21,00,00,1E,8C,0A,D0,8A,20,E0,2D,10,10,3E,96,00,13,8E,21
>
> ,00,00,1E,00,00,00,FC,00,54,6F,73,68,69,62,61,2D,48,32,43,0A,20,00,00,00,FD,00,3B,3D,0F,2E,0F,00,0A,20,20,20,20,20,20,01,6D,02,03,
>
> 21,41,4D,84,13,03,02,12,11,01,20,21,22,3C,3D,3E,23,09,07,07,66,03,0C,00,30,00,80,E3,00,7F,8C,8C,0A,D0,8A,20,E0,2D,10,10,3E,96,00,C
>
> 4,8E,21,00,00,18,8C,0A,D0,8A,20,E0,2D,10,10,3E,96,00,13,8E,21,00,00,18,8C,0A,A0,14,51,F0,16,00,26,7C,43,00,13,8E,21,00,00,98,00,00
>
> ,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,BE
>
>
> When I run this code it crashes with a segment fault on the
> g_object_set function.
>
> #include <gst/gst.h>
> #include <stdio.h>
>
> // gst-launch-1.0 -e -v v4l2src !
> 'video/x-raw,width=1280,height=720,framerate=30/1,format=UYVY' ! tee
> name=t ! queue ! v4l2h264enc
> extra-controls="controls,h264_profile=4,h264_level=10,video_bitrate=500000;"
> ! h264parse ! filesink location=foo1.h264 t. ! queue ! v4l2h264enc
> extra-controls="controls,h264_profile=4,h264_level=10,video_bitrate=2000000;"
> ! h264parse ! filesink location=foo2.h264
>
> typedef struct _App {
>         GstElement *pipeline;
>         GstElement *appsrc;
>
>         GMainLoop *loop;
>         guint sourceid;
>
>         GTimer *timer;
> } App;
>
> App app;
>
> gint main(gint argc, gchar *argv[]) {
>
>         GstElement *src, *split, *enc1, *enc2, *f1, *f2, *h1, *h2,
> *q1, *q2;
>         GstCaps *filtercaps;
>         GstCaps *enccaps;
>
>         gst_init(&argc, &argv);
>
>         app.loop = g_main_loop_new(NULL, FALSE);
>
>         app.pipeline = gst_pipeline_new("my-pipeline");
>
>         src = gst_element_factory_make("v4l2src", "src");
>         split = gst_element_factory_make("tee", "split");
>         h1 = gst_element_factory_make("h264parse", "h1");
>         h2 = gst_element_factory_make("h264parse", "h2");
>         q1 = gst_element_factory_make("queue", "q1");
>         q2 = gst_element_factory_make("queue", "q2");
>         enc1 = gst_element_factory_make("v4l2h264enc", "enc1");
>         enc2 = gst_element_factory_make("v4l2h264enc", "enc2");
>         f1 = gst_element_factory_make("filesink", "f1");
>         f2 = gst_element_factory_make("filesink", "f2");
>
>         if (!app.pipeline || !src || !split || !enc1 || !enc2 || !f1
> || !f2 || !h1 || !h2 || !q1 || !q2) {
>                 g_error ("Could not create
> elements\npip=%p\nsrc=%p\nsplit=%p\nenc1=%p\nenc2=%p\nf1=%p\nf2=%p\nh1=%p\nh2=%p\nq1=%p\nq2=%p",
>                                 app.pipeline, src, split, enc1, enc2,
> f1, f2, h1, h2, q1, q2);
>                 return -1;
>         }
>
>         g_object_set(f1, "location", "foo1.h264", NULL);
>         g_object_set(f2, "location", "foo2.h264", NULL);
>
>         fprintf(stderr, "Here 1\n");
>         // g_object_set(enc1, "extra-controls",
> "controls,h264_profile=4,h264_level=10,video_bitrate=500000;", NULL);
>         enccaps = gst_caps_new_simple ("controls",
>                         "h264_profile", G_TYPE_INT, 4,
>                         "h264_level", G_TYPE_INT, 10,
>                         "video_bitrate", G_TYPE_INT, 500000,
>                         NULL);
>         g_object_set (G_OBJECT (enc1), "extra-controls", enccaps, NULL);

I assume here is the crash?

extra-controls requires a GstStructure, not a GstCaps.

Replace gst_caps_new_simple() with gst_structure_new() (and types).

>         fprintf(stderr, "Here 2\n");
>         g_object_set(enc2, "extra-controls",
> "controls,h264_profile=4,h264_level=10,video_bitrate=2000000;", NULL);
>         fprintf(stderr, "Here 3\n");
>
>         gst_bin_add_many(GST_BIN(app.pipeline), src, split, q1, enc1,
> h1, f1, q2, enc2, h2, f2, NULL);
>
>         if (!gst_element_link_many(src, split, NULL)
>                 || !gst_element_link_many(split, q1, enc1, h1, f1, NULL)
>                 || !gst_element_link_many(split, q2, enc2, h2, f2,
> NULL)) {
>                 g_error("Failed to link elements ...");
>                 return -2;
>         }
>
>         filtercaps = gst_caps_new_simple ("video/x-raw",
>                "format", G_TYPE_STRING, "UYVY",
>                "width", G_TYPE_INT, 1280,
>                "height", G_TYPE_INT, 720,
>                "framerate", GST_TYPE_FRACTION, 30, 1,
>                NULL);
>         g_object_set (G_OBJECT (src), "caps", filtercaps, NULL);
>         gst_caps_unref (filtercaps);
>
>         gst_element_set_state (app.pipeline, GST_STATE_PLAYING);
>
>         if (gst_element_get_state (app.pipeline, NULL, NULL, -1) ==
> GST_STATE_CHANGE_FAILURE) {
>                 g_error ("Failed to go into PLAYING state");
>         }
>
>         g_print ("Running ...\n");
>         g_main_loop_run (app.loop);
>
>         /* exit */
>         gst_element_set_state (app.pipeline, GST_STATE_NULL);
>         gst_object_unref (app.pipeline);
>
>         return 0;
> }
>
> The 'Here 1' prints then it dies, can any one help me to understand why?
>
> Either method of calling g_object_set fails the same way.
>
> Thanks
>
>
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20200824/d37db033/attachment-0001.sig>


More information about the gstreamer-devel mailing list