V4l2-ctl can work well,but ioctl not

i can use v4l2-ctl to set/get some param for my sensor,like

v4l2-ctl --set-ctrl=gain=400

but ioctl not work

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <memory.h>

int main(void)
{
	int fd = open("/dev/video0", O_RDWR);
	if(fd < 0)
	{
		perror("open dev error");
		return -1;
	}

	struct v4l2_format vfmt;
    memset(&vfmt,0,sizeof(vfmt));
    vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    vfmt.fmt.pix.width = 1920;
	vfmt.fmt.pix.height = 1080;
	vfmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SGRBG12;
    int ret = ioctl(fd, VIDIOC_S_FMT, &vfmt);
    if(ret < 0) {
        printf("set camera frame format error \n");
        return -1;
    }
	struct v4l2_control ctrl;
    ctrl.id = V4L2_CID_GAIN;
    ret = ioctl(fd, VIDIOC_G_CTRL,&ctrl);
    if(ret < 0) {
        perror(" Get gain value failed ");
        return -1;
    } else {
		printf(" get gain = %d \n",ctrl.value);
	}
	close(fd);
	return 0;
}

$ ./main
Get gain value failed : Invalid argument

Hi,
Please share your release version. Is it JP4.5.1(r32.5.1)?

hi
Jetpack: 4.4.1

Hi,
You may try this sample:

/usr/src/jetson_multimedia_api/samples/v4l2cuda

Check if you run it successfully in raw frame capturing.

hello fanyj233,

you may enable below to check all available controls and their values,
for example, $ v4l2-ctl -d /dev/video0 --list-ctrls
thanks