目录
1.1.准备环境-安装yasm
这里我是直接通过ubuntu包安装的,当然也可以通过编译源码来安装。
sudo apt-get install yasm
sudo apt-get install pkg-config
也可以通过--disable-yasm不安装yasm
1.2.下载FFmpeg
1.2.1 git 下载
git clone https://git.ffmpeg.org/ffmpeg.git
1.2.2 http包下载(历史版本在这里都可以找到,而且不含版本控制信息,包也很小,推荐)
1.3配置、编译FFMPEG
1.3.1 386平台
./configure --prefix=../install --enable-shared --disable-static --disable-doc
关于FFMPEG的配置参数,我们可以通过下面命令来查看
./configure --help
然后执行
make && make install
1.3.2 arm平台配置
硬件是cortexa53的平台,需要编译一个64位的库,参数如下:
./configure --prefix=../instal_arm64 --enable-cross-compile --target-os=linux --cross-prefix=aarch64-linux-gnu- --cc=aarch64-linux-gnu-gcc --enable-static --cpu=cortex-a53 --arch=arm64
编译的过程有过 很多坑,如果你的平台和我有差异可以留言给我。
1.4 FFmpeg链接使用
gcc -I ../ffmpeg/install_386/include ffmpeg.c -o testFFMpeg -L ../ffmpeg/install_386/lib -lswscale -lavcodec -lavfilter -lavutil -lavdevice -lavformat -lm
1.5FFmpeg的版本差异
FFmpeg 3.x 之前称为旧版本,3.x之后称为新版本,具体可以 查看源码包里的sample实现
1.5.1 旧版本视频编码使用 avcodec_encode_video2,音频编码使用 avcodec_encode_audio2;新版本音视频编码统一使用 avcodec_send_frame 和 avcodec_receive_packet
1.5.2 旧版本 API 内部直接调用了 AVCodec 的函数指针 encode2;新版本 API 首先会判断编码器是否实现了函数指针 send_frame 和 receive_packet,如果实现了,优先使用send_frame 和 receive_packet,否则使用旧版本的 encode2
1.5.3 目前仅发现编码器 ff_hevc_nvenc_encoder 实现了新版本的 API(send_frame 和 receive_packet),libx264、AAC 等编码器依然使用了旧版本的 API(encode2)