18、ubutnu20.04使用RTX3060硬件进行视频编解码+推流

2024-03-03 19:28

本文主要是介绍18、ubutnu20.04使用RTX3060硬件进行视频编解码+推流,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

基本思想:先进行环境配置,系统环境如下

RTX3060
ubuntu 20.04
cuda 12.2
cudnn 11.3
NVIDIA-SMI 535.146.02
tensorRT 8.6
nv-codec-headers
Video_Codec_SDK_12.0.16

注意:发现一个很有意思的问题,如果我使用命令行安装的ffmpeg,似乎已经有了nvidia编码器和解码器,完全不需要下面的操作似乎,我用代码也可以调用使用,这是没安装之前的环境配置

ubuntu@ubuntu:~$ ffmpeg -codecs | grep cuvid
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developersbuilt with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-sharedlibavutil      56. 31.100 / 56. 31.100libavcodec     58. 54.100 / 58. 54.100libavformat    58. 29.100 / 58. 29.100libavdevice    58.  8.100 / 58.  8.100libavfilter     7. 57.100 /  7. 57.100libavresample   4.  0.  0 /  4.  0.  0libswscale      5.  5.100 /  5.  5.100libswresample   3.  5.100 /  3.  5.100libpostproc    55.  5.100 / 55.  5.100DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_cuvid ) (encoders: libx264 libx264rgb h264_nvenc h264_omx h264_v4l2m2m h264_vaapi nvenc nvenc_h264 )DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_v4l2m2m hevc_cuvid ) (encoders: libx265 nvenc_hevc hevc_nvenc hevc_v4l2m2m hevc_vaapi )DEVIL. mjpeg                Motion JPEG (decoders: mjpeg mjpeg_cuvid ) (encoders: mjpeg mjpeg_vaapi )DEV.L. mpeg1video           MPEG-1 video (decoders: mpeg1video mpeg1_v4l2m2m mpeg1_cuvid )DEV.L. mpeg2video           MPEG-2 video (decoders: mpeg2video mpegvideo mpeg2_v4l2m2m mpeg2_cuvid ) (encoders: mpeg2video mpeg2_vaapi )DEV.L. mpeg4                MPEG-4 part 2 (decoders: mpeg4 mpeg4_v4l2m2m mpeg4_cuvid ) (encoders: mpeg4 libxvid mpeg4_v4l2m2m )D.V.L. vc1                  SMPTE VC-1 (decoders: vc1 vc1_v4l2m2m vc1_cuvid )DEV.L. vp8                  On2 VP8 (decoders: vp8 vp8_v4l2m2m libvpx vp8_cuvid ) (encoders: libvpx vp8_v4l2m2m vp8_vaapi )DEV.L. vp9                  Google VP9 (decoders: vp9 vp9_v4l2m2m libvpx-vp9 vp9_cuvid ) (encoders: libvpx-vp9 vp9_vaapi )
ubuntu@ubuntu:~$ ffmpeg -codecs |  grep nvenc
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developersbuilt with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-sharedlibavutil      56. 31.100 / 56. 31.100libavcodec     58. 54.100 / 58. 54.100libavformat    58. 29.100 / 58. 29.100libavdevice    58.  8.100 / 58.  8.100libavfilter     7. 57.100 /  7. 57.100libavresample   4.  0.  0 /  4.  0.  0libswscale      5.  5.100 /  5.  5.100libswresample   3.  5.100 /  3.  5.100libpostproc    55.  5.100 / 55.  5.100DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_cuvid ) (encoders: libx264 libx264rgb h264_nvenc h264_omx h264_v4l2m2m h264_vaapi nvenc nvenc_h264 )DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_v4l2m2m hevc_cuvid ) (encoders: libx265 nvenc_hevc hevc_nvenc hevc_v4l2m2m hevc_vaapi )

这是配置之后的环境变化

