单个编译ffmpeg/doc/examples下测试

Makefile.example内容如下

# use pkg-config for getting CFLAGS and LDLIBS
FFMPEG_LIBS=    libavdevice                        \
	                libavformat                        \
	                libavfilter                        \
	                libavcodec                      \
	                libswresample                 \
	                libswscale                       \
	                libavutil                          \
	                x264                   \
	                libpostproc         \
CFLAGS += -Wall -g
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
EXAMPLES=       avio_list_dir                      \
                avio_reading                       \
                decode_audio                       \
                decode_video                       \
                demuxing_decoding                  \
                encode_audio                       \
                encode_video                       \
                extract_mvs                        \
                filtering_video                    \
                filtering_audio                    \
                http_multiclient                   \
                hw_decode                          \
                metadata                           \
                muxing                             \
                remuxing                           \
                resampling_audio                   \
         scaling_video                      \
                transcode_aac                      \
                transcoding                        \
OBJS=$(addsuffix .o,$(EXAMPLES))
# the following examples make explicit use of the math library
avcodec:           LDLIBS += -lm
encode_audio:      LDLIBS += -lm
muxing:            LDLIBS += -lm
resampling_audio:  LDLIBS += -lm	
.phony: all clean-test clean
all: $(OBJS) $(EXAMPLES)
clean-test:
 $(RM) test*.pgm test.h264 test.mp2 test.sw test.mpg
 clean: clean-test
 $(RM) $(EXAMPLES) $(OBJS)

一、编译ffmpeg

编译x264脚本如下:

#!/bin/sh
CWD=$(cd "$(dirname "S0")";pwd)
echo $CWD
BUILD_INSTALL=$CWD/../ffmpeg_install
echo ${BUILD_INSTALL}
./configure --prefix=${BUILD_INSTALL} --enable-shared --enable-strip --disable-asm \
--bindir=${BUILD_INSTALL}/bin \
--libdir=${BUILD_INSTALL}/lib \
--includedir=${BUILD_INSTALL}/include
make
make install

编译ffmpeg脚本如下:

#!/bin/sh
CWD=$(cd "$(dirname "S0")";pwd)
echo $CWD
BUILD_INSTALL=$CWD/../ffmpeg_install 
export PKG_CONFIG_PATH=${BUILD_INSTALL}/lib/pkgconfig/
./configure --prefix=${BUILD_INSTALL} --enable-gpl --enable-ffplay --disable-x86asm --disable-static --enable-shared --enable-libx264 \
--logfile=${BUILD_INSTALL}/log \
--bindir=${BUILD_INSTALL}/bin \
--datadir=${BUILD_INSTALL}/share/ffmpeg \
--docdir=${BUILD_INSTALL}/share/doc/ffmpeg \
--libdir=${BUILD_INSTALL}/lib \
--incdir=${BUILD_INSTALL}/include \
make
make install

生成ffmpeg_install目录文件如下:

xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ ls
bin  include  lib  log  share
xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ ls bin/
ffmpeg  ffprobe  x264
xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ ls include/
libavcodec  libavdevice  libavfilter  libavformat  libavutil  libpostproc  libswresample  libswscale  x264_config.h  x264.h
xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ ls lib/
libavcodec.so            libavdevice.so.59.0.101  libavformat.so.59        libpostproc.so           libswresample.so.4.0.100  libx264.so.164
libavcodec.so.59         libavfilter.so           libavformat.so.59.9.102  libpostproc.so.56        libswscale.so             pkgconfig
libavcodec.so.59.14.100  libavfilter.so.8         libavutil.so             libpostproc.so.56.0.100  libswscale.so.6
libavdevice.so           libavfilter.so.8.19.100  libavutil.so.57          libswresample.so         libswscale.so.6.1.101
libavdevice.so.59        libavformat.so           libavutil.so.57.10.101   libswresample.so.4       libx264.so
xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ ls log 
log
xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ ls share/
doc  ffmpeg  man
xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ ls lib/pkgconfig/
libavcodec.pc  libavdevice.pc  libavfilter.pc  libavformat.pc  libavutil.pc  libpostproc.pc  libswresample.pc  libswscale.pc  x264.pc
xxx@xxx-virtual-machine:/home/share/project/video/ffmpeg_install$ 

