FFmpeg基础总结

FFmpeg 环境准备以及编译

sudo apt-get -y install autoconf automake 
sudo apt-get install aptitude
sudo apt-get install libtool
sudo apt install yasm
sudo aptitude install libfaac-dev
sudo aptitude install libmp3lame-dev
sudo aptitude install libx264-dev

wget http://downloads.xiph.org/releases/speex/speexdsp-1.2.0.tar.gz
tar -zxvf speexdsp-1.2.0.tar.gz
./configure --prefix=/usr/local/   --enable-shared
sudo make 
sudo make install

wget http://downloads.us.xiph.org/releases/speex/speex-1.2.0.tar.gz
./configure --prefix=/usr/local/ 
sudo make 
sudo make install

wget https://nchc.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-2.0.1.tar.gz
./configure --prefix="/usr/local"
make
make install
make distclean

wget https://bitbucket.org/multicoreware/x265/downloads/x265_3.2.1.tar.gz
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/ source/
sudo make
sudo make install

wget http://libsdl.org/release/SDL2-2.0.10.tar.gz
cd SDL2-2.0.10/
./configure --prefix=/usr/local/
make
sudo make install

cd ~/work/project/FFmpeg
git checkout release/4.2
 ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-ffplay --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-cross-compile --host-cflags= --host-ldflags=
sudo make && sudo make install

sudo vim /etc/profile
  //加入环境变量
  export PATH="/usr/local/ffmpeg/bin:$PATH"

source /etc/profile

Error:

ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory

sudo vim /etc/ld.so.conf

  include ld.so.conf.d/*.conf
  /usr/local/ffmpeg/lib

ldconfig

FFMPEG常用命令

  • 分解/复用
ffmpeg -i out.mp4 -vcodec copy -acodec copy out.mov
-i  输入文件
-vcodec copy
-acodec copy

ffmpeg -i out.mp4 -an -vcodec copy out.h264
ffmpeg -i out.mp4 -acodec -vn copy out.aac
  • 原始数据
//提取YUV数据   yuv444p yuv422p 不常用
ffmpeg -i input.mp4 -an -c:v rawvideo -pix_fmt yuv420p out.yuv
//播放原始数据YUV需要指定分辨率大小
ffplay -s 1920x1080 out.yuv
//提取PCM数据   -ar: audio rate (44.1K 48K 32K 16K)  -ac : audio channel(单声道:左,右声道) -f : pcm 数据格式 s16le 符号 16位
ffmpeg -i out.mp4 -vn -ar 44100 -ac 2 -f s16le out.pcm
ffplay -ar 44100 -ac 2 -f s16le out.pcm
  • 滤镜

    对解码后的数据帧过滤,对过滤后的数据编码输出

//-vf : 视频滤镜        crop:out_w:out_y:x:y   视频编码器
ffmpeg -i in.mov -vf crop=in_w-200:in_h-200 -c:v libx264 -c:a copy out.mp4
  • 裁剪与合并

    裁剪几秒视频,几个小视频合并到一个视频

//从00:00:00 裁剪10秒
ffmpeg -i in.mp4 -ss 00:00:00 -t 10 out.ts
//concat -i 对后面的文件进行拼接 input.txt 内容格式 'file filename'
ffmpeg -f concat -i inputs.txt out.flv
  • 图片与视频互转
//-r 转换图片的帧率每秒1张 文件格式
ffmpeg -i in.flv -r 1 -f image2 image-%3d.jpeg
ffmpeg -i image-%3d.jpeg out.mp4

你可能感兴趣的:(FFmpeg基础总结)