# My program wants to dynamically switch resolutions

**URL:** <https://discourse.gstreamer.org/t/my-program-wants-to-dynamically-switch-resolutions/106>\
**Category:** Application Development\
**Created:** [September 26, 2023, 9:36am UTC](https://discourse.gstreamer.org/t/my-program-wants-to-dynamically-switch-resolutions/106 "2023-09-26T09:36:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Today](https://discourse.gstreamer.org/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@Today](https://discourse.gstreamer.org/u/Today)\
**Post date:** [September 26, 2023, 9:36am UTC](https://discourse.gstreamer.org/t/my-program-wants-to-dynamically-switch-resolutions/106/1 "2023-09-26T09:36:41Z")

</div>

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

```auto
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.

```cpp
        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:

```plaintext
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)

```

---

<div class="post-metadata">

**Author:** ![ystreet00](https://discourse.gstreamer.org/letter_avatar_proxy/v4/letter/y/3d9bf3/32.png) [@ystreet00](https://discourse.gstreamer.org/u/ystreet00)\
**Post date:** [September 26, 2023, 10:29am UTC](https://discourse.gstreamer.org/t/my-program-wants-to-dynamically-switch-resolutions/106/2 "2023-09-26T10:29:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Today](https://discourse.gstreamer.org/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@Today](https://discourse.gstreamer.org/u/Today)\
**Post date:** [September 27, 2023, 1:42am UTC](https://discourse.gstreamer.org/t/my-program-wants-to-dynamically-switch-resolutions/106/3 "2023-09-27T01:42:29Z")

</div>

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.

```auto
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

```
