一、移除原有的ffmpegffmpeg的更新很快,接口很有可能已经改变。所以,首先去除系统中已有的相关库,并下载依赖。
- $ sudo apt-get remove ffmpeg x264 libvpx-dev libx264-dev
- $ sudo apt-get update
- $ sudo apt-get -y install build-essential checkinstall git libfaac-dev libgpac-dev \
- libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev \
- libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev \
- libxfixes-dev texi2html yasm zlib1g-dev
二、编译相关库
x264
x264是编解码H.264/AVC流需要的开源库。
- $ git clone git://git.videolan.org/x264
- $ cd x264
- $ ./configure --enable-static
- $ make
- $ sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
- awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
- --fstrans=no --default
libvpx
VP8需要使用libvpx编解码。如果git下载不了,可以去google code里面下载:
- $ cd ..
- $ git clone
- $ cd libvpx
- $ ./configure
- $ make
- $ sudo checkinstall --pkgname=libvpx --pkgversion="1:$(date +%Y%m%d%H%M)-git" --backup=no \
- --deldoc=yes --fstrans=no --default
ffmpeg
- $ cd ..
- $ git clone --depth 1 git://source.ffmpeg.org/ffmpeg
- $ cd ffmpeg
- $ ./configure --enable-libfaac --enable-memalign-hack --enable-gpl \
--enable-libtheora --enable-libmp3lame --enable-libvorbis \
--enable-libx264 --enable-nonfree --enable-postproc --enable-avfilter \
--enable-swscale
- $ make
- $ sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" --backup=no \
--deldoc=yes --fstrans=no --default
sdl
sdl使用我们之前编译好的sdl1.2,具体参考http://blog.chinaunix.net/uid-25885064-id-3464743.html。
三、测试小例
player.c源码
- #include "libavcodec/avcodec.h"
- #include "libavformat/avformat.h"
- int main(int argc, char *argv[]) {
- av_register_all();
- }
Makefile
由于ffmpeg提供了很多动态库,首先需要指定gcc编译、链接的参数,这个可以用pkg-config命令来获取。
- # use pkg-config for getting CFLAGS and LDLIBS
- FFMPEG_LIBS= libavformat \
- libavcodec \
- libavutil
-
- CFLAGS += -Wall -O2 -g
- CFLAGS += $(shell pkg-config --cflags $(FFMPEG_LIBS))
- LDLIBS += $(shell pkg-config --libs $(FFMPEG_LIBS))
- EXAMPLES= player \
-
- OBJS=$(addsuffix .o,$(EXAMPLES))
-
- # the following examples make explicit use of the math library
- #main: LDLIBS += -lm
-
- %: %.o
- $(CC) $< $(LDLIBS) -o $@
-
- %.o: %.c
- $(CC) $< $(CFLAGS) -c -o $@
-
- .phony: all help show clean
-
- all: $(OBJS) $(EXAMPLES)
- help:
- @echo "Makefile for ffmpeg and SDL Programs version 1.0"
- @echo "Usage: make [TARGET]"
- @echo "TARGETS:"
- @echo " all (=make) compile and link."
- @echo " clean clean objects and the executable file."
- @echo " show show variables (for debug use only)."
- @echo " help print this message."
- show:
- @echo "CFLAGS :" $(CFLAGS)
- @echo "LDLIBS :" $(LDLIBS)
- clean:
- rm -rf $(EXAMPLES) $(OBJS)
编译
- $ make
- cc player.c -Wall -O2 -g -I/usr/local/include -c -o player.o
player.c: In function ‘main’:
player.c:28:24: warning: unused variable ‘t’ [-Wunused-variable]
cc player.o -pthread -L/usr/local/lib -lavformat -lavcodec -ldl -lva -ljack -lasound -lSDL -lx264 -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lmp3lame -lfaac -lz -lrt -lavutil -lm -o player
生成player可执行程序,由于gcc参数中加了-g,可以生成供调试的符号表,可以进行gdb调试的。
打印出CFLAGS和LDLIBS
- $ make show
CFLAGS: -Wall -O2 -g -I/usr/local/include
LDLIBS: -pthread -L/usr/local/lib -lavformat -lavcodec -ldl -lva -ljack -lasound -lSDL -lx264 -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lmp3lame -lfaac -lz -lrt -lavutil -lm
阅读(20707) | 评论(1) | 转发(1) |