Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3977313
  • 博文数量: 366
  • 博客积分: 9916
  • 博客等级: 中将
  • 技术积分: 7195
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-29 23:27
个人简介

简单!

文章分类

全部博文(366)

文章存档

2013年(51)

2012年(269)

2011年(46)

分类: LINUX

2013-01-08 22:40:27

一、移除原有的ffmpeg

ffmpeg的更新很快,接口很有可能已经改变。所以,首先去除系统中已有的相关库,并下载依赖。

  1. $ sudo apt-get remove ffmpeg x264 libvpx-dev libx264-dev
  2. $ sudo apt-get update
  3. $ sudo apt-get -y install build-essential checkinstall git libfaac-dev libgpac-dev \
  4. libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev \
  5. libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev \
  6. libxfixes-dev texi2html yasm zlib1g-dev


二、编译相关库

x264

x264是编解码H.264/AVC流需要的开源库。

  1. $ git clone git://git.videolan.org/x264
  2. $ cd x264
  3. $ ./configure --enable-static
  4. $ make
  5. $ sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
  6. awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
  7. --fstrans=no --default

libvpx

VP8需要使用libvpx编解码。如果git下载不了,可以去google code里面下载:

  1. $ cd ..
  2. $ git clone
  3. $ cd libvpx
  4. $ ./configure
  5. $ make
  6. $ sudo checkinstall --pkgname=libvpx --pkgversion="1:$(date +%Y%m%d%H%M)-git" --backup=no \
  7. --deldoc=yes --fstrans=no --default

ffmpeg
  1. $ cd ..
  2. $ git clone --depth 1 git://source.ffmpeg.org/ffmpeg
  3. $ cd ffmpeg
  4. $ ./configure --enable-libfaac --enable-memalign-hack --enable-gpl \
        --enable-libtheora --enable-libmp3lame --enable-libvorbis \
        --enable-libx264 --enable-nonfree --enable-postproc --enable-avfilter \
        --enable-swscale
  5. $ make
  6. $ 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源码

  1. #include "libavcodec/avcodec.h"
  2. #include "libavformat/avformat.h"

  3. int main(int argc, char *argv[]) {
  4.     av_register_all();
  5. }
Makefile
由于ffmpeg提供了很多动态库,首先需要指定gcc编译、链接的参数,这个可以用pkg-config命令来获取。

  1. # use pkg-config for getting CFLAGS and LDLIBS
  2. FFMPEG_LIBS= libavformat \
  3. libavcodec \
  4. libavutil

  5. CFLAGS += -Wall -O2 -g
  6. CFLAGS += $(shell pkg-config --cflags $(FFMPEG_LIBS))
  7. LDLIBS += $(shell pkg-config --libs $(FFMPEG_LIBS))
  8. EXAMPLES= player \

  9. OBJS=$(addsuffix .o,$(EXAMPLES))

  10. # the following examples make explicit use of the math library
  11. #main: LDLIBS += -lm

  12. %: %.o
  13. $(CC) $< $(LDLIBS) -o $@

  14. %.o: %.c
  15. $(CC) $< $(CFLAGS) -c -o $@

  16. .phony: all help show clean

  17. all: $(OBJS) $(EXAMPLES)
  18. help:
  19. @echo "Makefile for ffmpeg and SDL Programs version 1.0"
  20. @echo "Usage: make [TARGET]"
  21. @echo "TARGETS:"
  22. @echo " all (=make) compile and link."
  23. @echo " clean clean objects and the executable file."
  24. @echo " show show variables (for debug use only)."
  25. @echo " help print this message."
  26. show:
  27. @echo "CFLAGS :" $(CFLAGS)
  28. @echo "LDLIBS :" $(LDLIBS)
  29. clean:
  30. rm -rf $(EXAMPLES) $(OBJS)
编译
  1. $ make
  2. 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

  1. $ 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
阅读(20623) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

txgc_wm2013-01-11 22:29:18

视频流测试资源:http://samples.mplayerhq.hu/