FFmpeg简介
FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。
ubuntu下FFmpeg下载、编译并安装
1.基础依赖库安装
sudo apt-get update
sudo apt-get install -y \
autoconf \
automake \
build-essential \
cmake \
git-core \
libass-dev \
libfreetype6-dev \
libsdl2-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
pkg-config \
texinfo \
wget \
zlib1g-dev
2.汇编安装
NASM YASM-- 部分库使用到汇编程序,需要安装
sudo apt-get install -y nasm
sudo apt-get install -y yasm
3. 解码器安装
3.1 libx264 – H.264视频编码器
sudo apt-get install -y libx264-dev
3.2 libx265 – H.265视频编码器
sudo apt-get install -y libx265-dev libnuma-dev
3.3 AAC MP3音频解码器安装
sudo apt-get install -y libfdk-aac-dev
sudo apt-get install -y libmp3lame-dev
3.4下载并解压
wget https://ffmpeg.org/releases/ffmpeg-4.3.1.tar.bz2
tar xvf ffmpeg-4.3.1.tar.bz2
cd ffmpeg-4.3.1
3.5配置FFmpeg
./configure --enable-gpl \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree \
--enable-shared \
--prefix=/usr
3.6编译与安装
make -j8
make install
4.编写Hello world
编写一个Hello world,测试程序正确性
/
// \date
// \note 测试动态链接库能否正常链接
/
#include <iostream>
using namespace std;
#define __STDC_CONSTANT_MACROS
extern "C" {
#include "libavutil/avutil.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
};
int main(){
av_register_all();
cout<<"Hello world"<<endl;
}
Makefile
all:
g++ -w -o helloworld helloworld.cpp -lavformat -lavcodec -lswscale -lswresample -lavutil
如果编译成功,证明FFmpeg环境搭建完毕!