为什么createxgifactory占用GPU,即使我称其为“发行界面”

发布于 2025-01-28 17:02:38 字数 1315 浏览 6 评论 0原文

首先,我运行以下代码:

IDXGIFactory* pFactory;
    HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory1), (void**)(&pFactory));
    if (FAILED(hr))
    {
        return -1;
    }

然后我尝试使用FFMPEG的NVENC_H264函数:

    AVCodec* m_encoder = avcodec_find_encoder_by_name("h264_nvenc");
    if (!m_encoder) {
        m_encoder = avcodec_find_encoder_by_name("nvenc_h264");
    }

    if (!m_encoder) {
        err = -1;
        std::cout << "find 264 encoder failed" << std::endl;
        return 0;
    }

    AVCodecContext* m_encoder_ctx = avcodec_alloc_context3(m_encoder);
    if (!m_encoder_ctx) {

        err = -1;
        std::cout << "avcodec_alloc_context3 failed" << std::endl;
        return 0;
    }

    m_encoder_ctx->width = 1280;
    m_encoder_ctx->height = 720;
    m_encoder_ctx->time_base = { 1, (int)25 };

    m_encoder_ctx->codec_id = m_encoder->id;
    m_encoder_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
    m_encoder_ctx->pix_fmt = AV_PIX_FMT_YUV420P;

    ret = avcodec_open2(m_encoder_ctx, m_encoder, nullptr);

失败。 AVCODE_OPEN2将失败,它表明 “ [H264_NVENC @ 0000016AE3F06F00] dl_fn-&gt; cuda_dl-&gt; cuinit(0)失败 - &gt; cuda_error_no_device:未检测到具有CUDA的设备 但是,如果我不称为createxgifactory,那么avcodec_open2将成功。

First I run the following code:

IDXGIFactory* pFactory;
    HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory1), (void**)(&pFactory));
    if (FAILED(hr))
    {
        return -1;
    }

then I tried to use ffmpeg's nvenc_h264 function:

    AVCodec* m_encoder = avcodec_find_encoder_by_name("h264_nvenc");
    if (!m_encoder) {
        m_encoder = avcodec_find_encoder_by_name("nvenc_h264");
    }

    if (!m_encoder) {
        err = -1;
        std::cout << "find 264 encoder failed" << std::endl;
        return 0;
    }

    AVCodecContext* m_encoder_ctx = avcodec_alloc_context3(m_encoder);
    if (!m_encoder_ctx) {

        err = -1;
        std::cout << "avcodec_alloc_context3 failed" << std::endl;
        return 0;
    }

    m_encoder_ctx->width = 1280;
    m_encoder_ctx->height = 720;
    m_encoder_ctx->time_base = { 1, (int)25 };

    m_encoder_ctx->codec_id = m_encoder->id;
    m_encoder_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
    m_encoder_ctx->pix_fmt = AV_PIX_FMT_YUV420P;

    ret = avcodec_open2(m_encoder_ctx, m_encoder, nullptr);

it's failed. the avcode_open2 would fail, it shows that
"[h264_nvenc @ 0000016AE3F06F00] dl_fn->cuda_dl->cuInit(0) failed -> CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected"
but if I don't call the CreateDXGIFactory, then the avcodec_open2 would success.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文