0

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.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
TONY
  • 101
  • 7
  • 1
    It seems unlikely. The DXGI factory is just an entry point to DXGI API, it doesn't do much by itself. The following code (that you don't show) probably does something else after that, that may cause exclusive access. – Simon Mourier May 13 '22 at 14:35
  • Have you tried [IDXGIFactory::Release](https://learn.microsoft.com/en-us/windows/desktop/api/unknwn/nf-unknwn-iunknown-release) to verify? And could you please show a minimal, reproducible sample without private information? – YangXiaoPo-MSFT May 16 '22 at 08:51

0 Answers0