ubuntu@ubuntu:~$ ffmpeg -codecs | grep cuvid
ffmpeg version n6.1.1 Copyright (c) 2000-2023 the FFmpeg developersbuilt with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libfreetype --enable-libmp3lame --enable-libvpx --enable-libx264 --enable-libx265 --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-ffmpeg --enable-ffplay --enable-ffprobe --enable-libx264 --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64libavutil      58. 29.100 / 58. 29.100libavcodec     60. 31.102 / 60. 31.102libavformat    60. 16.100 / 60. 16.100libavdevice    60.  3.100 / 60.  3.100libavfilter     9. 12.100 /  9. 12.100libswscale      7.  5.100 /  7.  5.100libswresample   4. 12.100 /  4. 12.100libpostproc    57.  3.100 / 57.  3.100DEV.L. av1                  Alliance for Open Media AV1 (decoders: av1 av1_cuvid) (encoders: av1_nvenc)DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_cuvid) (encoders: libx264 libx264rgb h264_nvenc h264_v4l2m2m)DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_v4l2m2m hevc_cuvid) (encoders: libx265 hevc_nvenc hevc_v4l2m2m)DEVIL. mjpeg                Motion JPEG (decoders: mjpeg mjpeg_cuvid)DEV.L. mpeg1video           MPEG-1 video (decoders: mpeg1video mpeg1_v4l2m2m mpeg1_cuvid)DEV.L. mpeg2video           MPEG-2 video (decoders: mpeg2video mpegvideo mpeg2_v4l2m2m mpeg2_cuvid)DEV.L. mpeg4                MPEG-4 part 2 (decoders: mpeg4 mpeg4_v4l2m2m mpeg4_cuvid) (encoders: mpeg4 mpeg4_v4l2m2m)D.V.L. vc1                  SMPTE VC-1 (decoders: vc1 vc1_v4l2m2m vc1_cuvid)DEV.L. vp8                  On2 VP8 (decoders: vp8 vp8_v4l2m2m libvpx vp8_cuvid) (encoders: libvpx vp8_v4l2m2m)DEV.L. vp9                  Google VP9 (decoders: vp9 vp9_v4l2m2m libvpx-vp9 vp9_cuvid) (encoders: libvpx-vp9)
ubuntu@ubuntu:~$ ffmpeg -codecs |  grep nvenc
ffmpeg version n6.1.1 Copyright (c) 2000-2023 the FFmpeg developersbuilt with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libfreetype --enable-libmp3lame --enable-libvpx --enable-libx264 --enable-libx265 --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-ffmpeg --enable-ffplay --enable-ffprobe --enable-libx264 --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64libavutil      58. 29.100 / 58. 29.100libavcodec     60. 31.102 / 60. 31.102libavformat    60. 16.100 / 60. 16.100libavdevice    60.  3.100 / 60.  3.100libavfilter     9. 12.100 /  9. 12.100libswscale      7.  5.100 /  7.  5.100libswresample   4. 12.100 /  4. 12.100libpostproc    57.  3.100 / 57.  3.100DEV.L. av1                  Alliance for Open Media AV1 (decoders: av1 av1_cuvid) (encoders: av1_nvenc)DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_cuvid) (encoders: libx264 libx264rgb h264_nvenc h264_v4l2m2m)DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_v4l2m2m hevc_cuvid) (encoders: libx265 hevc_nvenc hevc_v4l2m2m)

所以搜索到类似的ubuntu 集成编译ffmpeg似乎没有必要,有点懵,且并不妨碍代码使用nvidia去解码和编码测试,所以下面编译方式可以直接忽视似乎

一、进行nv-codec-headers配置

ubuntu@ubuntu:~/nv-codec-headers$ cat README 
FFmpeg version of headers required to interface with Nvidias codec APIs.Corresponds to Video Codec SDK version 12.0.16.Minimum required driver versions:
Linux: 530.41.03 or newer
Windows: 531.61 or newerubuntu@ubuntu:~/nv-codec-headers$ sudo make install 
ubuntu@ubuntu:~/nv-codec-headers$ sudo vim ~/.bashrc 添加 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfigubuntu@ubuntu:~/nv-codec-headers$ source ~/.bashrc

二、进行video_codec_sdk配置

