centos7安装支持gpu加速的ffmpeg

阿里云ECS环境说明:

  • 规格:ecs.gn6i-c16g1.4xlarge
  • 显卡:T4
  • 镜像:centos7.5

安装显卡驱动

  1. 前往 NVIDIA官网 填写选项并下载驱动。

  2. 如果想与我的一致(CUDA版本:12.2),可直接执行以下命令:

    wget https://cn.download.nvidia.com/tesla/535.104.05/NVIDIA-Linux-x86_64-535.104.05.run
    chmod +x NVIDIA-Linux-x86_64-535.104.05.run
    sh NVIDIA-Linux-x86_64-535.104.05.run
    
  3. 验证安装:

    nvidia-smi
    

安装ffnvcodec

  1. 安装git:

    yum install git
    
  2. 克隆nv-codec-headers库:

    git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
    cd nv-codec-headers
    
  3. 编译和安装:

    make
    make install
    

安装CUDA

  1. 前往 NVIDIA官网 下载CUDA安装包。

  2. 安装CUDA:

    wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
    sh cuda_12.2.0_535.54.03_linux.run  (安装时第一步填accept,第二步选最下面的install)
    
  3. 添加以下环境变量到/etc/profile文件中:

    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    export PATH=/usr/local/cuda/bin:$PATH
    export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
    
  4. 使环境变量生效:

    source /etc/profile
    
  5. 验证CUDA安装:

    nvcc -V
    

安装cuDNN

  1. 前往 NVIDIA官网 下载cuDNN。

  2. 解压并复制文件:

    tar -xvf cudnn-linux-x86_64-8.9.2.26_cuda12-archive.tar.xz
    cd cudnn-linux-x86_64-8.9.2.26_cuda12-archive
    cp lib/* /usr/local/cuda/lib64/
    cp include/* /usr/local/cuda/include/
    

安装FFmpeg

  1. 安装基本开发工具:

    sudo yum groupinstall "Development Tools"
    
  2. 安装RPM Fusion存储库:

    sudo yum install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
    sudo yum install -y https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
    
  3. 安装编解码库和依赖:

    sudo yum install fdk-aac-devel
    sudo yum install x264-devel
    sudo yum install yasm
    
  4. 下载FFmpeg源码:

    git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/
    cd ffmpeg
    
  5. 配置FFmpeg:

    ./configure --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
    
  6. 编译和安装:

    make -j$(nproc)
    make install
    
  7. 验证FFmpeg安装:

    ffmpeg -hwaccels
    ffmpeg -codecs | grep "h264"
    

    如果遇到 "libavdevice.so.60: cannot open shared object file" 错误,可以使用以下命令修复:

    sudo find / -name "libavdevice.so.60"
    export LD_LIBRARY_PATH=/root/ffmpeg/libavdevice:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
posted @ 2023-09-01 13:53  剑小破  阅读(563)  评论(1编辑  收藏  举报