NVENC ENDEC 硬件编解码
NVENC: AV1、H264、H265
ENDEC: AV1、H264、H265、VP8、VP9、VC1、MPEG-2
jetson编译ffmpeg
NVIDIA Jetson 系列采用nvmpi使用FFmpeg进行视频编码和解码的硬件加速功能环境配置说明
jetson-ffmpeg链接,支持的 Jetson/JetPack 版本如图所示:
默认安装
sudo apt install libx264-dev libx265-dev libfreetype6-dev libv4l-dev zlib1g-dev
下载编译安装jetson-ffmpeg
下载支持FFmpeg的nvmpi,ffmpeg的补丁
ffmpeg
支持nvmpi
需要打补丁,根据jetson-ffmpeg
源码的ffmpeg_patches
补丁包,目前只支持ffmpeg
的版本有 4.2、4.4、6.0
#git clone https://github.com/jocover/jetson-ffmpeg.git
git clone https://github.com/Keylost/jetson-ffmpeg.git
cd jetson-ffmpeg
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig
默认安装在/usr/local/lib
和 /usr/local/include
x264编译安装
git clone https://gitee.com/mirrors/x264/tree/stable/
cd x264-stable
mkdir myinstalled
./configure --enable-static --enable-shared --enable-debug
make -j8
make install
下载编译安装ffmpeg
下载FFmpeg4.4
git clone git://source.ffmpeg.org/ffmpeg.git -b release/4.4 --depth=1
将jetson-ffmpeg中的ffmpeg_nvmpi.patch文件拷贝至FFmpeg工程目录下,并执行
cd ffmpeg
cp /path_to/jetson-ffmpeg/ffmpeg_patches/ffmpeg4.4_nvmpi.patch ./
git apply ffmpeg4.4_nvmpi.patch
configure
#./configure --enable-static --enable-shared --prefix=/usr --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --disable-doc --enable-gpl --enable-libx265 --enable-libx264 --enable-libfreetype --enable-libv4l2 --extra-libs="-L/usr/lib/aarch64-linux-gnu/tegra -lnvbufsurface -lnvbufsurftransform -lnvv4l2 -L/usr/local/lib" --extra-cflags="-I /usr/src/jetson_multimedia_api/include/ -I /usr/local/include/" --enable-nvmpi --enable-sdl2
mkdir myinstalled
./configure --enable-shared --enable-static --enable-libx264 --enable-gpl --enable-nvmpi
make -j6
sudo make install
configure后,可以看到支持的解码器中(Enable decoders)中出现h264_nvmpi,即为配置成功
自定义安装
下载编译安装jetson-ffmpeg
下载支持FFmpeg的nvmpi,ffmpeg的补丁
#git clone https://github.com/jocover/jetson-ffmpeg.git
git clone https://github.com/Keylost/jetson-ffmpeg.git
cd jetson-ffmpeg
mkdir build
cd build
#cmake -D CMAKE_INSTALL_PREFIX=path/build/installed ..
mkdir myinstalled
cmake -D CMAKE_INSTALL_PREFIX=./myinstalled ..
make -j6
sudo make install
环境变量(编辑~/.bashrc):由于为自定义路径安装,需要将相关库路径添加入环境变量LD_LIBRARY_PATH中
也可以按照默认路径安装,改用cmake ..
x264编译安装
git clone https://gitee.com/mirrors/x264/tree/stable/
cd x264-stable
mkdir myinstalled
./configure --enable-static --enable-shared --enable-debug --prefix=./myinstalled
make -j8
make install
下载编译安装ffmpeg
git clone git://source.ffmpeg.org/ffmpeg.git -b release/4.4 --depth=1
将jetson-ffmpeg中的ffmpeg_nvmpi.patch文件拷贝至FFmpeg工程目录下,并执行
cd ffmpeg
cp ../jetson-ffmpeg-master/ffmpeg_patches/ffmpeg4.4_nvmpi.patch ./
git apply ffmpeg4.4_nvmpi.patch
mkdir myinstalled
configure
./configure --prefix=path/build/installed --enable-shared --enable-static --disable-debug --enable-gpl --enable-libx264 --extra-cflags=-Ix264_path/include --extra-ldflags=-Lx264_path/lib --extra-libs=-ldl --enable-nonfree --disable-x86asm --enable-ffmpeg --enable-nvmpi
or
./configure --extra-cflags="-I/home/nvidia/yfy/x264-stable/myinstalled/include" --extra-ldflags=-L/home/nvidia/yfy/x264-stable/myinstalled/lib --extra-libs=-llibx264 --enable-shared --enable-static --enable-libx264 --enable-gpl --enable-nvmpi --enable-nonfree --prefix=./myinstalled
configure后,可以看到支持的解码器中(Enable decoders)中出现h264_nvmpi,即为配置成功
make -j6
make install
环境变量(~/.bashrc):
由于为自定义路径安装,需要将相关库路径添加入环境变量LD_LIBRARY_PATH中
也可以按照默认路径安装,改用cmake ..
查看nvmpi
ffmpeg -encoders | grep 264
cd ffmpeg/myinstalled/bin
ffmpeg -h encoder=h264_nvmpi ## 通过运行以下命令来检查 FFmpeg 是否支持 NVENC
编译完成后, 查看支持H264编解码方式
./ffmpeg -codecs | grep h264
测试
ffmpeg -re -stream_loop -1 -i ~/yfy/test.mp4 -s 640x360 -r 15 -f rtsp rtsp://61.48.133.19/live/test
ffmpeg -rtsp_transport tcp -i rtsp://61.48.133.19/live/test -c:v h264_nvmpi -hls_time 10 -hls_list_size 1 -hls_flags delete_segments -f hls index.m3u8
运行jtop 查看 ,已经调用了硬编码
x264软编码器安装
git clone https://gitee.com/mirrors/x264/tree/stable/
./configure --enable-static --enable-shared --enable-debug --prefix=./bin_x264
make
make install
更改源码的编码器
// 将 AV_CODEC_ID_H264 配置API函数 改为 "h264_nvmpi" API函数
// AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_H264);
// if (!codec) {
// std::cerr << "AVCodec not found\n";
// return NULL;
// }
//改为
AVCodec* codec = avcodec_find_encoder_by_name("h264_nvmpi");
if (!codec) {
std::cerr << "AVCodec not found\n";
return NULL;
}
更改CMakeLists.txt
## 添加动态库,根据自己安装的路径配置即可
set(nvmpi_libs_DIR /home/nvidia/encode/jetson-ffmpeg-master/bin_nvmpi/lib) ## nvmpi
set(nvmpi_headers_DIR /home/nvidia/encode/jetson-ffmpeg-master/bin_nvmpi/include)
add_library(nvmpi SHARED IMPORTED )
set_target_properties(nvmpi PROPERTIES IMPORTED_LOCATION ${nvmpi_libs_DIR}/libnvmpi.so )
set(x264_libs_DIR /home/nvidia/encode/x264-stable/bin_x264/lib) ## x264
set(x264_headers_DIR /home/nvidia/encode/x264-stable/bin_x264/include)
add_library(x264 SHARED IMPORTED )
set_target_properties(x264 PROPERTIES IMPORTED_LOCATION ${x264_libs_DIR}/libx264.so )
set(ffmpeg_libs_DIR /home/nvidia/encode/ffmpeg/bin_ffmpeg/lib) ## ffmpeg
set(ffmpeg_headers_DIR /home/nvidia/encode/ffmpeg/bin_ffmpeg/include)
#对于find_package找不到的外部依赖库,可以用add_library添加
# SHARED表示添加的是动态库
# IMPORTED表示是引入已经存在的动态库
add_library( avcodec SHARED IMPORTED )
# #指定所添加依赖库的导入路径
set_target_properties( avcodec PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavcodec.so )
add_library( avfilter SHARED IMPORTED )
set_target_properties( avfilter PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavfilter.so )
add_library( swresample SHARED IMPORTED )
set_target_properties( swresample PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libswresample.so )
add_library( swscale SHARED IMPORTED )
set_target_properties( swscale PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libswscale.so )
add_library( avformat SHARED IMPORTED )
set_target_properties( avformat PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavformat.so )
add_library( avutil SHARED IMPORTED )
set_target_properties( avutil PROPERTIES IMPORTED_LOCATION ${ffmpeg_libs_DIR}/libavutil.so )
target_link_libraries(encode PRIVATE
${OpenCV_LIBS}
pthread
avformat avcodec x264 nvmpi avfilter avutil avdevice swscale swresample
)
参考
NVIDIA Jetson 系列采用nvmpi使用FFmpeg进行视频编码和解码的硬件加速功能环境配置说明_nvidia硬件对图像进行压缩编码-CSDN博客
ffmpeg使用NVIDIA Jeston Xavier NX 硬编码_jetson xavier nx ffmpeg-CSDN博客
方式2
sudo apt install libx264-dev libx265-dev libfreetype6-dev libv4l-dev zlib1g-dev
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
cd jetson-ffmpeg/build
cmake -DCMAKE_INSTALL_PREFIX=/opt/ffmpeg_jetson ..
sudo make install
mkdir -p mad-jetson-ffmpeg/build
cd 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
编译完成后,通过./ffmpeg -codecs | grep h264
查看支持H264编解码方式
Nvidia Jetson AGX Orin 基于NVJPG硬件编码的图像压缩实现
Nvidia Jetson AGX Orin 基于NVJPG硬件编码的图像压缩实现_jetson agx orin找不到nvjpeg.h头文件-CSDN博客
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » jetson nvidia 硬件编码, ffmpeg推流
发表评论 取消回复