二、编译example

把ffmpeg doc/exampes下的Makefile.example改写为Makefile
pkg-config这个东西,下面简单介绍一下。
g-config提供了下面几个功能:
检查库的版本号。如果所需要的库的版本不满足要求,它会打印出错误信息,避免链接错误版本的库文件。

2.获得编译预处理参数,如宏定义,头文件的位置。

3.获得链接参数,如库及依赖的其它库的位置,文件名及其它一些连接参数。
4.自动加入所依赖的其它库的设置

这一切都自动的,库文件安装在哪里都没关系!
makefile中的:$(shell pkg-config --cflags ( F F M P E G L I B S ) ) 这 句 的 意 思 是 在 T e r m i n a l ( 终 端 ) 中 输 入 : p k g − c o n f i g − − c f l a g s (FFMPEG_LIBS)) 这句的意思是在Terminal(终端)中输入:pkg-config --cflags (FFMPEGLIBS))Terminal()pkgconfigcflags(FFMPEG_LIBS),
这里的$(FFMPEG_LIBS)可以用FFMPEG_LIBS:libavdevice 、libavformat 、libavfilter、libavcodec 、libswresample 、libswscale 、libavutil 等等来代替。

可以输入命令试试:pkg-config --cflagslibavdevice 。
发现了跟make时候,差不多的一个错误:Packagelibavdevice was not found in the pkg-config search path.到错误,不过却很开心,起码找到了错误的来源,就是这个pkg-config,于是开始研究pkg-config的运行原理。
,为了让pkg-config可以得到这些信息,要求库的提供者,提供一个.pc文件,.pc文件里面存放的是一些头文件及库的地址。这些.pc文件默认放在/usr/share/pkgconfig里面,如果你改变了.pc的存放路径,必须要让计算机知道,所以需要修改 PKG_CONFIG_PATH 。

假设我的.pc文件放到了/home/share/project/video/ffmpeg_install/lib/pkgconfig下,我需要做如下修改:

xxx@xxx-virtual-machine:/home/share/project/video/test_ffmpeg/doc/examples$ export PKG_CONFIG_PATH=/home/share/project/video/ffmpeg_install/lib/pkgconfig:$PKG_CONFIG_PATH
 
xxx@xxx-virtual-machine:/home/share/project/video/test_ffmpeg/doc/examples$ make
xxx@xxx-virtual-machine:/home/share/project/video/test_ffmpeg/doc/examples$ ls
avio_list_dir    decode_video.c       encode_video.o     filtering_video.o   metadata        remuxing.c          transcode_aac.o
avio_list_dir.c  decode_video.o       extract_mvs        http_multiclient    metadata.c      remuxing.o          transcoding
avio_list_dir.o  demuxing_decoding    extract_mvs.c      http_multiclient.c  metadata.o      resampling_audio    transcoding.c
avio_reading     demuxing_decoding.c  extract_mvs.o      http_multiclient.o  muxing          resampling_audio.c  transcoding.o
avio_reading.c   demuxing_decoding.o  filter_audio.c     hw_decode           muxing.c        resampling_audio.o  vaapi_encode.c
avio_reading.o   encode_audio         filtering_audio    hw_decode.c         muxing.o        scaling_video       vaapi_transcode.c
decode_audio     encode_audio.c       filtering_audio.c  hw_decode.o         pc-uninstalled  scaling_video.c
decode_audio.c   encode_audio.o       filtering_audio.o  Makefile            qsvdec.c        scaling_video.o
decode_audio.o   encode_video         filtering_video    Makefile.example    README          transcode_aac
decode_video     encode_video.c       filtering_video.c  Makefile_file       remuxing        transcode_aac.c

发现,编译成功啦!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值