为什么createxgifactory占用GPU,即使我称其为“发行界面”
首先,我运行以下代码:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论