记录linux服务器安装ffmpeg进行视频压缩以及图片截取

安装ffmpeg命令,如下:

#!/usr/bin/env bash
# 源码编译ffmpeg静态库以及可执行文件
# 需要root权限
# 本脚本的最新版本请访问  https://pengrl.com/p/20029/

set -x

cd /usr/local/

# 编译yasm,ffmpeg依赖的汇编优化的库
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make
make install
cd ..

# 编译nasm,x264依赖的汇编优化的库
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.gz
tar xvf nasm-2.14.02.tar.gz
cd nasm-2.14.02/
./configure
make
make install
cd ..

# 编译x264
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar xvf x264-master.tar.bz2
cd x264-master/
./configure
make
make install-lib-static
cd ..

# 编译ffmpeg
wget https://ffmpeg.org/releases/ffmpeg-4.2.2.tar.bz2
tar xvf ffmpeg-4.2.2.tar.bz2
cd ffmpeg-4.2.2
./configure --disable-debug --enable-static --enable-libx264 --enable-gpl --extra-libs=-ldl --enable-openssl --enable-nonfree
make
make install
./ffmpeg

ffmpeg命令的使用,前面地址为原视频文件,后边地址为截取后图片的地址,或者压缩后的视频地址

截取封面(图片):
ffmpeg -i /www/wwwroot/web/kbjt/public/uploads/video/20221009/test33.mp4 -y -f image2 -ss 0:0:15 -vframes 1 /www/wwwroot/web/kbjt/public/uploads/img/20221009/test33.jpg
视频压缩:
ffmpeg -y -i /www/wwwroot/web/kbjt/public/uploads/video/20221009/test33.mp4 -r 10 -s 768x432 -b 500k /www/wwwroot/web/kbjt/public/uploads/video/20221009/test33-1.mp4

你可能感兴趣的:(ffmpeg,服务器,linux)