ubuntu@ubuntu:~/Downloads$  wget https://developer.nvidia.com/downloads/designworks/video-codec-sdk/secure/12.1/video_codec_sdk_12.1.14.zip
ubuntu@ubuntu:~/Video_Codec_SDK_12.0.16$ cat README #实际使用需要查看README对应的版本NVIDIA CUDA CUDNN 
然后解压之后
ubuntu@ubuntu:~/Video_Codec_SDK_12.0.16$ sudo cp Interface/* /usr/local/cuda/includeubuntu@ubuntu:~/Video_Codec_SDK_12.0.16$ sudo cp Lib/linux/stubs/x86_64/* /usr/local/cuda/lib64/stubs/

三、进行ffmpeg编译

​
ubuntu@ubuntu:~$ sudo apt-get install libtool automake autoconf nasm yasm
ubuntu@ubuntu:~$ sudo apt-get install libx264-dev
ubuntu@ubuntu:~$ sudo apt-get install libx265-dev
ubuntu@ubuntu:~$ sudo apt-get install libmp3lame-dev
ubuntu@ubuntu:~$ sudo apt-get install libvpx-dev
ubuntu@ubuntu:~$ sudo apt-get install libfaac-devubuntu@ubuntu:~$ git clone GitHub - FFmpeg/FFmpeg: Mirror of https://git.ffmpeg.org/ffmpeg.git
ubuntu@ubuntu:~/FFmpeg$ git checkout n6.0.1
Previous HEAD position was c9864adf34 release notes for 0.5.3
HEAD is now at e38092ef93 Changelog: update
在ffmpeg的configure中有这样的版本对应if ! disabled ffnvcodec; thenffnv_hdr_list="ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h"check_pkg_config ffnvcodec "ffnvcodec >= 12.0.16.0" "$ffnv_hdr_list" "" || \check_pkg_config ffnvcodec "ffnvcodec >= 11.1.5.2 ffnvcodec < 12.0" "$ffnv_hdr_list" "" || \check_pkg_config ffnvcodec "ffnvcodec >= 11.0.10.2 ffnvcodec < 11.1" "$ffnv_hdr_list" "" || \check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.14 ffnvcodec < 8.2" "$ffnv_hdr_list" ""
fiubuntu@ubuntu:~/FFmpeg$./configure  --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libfreetype --enable-libmp3lame --enable-libvpx --enable-libx264 --enable-libx265 --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-ffmpeg --enable-ffplay --enable-ffprobe --enable-libx264 --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
ubuntu@ubuntu:~/FFmpeg$ sudo vim /etc/ld.so.conf 添加: /usr/local/libubuntu@ubuntu:~/FFmpeg$ sudo ldconfig​

代码就放在这里了,使用显卡进行硬件编码和解码+yuv2bgr.cu+bgr2yuv.cu进行加速处理,然后进行视频推流,视频流畅且一点不卡顿,延迟只有1s之内,贴个地址https://github.com/sxj731533730/GPU_D_E_Rtserver_v2.git

这篇关于18、ubutnu20.04使用RTX3060硬件进行视频编解码+推流的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/770658

相关文章

C++中assign函数的使用

《C++中assign函数的使用》在C++标准模板库中,std::list等容器都提供了assign成员函数,它比操作符更灵活,支持多种初始化方式,下面就来介绍一下assign的用法,具有一定的参考价... 目录​1.assign的基本功能​​语法​2. 具体用法示例​​​(1) 填充n个相同值​​(2)

MySQL深分页进行性能优化的常见方法

《MySQL深分页进行性能优化的常见方法》在Web应用中,分页查询是数据库操作中的常见需求,然而,在面对大型数据集时,深分页(deeppagination)却成为了性能优化的一个挑战,在本文中,我们将... 目录引言:深分页,真的只是“翻页慢”那么简单吗?一、背景介绍二、深分页的性能问题三、业务场景分析四、

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

SpringBoot结合Docker进行容器化处理指南

《SpringBoot结合Docker进行容器化处理指南》在当今快速发展的软件工程领域,SpringBoot和Docker已经成为现代Java开发者的必备工具,本文将深入讲解如何将一个SpringBo... 目录前言一、为什么选择 Spring Bootjavascript + docker1. 快速部署与

深入理解Go语言中二维切片的使用

《深入理解Go语言中二维切片的使用》本文深入讲解了Go语言中二维切片的概念与应用,用于表示矩阵、表格等二维数据结构,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录引言二维切片的基本概念定义创建二维切片二维切片的操作访问元素修改元素遍历二维切片二维切片的动态调整追加行动态

prometheus如何使用pushgateway监控网路丢包

《prometheus如何使用pushgateway监控网路丢包》:本文主要介绍prometheus如何使用pushgateway监控网路丢包问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录监控网路丢包脚本数据图表总结监控网路丢包脚本[root@gtcq-gt-monitor-prome

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数

linux解压缩 xxx.jar文件进行内部操作过程

《linux解压缩xxx.jar文件进行内部操作过程》:本文主要介绍linux解压缩xxx.jar文件进行内部操作,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、解压文件二、压缩文件总结一、解压文件1、把 xxx.jar 文件放在服务器上,并进入当前目录#

SpringBoot中如何使用Assert进行断言校验

《SpringBoot中如何使用Assert进行断言校验》Java提供了内置的assert机制,而Spring框架也提供了更强大的Assert工具类来帮助开发者进行参数校验和状态检查,下... 目录前言一、Java 原生assert简介1.1 使用方式1.2 示例代码1.3 优缺点分析二、Spring Fr