1. PC环境
2. ffmpeg 下载安装
$ git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
$ cd ffmpeg
$ ./configure --enable-shared --prefix=/usr/local/ffmpeg
$ sudo make
$ sudo make install
3. 添加ffmpeg库链接
$ cd /etc/ld.so.conf.d/
$ sudo echo " /usr/local/ffmpeg/lib" >> ffmpeglib.conf
4. 支持pkg-config
$ export PKG_CONFIG_PATH=/usr/local/ffmpeg/lib/pkgconfig:$PKG_CONFIG_PATH
5. 测试
ffmpeg_version.c
#include <stdio.h>
#include <stdlib.h>
#include <libavformat/avformat.h>
int main()
{
unsigned int ver=0;
av_register_all();
ver=avformat_version();
av_log(NULL,AV_LOG_INFO,"%d\n",ver);
return 0;
}
编译
gcc
$ gcc -g -o ffmpeg_version ffmpeg_version.c -I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavformat -lavutil
Makefile
FFMPEG=/usr/local/ffmpeg
CC=gcc
CFLAGS=-I$(FFMPEG)/include
LDFLAGS=-L$(FFMPEG)/lib/ -lswscale -lswresample -lavformat -lavdevice -lavcodec -lavutil -lavfilter -lm
TARGETS=ffmpeg_version
$(TARGETS):ffmpeg_version.c
$(CC) -g -o $@ $^ $(CFLAGS) $(LDFLAGS)
clean:
rm -rf $(TARGETS)
$ make
pkg-config
$ gcc -g -o ffmpeg_version ffmpeg_version.c `pkg-config --cflags --libs libavformat libavutil`
6. 存在的问题
- pkg-config 自动查找路径应该是安装路径,但结果是:
$ pkg-config --cflags --libs libavformat libavutil
-I/usr/include/x86_64-linux-gnu -lavformat -lavutil
7. 学习计划
$ export PKG_CONFIG_PATH=/usr/local/ffmpeg/lib/pkgconfig:$PKG_CONFIG_PATH
$ pkg-config --cflags --libs libavformat
-I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavformat -lXv -lX11 -lXext -lSDL2 -lxcb -lxcb-shm -lxcb-xfixes -lxcb-shape -lsndio -lasound -lSDL2 -lm -ldl -llzma -lbz2 -lz -pthread -lavcodec -lXv -lX11 -lXext -lSDL2 -lxcb -lxcb-shm -lxcb-xfixes -lxcb-shape -lsndio -lasound -lSDL2 -lm -ldl -llzma -lbz2 -lz -pthread -lswresample -lm -lavutil -lm
# use pkg-config for getting CFLAGS and LDLIBS
FFMPEG_LIBS= libavdevice \
libavformat \
libavfilter \
libavcodec \
libswresample \
libswscale \
libavutil \
sdl \
CFLAGS += -Wall -g
INCLUDES:=$(shell pkg-config --cflags libavformat libavcodec libswscale libavutil sdl)
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
LDFLAGS:=$(shell pkg-config --libs libavformat libavcodec libswscale libavutil libswresample sdl) -lm
LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
EXE:= muxing.out demo.out
#OBJS=$(addsuffix .o,$(EXAMPLES))
# the following examples make explicit use of the math library
# decoding_encoding: LDLIBS += -lm
muxing: LDLIBS += -lm
#.phony: all clean-test clean
#all: $(OBJS) $(EXAMPLES)
all: dirs $(addprefix bin/, $(EXE)) tags
dirs:
mkdir -p obj
mkdir -p bin
tags: *.c
ctags *.c
bin/%.out: obj/%.o
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
obj/%.o : %.c
$(CC) $(CFLAGS) $< $(INCLUDES) -c -o $@
#clean-test:
#$(RM) test*.pgm test.h264 test.mp2 test.sw test.mpg
#clean: clean-test
#$(RM) $(EXAMPLES) $(OBJS)
clean:
rm -f obj/*
rm -f bin/*
rm -f tags