【问题标题】:How can I specify a GPU using ffmpeg API?如何使用 ffmpeg API 指定 GPU?
【发布时间】:2021-10-12 23:45:53
【问题描述】:

据我所知,它可以在命令行中使用-hwaccel_device-gpu 指定GPU 设备,但是如何在使用API​​ 时指定GPU?

我试图在 ffmpeg.c 中找到它,而对于 c++ 和 ffmpeg 的新手来说这太复杂了。

我可以使用 AVDictionary 吗?什么是关键字?

如果有人能提供一些提示,将不胜感激!

【问题讨论】:

    标签: c ffmpeg gpu video-processing


    【解决方案1】:

    我终于通过阅读OpenCV的源代码解决了这个问题。 关键API是

    int av_hwdevice_ctx_create(AVBufferRef **device_ctx, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags).

    OpenCV 的cap_ffmpeg_hw.hpp 中的源代码:

    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);
    

    【讨论】:

      猜你喜欢
      • 2017-03-18
      • 1970-01-01
      • 2021-05-05
      • 2021-08-18
      • 2020-11-26
      • 2021-04-20
      • 1970-01-01
      • 2020-01-14
      • 2013-08-19
      相关资源
      最近更新 更多