'Why does CreateDXGIFactory occupy GPU even if I call it's release interface

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source