注:可直接下载我上传的CSDN资源,然后直接跳到"一"中的第"3"项"将文件按以下顺序存放"。
ffmpeg源码:音视频开发+ffmpeg+编译所需资源文件
其他文件:音视频开发+ffmpeg+x86/Arm+编译所需库文件(fdk-aac-2.0.2,lame-3.99.5,opencore)
nvidia硬件加速文件:音视频开发+ffmpeg+x86/Arm+编译所需文件(使用nvidia硬件加速)
官网下载
网址:
http://ffmpeg.org/download.html#releases
操作:
点击FFmpeg 4.4.3 “Rao"下的"Download xz tarball”
下载得到ffmpeg-4.4.3.tar.xz压缩文件
注:本教程使用的ffmpeg4.4.3,官网找不到也可以使用其他版本。
官网下载
网址:
https://www.linuxfromscratch.org/blfs/view/svn/multimedia/fdk-aac.html
官网下载
网址:
https://sourceforge.net/projects/lame/files/lame/3.99/
官网下载
网址:
https://sourceforge.net/projects/opencore-amr/files/opencore-amr/
执行
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
新建"ffmpeg"目录与"ffmpegOtherFiles"目录
mkdir ffmpeg && \
mkdir -p ffmpeg/ffmpegOtherFiles
"ffmpeg-4.4.3.tar.xz"放入ffmpeg目录
“fdk-aac-2.0.2.tar.gz”,“lame-3.99.5.tar.gz”,"opencore-amr-0.1.6.tar.gz"放入ffmpegOtherFiles目录
"nv-codec-headers.zip"放入ffmpeg目录
sudo apt update && \
sudo apt upgrade -y && \
sudo apt install -y build-essential cmake python
sudo apt install -y gnutls-dev \
libass-dev \
libdrm-dev \
libopus-dev \
libpulse-dev \
libspeex-dev \
libtheora-dev \
libtwolame-dev \
libv4l-dev \
libvorbis-dev \
libvpx-dev \
libx264-dev \
libx265-dev \
libxvidcore-dev \
libopenal-dev \
libomxil-bellagio-dev \
libxcb1-dev \
libsdl2-dev \
libva-dev \
libvdpau-dev
进入"ffmpegOtherFiles"目录
cd ffmpeg/ffmpegOtherFiles
解压编译安装依赖
tar -xvf fdk-aac-2.0.2.tar.gz && \
cd fdk-aac-2.0.2 && \
./configure --prefix=/usr --disable-static && \
make -j12 && \
sudo make install && \
cd .. && \
tar -xvf lame-3.99.5.tar.gz && \
cd lame-3.99.5 && \
./configure --prefix=/usr --disable-static && \
make -j12 && \
sudo make install && \
cd .. && \
tar -xvf opencore-amr-0.1.6.tar.gz && \
cd opencore-amr-0.1.6 && \
./configure --prefix=/usr --disable-static && \
make -j12 && \
sudo make install
cd ffmpeg
unzip nv-codec-headers.zip
cd nv-codec-headers
make -j $(nproc)
sudo make install
cd ffmpeg
tar -xvf ffmpeg-4.4.3.tar.xz
cd ffmpeg-4.4.3
sed -i "s/compute_30,code=sm_30/compute_86,code=sm_86/g" configure
注:电脑显卡为3050,所以是86,需要根据你的显卡算力进行修改
可在此网站查看:显卡算力查看
./configure --prefix=/usr/local/ffmpeg \
--disable-debug \
--disable-doc \
--disable-static \
--enable-cuda-nvcc \
--enable-cuvid \
--enable-libdrm \
--enable-ffplay \
--enable-gnutls \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libfontconfig \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libnpp \
--enable-libopencore_amrnb \
--enable-libopencore_amrwb \
--enable-libopus \
--enable-libpulse \
--enable-sdl2 \
--enable-libspeex \
--enable-libtheora \
--enable-libtwolame \
--enable-libv4l2 \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-libxcb \
--enable-libxvid \
--enable-nonfree \
--enable-nvenc \
--enable-omx \
--enable-openal \
--enable-opencl \
--enable-runtime-cpudetect \
--enable-shared \
--enable-vaapi \
--enable-vdpau \
--enable-version3 \
--enable-xlib \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 \
--libdir=/usr/lib/x86_64-linux-gnu \
--incdir=/usr/include/x86_64-linux-gnu \
--disable-asm \
--disable-x86asm \
--extra-cflags=-fPIC \
--toolchain=hardened \
--disable-stripping \
--extra-cflags=-I/usr/local/include/ffnvcodec
make -j $(nproc)
sudo make install
sudo ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/bin/ffmpeg && \
sudo ln -s /usr/local/ffmpeg/bin/ffprobe /usr/bin/ffprobe && \
sudo ln -s /usr/local/ffmpeg/bin/ffplay /usr/bin/ffplay && \
sudo ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/ffmpeg && \
sudo ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/ffprobe && \
sudo ln -s /usr/local/ffmpeg/bin/ffplay /usr/local/bin/ffplay
写入设置
sudo sh -c "echo '/usr/local/ffmpeg/lib' >> /etc/ld.so.conf.d/ffmpeg.conf"
更新设置
sudo ldconfig
查看ffmpeg支持信息
ffmpeg -hwaccels
执行结果如下:
ffmpeg version 4.4.3 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr/local/ffmpeg --disable-debug --disable-doc --disable-static --enable-cuda-nvcc --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --disable-asm --disable-x86asm --extra-cflags=-fPIC --toolchain=hardened --disable-stripping --extra-cflags=-I/usr/local/include/ffnvcodec
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Hardware acceleration methods:
vdpau
cuda(使用nvidia硬件加速才有)
vaapi
drm
opencl
编解码测试(使用nvidia硬件加速):
HEVC->H.264
ffmpeg -vcodec hevc_cuvid -an -gpu 0 -i -vcodec h264_nvenc -an -gpu 0 -y output.mp4
H.264->HEVC
ffmpeg -vcodec h264_cuvid -an -gpu 0 -i -vcodec hevc_nvenc -an -gpu 0 -y output.mp4
Ubuntu系统+x86架构+编译安装ffmpeg+带有nvidia硬件加速-完毕