gpt4 book ai didi

c - 如何使用 ffmpeg API 指定 GPU?

转载 作者:行者123 更新时间:2023-12-04 22:49:02 31 4
gpt4 key购买 nike

据我所知,它可以使用-hwaccel_device-gpu在命令行中指定 GPU 设备,但如何在使用 API 时指定 GPU?
我试图在 ffmpeg.c 中找到它,而对于 c++ 和 ffmpeg 的新手来说这太复杂了。
我可以使用 AVDictionary 吗?什么是关键字?
如果有人可以提供一些提示,将不胜感激!

最佳答案

我终于通过阅读 OpenCV 的源代码解决了这个问题。
关键API是int av_hwdevice_ctx_create(AVBufferRef **device_ctx, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags) .cap_ffmpeg_hw.hpp中的源代码OpenCV 的:

char device[128] = "";
char* pdevice = NULL;
if (hw_device >= 0 && hw_device < 100000) {
if (child_type == AV_HWDEVICE_TYPE_VAAPI) {
snprintf(device, sizeof(device), "/dev/dri/renderD%d", 128 + hw_device);
}else {
snprintf(device, sizeof(device), "%d", hw_device);
}
pdevice = device;
}
const char* hw_child_name = av_hwdevice_get_type_name(child_type);const char* device_name = pdevice ? pdevice : "'default'";
int err = av_hwdevice_ctx_create(&hw_device_ctx, child_type, pdevice, NULL, 0);

关于c - 如何使用 ffmpeg API 指定 GPU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68709401/

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