Jetson Xavier NX FFmpeg支持硬件编解码

FFmpeg

FFmpeg名声在外,这里不做过多的介绍。本文主要参考的官方资料如下

系统自带的FFmpeg包

查看系统自带的ffmpeg相关信息

nvidia@nvidia-desktop:~$ dpkg -l ffmpeg
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                           Version              Architecture         Description
+++-==============================-====================-====================-=================================================================
ii  ffmpeg                         7:3.4.11-0ubuntu0.1  arm64                Tools for transcoding, streaming and playing of multimedia files
nvidia@nvidia-desktop:~$ ffmpeg -hide_banner -codecs | grep h264
 DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_vdpau ) (encoders: libx264 libx264rgb h264_omx h264_v4l2m2m h264_vaapi )

通过测试来看系统自带的ffmpeg 3.4.11-0ubuntu0.1包在NVIDIA® Jetson™ device上并不支持硬件加速编解码,如果使用在NVIDIA® Jetson™ device上使用硬件加速,需要使用NVIDIA ffmpeg包。

FFmpeg的nvidia包

根据官网文档,添加NVIDIA ffmpeg源,并安装

$ echo "deb https://repo.download.nvidia.com/jetson/ffmpeg main main" | sudo tee -a /etc/apt/sources.list
$ echo "deb-src https://repo.download.nvidia.com/jetson/ffmpeg main main" | sudo $ tee -a /etc/apt/sources.list
$ sudo apt update

$ sudo apt install ffmpeg
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ffmpeg : Depends: libaom0 (>= 1.0.0) but it is not installable
          Depends: libc6 (>= 2.29) but 2.27-3ubuntu1.4 is to be installed
          Depends: libcdio-cdda2 (>= 10.2+2.0.0) but 10.2+0.94+2-2build1 is to be installed
          Depends: libcdio-paranoia2 (>= 10.2+2.0.0) but 10.2+0.94+2-2build1 is to be installed
          Depends: libcodec2-0.9 but it is not installable
          Depends: libgnutls30 (>= 3.6.12) but 3.5.18-1ubuntu1.5 is to be installed
          Depends: libgsm1 (>= 1.0.18) but 1.0.13-4build1 is to be installed
          Depends: libmysofa1 (>= 0.7~) but it is not installable
          Depends: librubberband2 (>= 1.8.2) but 1.8.1-7ubuntu2 is to be installed
          Depends: libsdl2-2.0-0 (>= 2.0.10) but 2.0.8+dfsg1-1ubuntu1.18.04.4 is to be installed
          Depends: libsnappy1v5 (>= 1.1.8) but 1.1.7-1 is to be installed
          Depends: libsndio7.0 (>= 1.1.0) but it is not installable
          Depends: libssh-gcrypt-4 (>= 0.8.0) but 0.8.0~20170825.94fa1e38-1ubuntu0.7 is to be installed
          Depends: libva2 (>= 2.2.0) but 2.1.0-3 is to be installed
          Depends: libvidstab1.1 but it is not installable
          Depends: libvpx6 (>= 1.6.0) but it is not installable
          Depends: libwebpmux3 (>= 0.6.1-2ubuntu0.20.04.1) but 0.6.1-2ubuntu0.18.04.1 is to be installed
          Depends: libx264-155 but it is not installable
          Depends: libx265-179 (>= 3.2) but it is not installable
E: Unable to correct problems, you have held broken packages.

安装ffmpeg 4.2.7-nvidia的过程中由于依赖库不满足而终止,至于为什么缺少相应的依赖,这里占空后续排查。

安装二进制包ffmpeg 4.2.7-nvidia行不通,那么这里就准备源码编译ffmpeg 4.2.7-nvidia

sudo apt install autoconf automake build-essential pkg-config
sudo apt install libx264-dev libx265-dev libfreetype6-dev libv4l-dev zlib1g-dev

apt source ffmpeg
tar -xvf ffmpeg_4.2.7-nvidia.tar.xz

mkdir -p ffmpeg-4.2.7/build
cd ffmpeg-4.2.7/build
../configure --prefix=/usr/local/ffmpeg --disable-doc --enable-gpl --enable-libx265 --enable-libx264 --enable-libfreetype --enable-nvv4l2dec --enable-libv4l2 --extra-libs="-L/usr/lib/aarch64-linux-gnu/tegra -lnvbuf_utils" --extra-cflags="-I /usr/src/jetson_multimedia_api/include/"
make -j 6 install

然鹅编译完成后,通过./ffmpeg -codecs | grep h264查看支持H264编解码方式,DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_nvv4l2dec ) (encoders: libx264 libx264rgb h264_v4l2m2m ),会发现NVIDIA ffmpeg包支持硬件解码,不支持硬件编码。看看在Jetson平台上支持硬件编解码要另寻他途。

基于nvmpi库的硬件编解码支持

  • https://github.com/jocover/jetson-ffmpeg
    • 大神公开的libnvmpi源码,基于此库扩展ffmpeg在Jetson平台下的硬件支持能力
  • https://github.com/LinusCDE/mad-jetson-ffmpeg
    • 将NVIDIA提供ffmpeg硬件支持以及libnvmpi提供的硬件支持打包到ffmpeg库中,具体可以查看Changes中的说明,以及最新提交编解码扩展。
    • 扩展打包支持ffmpeg 4.4.1以及6.0两个分支
git clone https://github.com/jocover/jetson-ffmpeg.git
git clone https://github.com/LinusCDE/mad-jetson-ffmpeg.git

mkdir -p jetson-ffmpeg/build
pushd jetson-ffmpeg/build
cmake -DCMAKE_INSTALL_PREFIX=/opt/ffmpeg_jetson ..
sudo make install
popd

mkdir -p mad-jetson-ffmpeg/build
pushd mad-jetson-ffmpeg/build
PKG_CONFIG_PATH=/opt/ffmpeg_jetson/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}} ../configure --prefix=/opt/ffmpeg_jetson --disable-doc --disable-static --enable-shared --enable-gpl --enable-libx265 --enable-libx264 --enable-libfreetype --enable-nvmpi --enable-nvv4l2dec --enable-libv4l2 --extra-libs="-L/usr/lib/aarch64-linux-gnu/tegra -lnvbuf_utils" --extra-cflags="-I /usr/src/jetson_multimedia_api/include/"
sudo make -j6 install
popd

遇到的问题

  • 消除告警 nvbuf_utils: Could not get EGL display connection
    • unset DISPLAY
  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 33
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

callinglove

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值