h264_nvenc fails to set gpu

Hello,

I am working on ffmpeg h264_nvenc for nvidia encoding.

here is a sample code.

ret = av_hwdevice_ctx_create(&encode_device, AV_HWDEVICE_TYPE_CUDA, NULL, NULL, 0);

codec = avcodec_find_encoder_by_name(“h264_nvenc”);

c = avcodec_alloc_context3(codec);

c->gop_size = 10;

c->pix_fmt = AV_PIX_FMT_NV12;

c->hw_device_ctx = av_buffer_ref(encode_device);

ret = avcodec_open2(c, codec, NULL);

I set to gpu 1 but function takes gpu 0 power only.

Please help me how to flip nvidea gpu 0 to 1.