PC环境: Ubuntu 16.04.3
编译步骤:
1, 安装相关工具:
sudo apt-get install -y autoconf automake build-essential git libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
sudo apt-get install -y nasam yasm cmake mercurial
2,git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg,得到文件夹ffmpeg,进入ffmpeg文件夹:
./configure --enable-shared --prefix=/usr/local/ffmpeg
安装到/usr/local/ffmpeg下,可通过“--prefix=安装目录”进行修改。--enable-shared:指定生成动态库,默认是静态库。静态库不方便后续开发。
make -j4
make install
3,添加ffmpeg库的链接:
在/etc/ld.so.conf中 末尾添加 /usr/local/ffmpeg/lib
执行
sudo ldconfig
4.安装VS Code
参考https://blog.csdn.net/u011258217/article/details/78693564
5.测试环境
#include <stdio.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavfilter/avfilter.h>
#define dbmsgc(fmt, args ...) printf("cong:%s[%d]: "fmt"\n", __FUNCTION__, __LINE__,##args)
//#define dbmsg(fmt, args ...) printf("cong:%s:%s[%d]: "fmt"\n",__FILE__, __FUNCTION__, __LINE__,##args)
int main(int argc, char **argv)
{
int i=0;
AVFormatContext *pFormatCtx = NULL;
avcodec_register_all();
#if CONFIG_AVDEVICE
avdevice_register_all();
#endif
avfilter_register_all();
av_register_all();
if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)
return -1; // Couldn't open file
if(avformat_find_stream_info(pFormatCtx, NULL)<0)
return -1; // Couldn't find stream inform
av_dump_format(pFormatCtx,0, 0, 0);
return 0;
}
6..编写Makefile
FFMPEG=/usr/local/ffmpeg
CC=gcc
CFLAGS=-g -I$(FFMPEG)/include
LDFLAGS = -L$(FFMPEG)/lib/ -lswscale -lswresample -lavformat -lavdevice -lavcodec -lavutil -lavfilter -lm
TARGETS=test
all: $(TARGETS)
test:test.c
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -std=c++11 #注意这里的-std=c++11
clean:
rm -rf $(TARGETS)
7.make
8../test test.flv