My program wants to dynamically switch resolutions

Hello, I want to dynamically switch the resolution in the pipeline below, but the ability of appsrc keeps failing.

appsrc ! h264parse ! capsfilter ! nvv4l2decoder ! appsink

// The initial settings of appsrc are as follows
    g_object_set(data_info.appsrc ,
        "caps" , gst_caps_new_simple(
            "video/x-h264" ,
            "stream-format" , G_TYPE_STRING , "byte-stream" ,
            "width" , G_TYPE_INT , width ,
            "height" , G_TYPE_INT , height ,
            "framerate" , GST_TYPE_FRACTION , 30 , 1 ,
            NULL) ,
        "format" , GST_FORMAT_TIME ,
        "is-live" , TRUE ,
        "max-bytes" , 0 ,
        NULL);

Since the resolution of my device when switching the camera’s photo or video mode is 1080 and 1440 respectively, when the data reaches Appsrc, I failed to switch caps through the code below. The element nvv4l2decoder has been confirmed by nvidia to support dynamic switching, so now I want to know how appsrc can dynamically switch its capabilities.

        auto app_caps = gst_caps_new_simple(
            "video/x-h264" ,
            "stream-format" , G_TYPE_STRING , "byte-stream" ,
            "width" , G_TYPE_INT , width ,
            "height" , G_TYPE_INT , height ,
            "framerate" , GST_TYPE_FRACTION , 30 , 1 ,
            NULL);

        auto sample = gst_sample_new(data_info.gst_buffer , app_caps , NULL , NULL);
        gst_app_src_push_sample(GST_APP_SRC(appsrc) , sample);

The exception is as follows:

ERROR from element appsrc_one: Internal data stream error.
nvstreammux: Successfully handled EOS for source_id=0
Error details: gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:resolution_test/GstAppSrc:appsrc_one:
streaming stopped, reason not-negotiated (-4)

In my experience, the nvv4l2decoder element does not support resolution changes in some cases. Setting disable-passthrough=true on h264parse may help with this situation in some cases.

I would first test without using nvv4l2decoder to check that your pipeline is correct.

Thank you for your support. I tested in the pipeline below and found that appsrc can dynamically switch the resolution through gst_app_src_push_sample(). The program may be blocking on the nvv4l2decoder element.

appsrc caps=video/x-h264,stream-format=byte-stream,width=1920,height=1080 format=3 is-live=1 max-bytes=0 ! h264parse disable-passthrough=1 ! appsink