gpt4 book ai didi

c++ - FFmpeg + cpp,如何获取处理 h264_nvenc 的 GPU 列表?

转载 作者:行者123 更新时间:2023-12-04 23:22:42 30 4
gpt4 key购买 nike

我正在编写要在具有多个 GPU 的 PC 上使用的应用程序,我正在尝试获取可以在 h264 中解码流的 GPU 索引列表,以在所有可用 GPU 之间平均分配所有新视频源。

我已经找到了如何在命令提示符下执行此操作,但我需要在 C++ 中编写属于它的行

ffmpeg -vsync 0 -i input.mp4 -c:v h264_nvenc -gpu list -f null –

我需要它动态地将它传递给 av_hwdevice_ctx_create(AVBufferRef**,char *int)

有谁知道如何做到这一点?

最佳答案

据我所知,您不需要将设备显式传递给

av_hwdevice_ctx_create  (   
AVBufferRef ** device_ctx,
enum AVHWDeviceType type,
const char * device,
AVDictionary * opts,
int flags
)
device_ctx可以为 NULL,因为它是在这里创建的。你只需要知道你想要的类型。例如 AV_HWDEVICE_TYPE_CUDA .其余参数可以为 NULL 或 0。
至少在 hw_decode example 中是这样的。 :
static AVBufferRef *hw_device_ctx = NULL;
//...
static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type)
{
int err = 0;
if ((err = av_hwdevice_ctx_create(&hw_device_ctx, type,
NULL, NULL, 0)) < 0) {
fprintf(stderr, "Failed to create specified HW device.\n");
return err;
}
ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
return err;
}

(注意:我自己没有使用过该功能。我只是根据示例中的操作方式来回答。)

关于c++ - FFmpeg + cpp,如何获取处理 h264_nvenc 的 GPU 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62151289/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com