简体   繁体   English

FFMPEG C++ select GPU

[英]FFMPEG C++ select GPU

 AVDictionary* options = nullptr;
 av_dict_set(&options, "hwaccel", "cuvid", 0);
 av_dict_set_int(&options, "hwaccel_device", 2, 0);

Even though I specify hwaccel device to be 2, it still runs on GPU 0. How can I fix this?即使我将 hwaccel 设备指定为 2,它仍然在 GPU 0 上运行。我该如何解决这个问题?

Ran into this issue myself.我自己遇到了这个问题。 Here is the solution.这是解决方案。 When you create the hwdevice ctx you can pass in a char* specifying the gpu device.创建 hwdevice ctx 时,您可以传入指定 gpu 设备的char*

int gpu_id = 1;
std::string d = std::to_string(gpu_id);
const char * device = d.c_str();
int err = 0;
if ((err = av_hwdevice_ctx_create(&hw_device_ctx, type,
                                      device, NULL, 0)) < 0) {
    return err;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM