FFmpeg av_hwdevice_ctx_create 返回 ENOMEM

问题描述

我正在尝试使用 ffmpeg 的 vaapi 库在 GPU 上执行 h264 视频编码。

我一直在关注这个来自 ffmpeg Github 存储库的 example

这里对我来说失败了:

AVBufferRef* vaapi_encoder;
int err = av_hwdevice_ctx_create(&vaapi_encoder,AV_HWDEVICE_TYPE_VAAPI,NULL,0);

这将返回 -12,它映射到 ENOMEM(内存不足)错误,但这对我来说没有意义,因为我有足够的内存。

作为参考,这是我运行 'vainfo' 后的输出:

libva info: VA-API version 1.7.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_7
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.7 (libva 2.6.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 20.1.1 ()
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSliceLP
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSliceLP
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD

谢谢!

解决方法

好的,所以我想出了问题所在。

即使我的系统上安装了正确的 FFmpeg 配置(带有 --enable-hwaccel=h264_vaapi 的配置),但问题是我将我的程序与错误版本的 libav(包含在 libwebrtc 中的版本,而不是一个来自我的系统。

所以我不正确的 Makefile 有类似的内容:

LDLIBS += -lwebrtc -lpthread -lm -lavcodec -lavutil -lavformat -lavdevice

所以它首先与 libwebrtc 链接,然后使用那里的 libav 内容。

在我将 -lwebrtc 移动到 -lavcodec -lavutil 之后链接后,它开始工作:

LDLIBS += -lpthread -lm -lavcodec -lavutil -lavformat -lavdevice -lwebrtc

另外,我确保使用 sudo 运行程序,否则它会给我其他错误。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...