ffmpeg的常用功能


cuda版安装https://blog.csdn.net/TracelessLe/article/details/108205992

使用gpu加速

参考自https://developer.nvidia.com/blog/nvidia-ffmpeg-transcoding-guide/

  1. 安装驱动。

  2. 安装cuda。

    https://developer.nvidia.com/cuda-toolkit下载。例如

    wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_530.30.02_linux.run
    sudo sh cuda_12.1.0_530.30.02_linux.run

    安装完成后会显示

    ===========
    = Summary =
    ===========
    
    Driver:   Installed
    Toolkit:  Installed in /usr/local/cuda-12.1/
    
    Please make sure that
     -   PATH includes /usr/local/cuda-12.1/bin
     -   LD_LIBRARY_PATH includes /usr/local/cuda-12.1/lib64, or, add /usr/local/cuda-12.1/lib64 to /etc/ld.so.conf and run ldconfig as root
    
    To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-12.1/bin
    To uninstall the NVIDIA Driver, run nvidia-uninstall
    Logfile is /var/log/cuda-installer.log
  3. 安装必要的东西

    sudo apt install -y  nasm yasm
  1. ./configure --enable-cuda --enable-cuvid --enable-nvdec --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include  --extra-ldflags=-L/usr/local/cuda/lib64

视频格式转换

  1. mov转mp4

    ffmpeg -i {in-video}.mov -vcodec h264 -acodec aac {out-video}.mp4

    使用gpu进行编解码。

    ffmpeg -hwaccel cuvid -c:v h264_cuvid  -i test3.mov  -acodec aac -c:v h264_nvenc -y test3.mp4

    ffmpeg -hwaccel cuvid -c:v h264_cuvid -i pred-450.mp4 -c:v hevc_nvenc -y test-gpu.mp4

  1. 视频合并与分割

  2. 视频的合并使用以下方法:

    创建一个文本文件,内容如下:

    # this is a comment
    file ‘/path/to/file1’
    file ‘/path/to/file2’
    file ‘/path/to/file3’

    然后使用命令进行合并:

    ffmpeg -f concat -i ~/Downloads/mylist.txt -c copy ~/Downloads/noname.mov

    或者更简单的一个命令搞定:

    ffmpeg -i “concat:noname1.mov|noname2.mov” -c copy noname.mov

裁剪视频

ffmpeg -ss 00:00:00 -t 00:00:30 -i test.mp4 -vcodec copy -acodec copy output.mp4
* -ss 指定从什么时间开始
* -t 指定需要截取多长时间
* -i 指定输入文件
ffmpeg -i input.wmv -ss 30 -c copy -to 40 output.wmv
也可以用 -ss 和 -to 选项, 从第 30 秒截取到第 40 秒

配合编码一起使用,裁剪出来后直接进行编码

ffmpeg -ss 00:00:00 -t 00:00:30 -i test.mp4 -vcodec h264 -acodec aac output.mp4

评论
评论
  目录