x264 代码重点详解 详细分析

eg mplayer x264 代码重点详解 详细分析

分类: ffmpeg 4229人阅读 评论(1) 收藏 举报

目录(?)[+]

ffmpeg和mplayer中求平均值得方法

1 ordinary c language level

#define avg2(a,b) ((a+b+1)>>1)
#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
显而易见...,注意a,b宏表达式可能引出的副作用

2 SIMD by software

实现方法1:
inline static uint64_t BYTE_VEC(uint64_t x)
{
    x |= x <<  8;
    x |= x << 16;
    x |= x << 32;
    return x;
}
static inline uint64_t avg2_no_rnd(uint64_t a, uint64_t b)
{
    return (a & b) + (((a ^ b) & BYTE_VEC(0xfe))>> 1);
}
static inline uint64_t avg2(uint64_t a, uint64_t b)
{
    return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >>1);
}

实现方法2:
#define op_avg_round(a,b)  a = ( ((a)|(b)) -((((a)^(b))&0xFEFEFEFEUL)>>1) )
#define op_avg_noround(a,b)  a = ( ((a)&(b)) + ((((a)^(b))&0xFEFEFEFEUL)>>1))
通 过软件实现 singl instruction multi data,单指令多数据流,上述实现方法一样方法1实现8个8bits宽度数据的同时平均,在64位cpu上使用方法2实现4个8bits宽度数据的同时 平均,在32位cpu上使用,简单对此加以分析加法结果有2个成分,1个是进位,1个是逻辑和((a)&(b))<<1是进位 (((a)^(b))是逻辑和((a)&(b))<<1 +(((a)^(b))&0xFEFEFEFEUL) 为和,各自右移一位得到平均值,之所以是0xFE..,因为把每个字节的最后一个bit置零以免移位时进入下一个字节影响下一个字节的值((a)| (b)) 对应位在 0 1, 1 0, 1 1的3种情况下都得到1,所以((a)|(b))<<1表示进位+非满进位,因为在0 1, 1 0这种情况下也产生了进位,刚好是它的逻辑和,其他分析同上

3 machine instruction levelAMD

3DNOW 指令:
#define AVG_3DNOW_OP(a,b,temp, size) /
"mov" #size " " #b ", " #temp "  /n/t"/
"pavgusb " #temp ", " #a"        /n/t"/
"mov" #size " " #a ", " #b"      /n/t"

intel MMX指令:
#define AVG_MMX2_OP(a,b,temp, size) /
"mov" #size " " #b ", " #temp "  /n/t"/
"pavgb " #temp ", " #a"          /n/t"/
"mov" #size " " #a ", " #b "     /n/t"

 

mplayer和ffmpeg的编译大全

MPlayer下载
http://www.mplayerhq.hu/design7/dload.html
目前版本MPlayer v1.0rc2

MPlayer编译
tar -xjvf MPlayer-1.0rc2.tar.bz2
cd MPlayer-1.0rc2
./configure
make
make install

如果出现以下错误
cabac.h: In function `get_cabac_noinline':
cabac.h:525: error: can't find a register in class `GENERAL_REGS' whilereloading `asm'
make[1]: *** [h264.o] 错误 1
在make前加入
export CFLAGS=-fomit-frame-pointer
make clean

 

ffmpeg的编译大全

1. 首先获取ffmpeg

很多人找不到怎么下载,其实之前ffmpeg可以通过cvs下载,不过最近他已经换成了更加强大的svn

如何使用SVN我这里不再介绍,网上还有大量的安装和使用的文章可以借鉴,这里简单罗列几个SVN辅助的软件:

SubVersion,从 http://subversion.tigris.org/ 下载,支持linux,我们这里就装这个

TortoiseSVN,从 http://tortoisesvn.tigris.org/ 下载,是很不错的SVN客户端程序,为windows外壳程序集成到windows资源管理器和文件管理系统的Subversion客户端,用起来很方便,commit动作变得就像Winrar右键压缩一样方便。


ok,那我们先装subversion,记住最好之前装过apr和apr-util,在apache.org网站能下到

wget http://subversion.tigris.org/downloads/subversion-1.3.2.tar.gz
tar zvxf subversion-1.3.2.tar.gz
cd subversion-1.3.2
./configure --with-apr=/usr/local/apr-httpd --with-apr-util=/usr/local/apr-util-httpd/
make
make install


到此,我们就可以通过svn命令获取最新的ffmpeg了

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

你会发现在你所在的目录,自动出现一个ffmpeg的目录,就是你下载的源代码。

官网:http://ffmpeg.mplayerhq.hu/download.html

我们还不能这么快编译ffmpeg,应该如果要让ffmpeg支持更多格式的转换,还需做一些前期工作

2. 支持mp3,linux当然是lame,下载解压
http://sourceforge.net/projects/lame

 

 

lame-3.97.tar.gzMirror


cd lame-3.97
./configure --enable-shared --prefix=/usr
./make
./make install
这里推荐尽量装在/usr下,默认是装在/usr/local下。这样ffmpeg编译都能顺利的找到库文件

3.支持Ogg Vorbis:
as4自带相应的rpm包,你可以安装一下如下rpm包
libvorbis, libvorbis-devel,libogg, libogg-devel

FC3和FC4應該是預設安裝了有關的library的,實際上要安裝的套件有4個:libvorbis、libvorbis-devel、libogg 和libogg-devel。您可以用以下指令檢查一下有沒有。
#rpm -qa | grep libogg
#rpm -qa | grep libvorbis
如果沒有的話,用yum安裝就可以了。


4.支持xvid x264,现在最流行的两种高质量的压缩格式
xvid的编译安装
Get the latest version on http://www.xvid.org/,and uncompress it on
your disk. Let's name the resulting source directory ${xvidcore}.
wget http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz

The next step allows you to configure the xvid sources.
# cd ${xvidcore}/build/generic
# ./configure

Some building options can be tuned thanks to the ./configure tool. You
can use your own CC and CFLAGS variables in order to override xvid's
default ones. To have a list of known options:
# ./configure --help

Now xvidcore is configured according to your specific platform. You
can still handwrite the platform.inc file in order to add/remove
specific flags that ./configure may have set them wrong.

It is time to build xvidcore:
# make

That creates a =build directory where all object files go, and where
the build targets are linked. If no error was reported by the build
process, then you can install it on your system:
# make install

This copies the shared and static libraries to the prefix location
passed to the ./configure tool (/usr/local by default). The xvid.h
include file is also copied during the "make install" run.

Voila, xvidcore is installed on your system, make sure your runtime
linker knows about the xvidcore prefix lib dir where it is
installed. And make also sure that it generates a symlink to its
SONAME. In case it would do not take care of the symlink itself:
# cd ${prefix}/lib
# ls libxvidcore.so.*
    ls should list at least one libxvidcore.so.MAJOR.MINOR file
# ln -s libxvidcore.so.MAJOR.MINOR libxvidcore.so.MAJOR

You may also add a .so link to .so.MAJOR, so that applications linked
against .so are in fact linked to .so.MAJOR and thus ensures better
binary compatibility as we take care not changing the MAJOR number
until there is an incompatible ABI change.
# ln -s libxvidcore.so.MAJOR libxvidcore.so

#tar zvxf xvidcore-1.1.2.tar.gz
#cd xvidcore-1.1.2/build/generic/
#./configure --prefix=/usr
#make
#make install


H264/AVC 支援:x264

要壓HQ1080、iPod和PSP的影片,x264是少不了的。不過要安裝x264,就需要用yasm來編譯。那就先裝個yasm吧。
yasm下載網址:http://www.tortall.net/projects/yasm/releases/yasm-0.6.0.tar.gz
最新的 下载:     Source.tar.gz 0.6.2

#tar xzvf yasm-0.6.0.tar.gz
#cd yasm-0.6.0
#./configure --prefix=/usr/local/yasm
#make
#make install
#export PATH="$PATH:/usr/local/yasm/bin"
#vi /etc/profile
--[在最後,插入]--
export PATH="$PATH:/usr/local/yasm/bin"
--[存檔並關閉]--

跟ffmpeg一樣,x264的官網也是鼓勵大家 checkout SVN來取得最新版本。但據SupeSite在2007年5月16日的說明指出官網的x264最新版有Bug,無法正常在一些Intel的CPU上編譯安 裝(甚麼雙至強、四至強CPU嘛,是指雙核和四核嗎?)。不過起碼米奇在公司的P4 2.8GHz CPU安裝沒有問題啦,所以...管它。如果您遇上問題的話,就去下載SupeSite的開發公司Comsenz的版本吧,不過先旨聲明,那個改版的授權 還是不是原來的GPL就不知道了。如果您在意於授權的話,那就用SVN checkout吧,我想那問題可能在您安裝時已經修正好了。

x264的获取同样是采用svn方式,看来svn取代cvs不远了
svn co svn://svn.videolan.org/x264/trunk x264
cd x264
./configure --prefix=/usr --enable-shared
make
make install

5.AC3和dts编码的支持
as4系统似乎已经支持ac3编码,编译的时候只要加--enable-a52--enable-gpl参数就行
現在的ffmpeg又沒附有liba52了,所以,還是自己動手裝吧...
下載網站:http://liba52.sourceforge.net/

# tar zxvf a52dec-0.7.4.tar.gz
# cd a52dec-0.7.4
# ./configure --enable-shared --prefix=/usr
# make
# make install

6.mpg4 aac格式支持,由于服务器还针对手机用户服务,所以,类似aac,mpg4铃声格式的支持,我们也得做。这里我们安装faad2和faac就行
faac是用來壓製AAC音軌的,而faad2就是AAC音軌的解碼器。手機鈴聲和MP4影片都是使用AAC作聲音編碼的,所以要裝這個。
另外,faac和faad2都可以配合libmp4v2來安裝,有些網站說需要先安 裝libmp4v2,(http://mpeg4ip.net/) 不過米奇就發覺只要編譯faac和faad2時加入適當參數,就可以連同libmp4v2一同安裝了。
下载请到http://www.audiocoding.com/downloads.html

FAAD2的编译
cd faad2
autoreconf -vif
./configure --prefix=/usr --with-mp4v2 --enable-shared
make
make install

faac的编译
cd faac
chmod +x bootstrap
./bootstrap
./configure --prefix=/usr --with-mp4v2 --enable-shared
make
make install

Comsenz版下載網址:http://download.discuz.net/env/video/faac-1.25-Comsenz.tar.bz2

#tar xjvf faac-1.25-Comsenz.tar.bz2
#cd faac-Comsenz
#autoreconf -vif
#./configure --prefix=/usr --with-mp4v2 --enable-shared
#make
#make install

要知道安裝了faac和faad2之後有沒有安裝好libmp4v的話,只要找一找/usr/lib目錄裡有沒有 libmp4v2.so等一系列檔案就可以了。找不到的話,就到這裡去下載,安裝好之後再重頭安裝faac和 faad2了。

7.支持3gp格式,这也是现在好多手机支持的格式,因为手机用户是我们的主要用户,所以也得支持编译

编译的时候加上--enable-amr_nb --enable-amr_wb参数就行,根据编译系统的提示,所以我们得下载一

些编译3gp所需得文件。

wget http://www.3gpp.org/ftp/Specs/ar ... 6.204/26204-510.zip
解压以后把里面的文件都拷贝到libavcodec/amrwb_float

wget http://www.3gpp.org/ftp/Specs/ar ... 6.104/26104-510.zip
解压以后把里面的文件都拷贝到libavcodec/amr_float

3GPP AMR Floating point 和AMR-Wideband支援:libamrnb、libamrwb
3GP 影片的影像是h263編碼,而聲音就用AMR-NB或AMR-WB編碼,所以要轉換手機影片,就要安裝AMR程式庫。最初坊間的安裝方式都是到3GPP官 網去下載那些連名字也搞不懂的檔案來,放在ffmpeg裡的指定目錄去跟ffmpeg一同編譯的,但現在已經有人抽取了出來而成為獨立的程式庫,安裝起來 就簡單得多了。
下載網址:http://www.penguin.cz/~utx/amr

libamrnb
#tar xjvf amrnb-7.0.0.0.tar.tar
#cd amrnb-7.0.0.0
#./configure --prefix=/usr --enable-shared
#make
#make install

libamrwb
#tar xjvf amrwb-7.0.0.2.tar.tar
#cd amrwb-7.0.0.2
#./configure --prefix=/usr --enable-shared
#make
#make install

8. DTS 支援:libdca
ffmpeg已經內含了用來解碼DTS的libdca,所以不用安裝,也沒有要入加的參數。

9. 安裝ffmpeg
安裝完成必要的程式庫之後,終於可以動手安裝ffmpeg本體了。如果您先前曾經安裝過ffmpeg的話,就先把ffmpeg的源碼目錄刪掉,再次 checkout個新版本回來安裝吧。

#svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/usr/local/src/ffmpeg
#cd /usr/local/src/ffmpeg
#./configure --prefix=/usr --enable-gpl --enable-shared --enable-libmp3lame--enable-libvorbis --enable-libamr-nb --enable-libamr-wb --enable-libxvid --enable-libx264 --enable-liba52--enable-liba52bin --enable-libfaac --enable-libfaad --enable-libfaadbin--enable-pp --enable-pthreads --disable-ffserver --disable-ffplay
#make clean && make
#make install

經過可以去看一節動畫的時間編譯之後,你應該可以在/usr/bin目錄裡找到ffmpeg程式。輸入ffmpeg便會列出用了甚麼參數來編譯這個 ffmpeg和它的版本。米奇試過用以這程序來安裝的ffmpeg來編製和解壓3GP、Xvid、mov、wmv9、msmpeg4、MPEG2+AC3 音源、h264+aac音源的mkv、PSP用的MP4和FLV影片,都沒有問題,只有wmv7的影片無法解碼,相信已經對應得到大部份現時流行的影音格式了。

可以用 ffmpeg -threads [thread_count] -deinterlace -i [input_file] -ac 2-ab [audio_bitrate] -acodec libfaac -vcodec libx264 -b [video_bitrate][output_file] 來產生 H.264+AAC 的mp4 檔案了。

ffmpeg编译及使用

ffmpeg编译及使用

1 ffmpeg介绍
ffmpeg是音视频的分离,转换,编码解码及流媒体的完全解决方案,其中最重要的就是libavcodec库。它被mplayer或者xine使用作为解码器。还有,国内比较流行的播放器影音风暴或MyMPC的后端ffdshow也是使用ffmpeg的解码库的。

ffmpeg软件包经编译过后将生成三个可执行文件,ffmpeg,ffserver,ffplay。其中ffmpeg用于对媒体文件进行处理,ffserver是一个http的流媒体服务器,ffplay是一个基于SDL的简单播放器。
ffmpeg 中有五个库文件,libavcodec,libavformat,libavutil,libswscale,libpostproc,其中库 libavcodec,libavformat用于对媒体文件进行处理,如格式的转换;libavutil是一个通用的小型函数库,该库中实现了CRC校 验码的产生,128位整数数学,最大公约数,整数开方,整数取对数,内存分配,大端小端格式的转换等功能;libswscale,libpostproc 暂时不知道何用。


2 ffmpeg下载
最新的ffmpeg可以通过svn下载,SVN辅助的软件有:
SubVersion,从 http://subversion.tigris.org/下载,支持linux。
TortoiseSVN,从 http://tortoisesvn.tigris.org/下载,是很不错的SVN客户端程序,为windows外壳程序集成到windows资源管理器和文件管理系统的Subversion客户端,用起来很方便。

subversion安装,记住最好之前装过apr和apr-util,在apache.org网站能下到
wget http://subversion.tigris.org/downloads/subversion-1.3.2.tar.gz
tar zvxf subversion-1.3.2.tar.gz
cd subversion-1.3.2
./configure --with-apr=/usr/local/apr-httpd--with-apr-util=/usr/local/apr-util-httpd/
make
make install
如果安装了FC6,它已经带了svn,不用装了。
ffmpeg的下载:我们就可以通过svn命令获取最新的ffmpeg,命令如下:
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg



3 ffmpeg支持库的安装

* xvid
xvid的获取地址如下:
http://www.xvid.org/
wget http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz
配置编译
   for x86
#./configure --prefix=/usr/local
#make
#make install
   for arm
#CC=arm-linux-gcc ./configure--prefix=/usr/local/arm/arm-linux --build=i686-pc-linux --host=arm-linux--target=arm-linux
#make
#make install


* x264
x264的获取地址如下:
svn co svn://svn.videolan.org/x264/trunk x264
配置编译
   for x86
#./configure --enable-shared --prefix=/usr/local
#make
#make install
   for arm
#CC=arm-linux-gcc ./configure --enable-pthread--enable-shared --host=arm-linux

--prefix=/usr/local/arm/arm-linux
#make
#make install


* 支持mp3
lame的获取地址如下: http://lame.sourceforge.net/index.php
配置编译
   for x86
./configure --enable-shared --prefix=/usr/local


* 支持Ogg Vorbis:


* AC3和dts编码的支持
libdts编译参数
./configure --prefix=/usr
make
make install


* mpg4 aac格式支持,如果ffserver服务器还针对手机用户服务,所以,类似aac,mpg4铃声格式的支持,我们也得做。这里我们安装faad2和faac就行,下载请到http://www.audiocoding.com/modules/mydownloads/http://prdownloads.sourceforge.net/faac
   FAAD2的编译
cd faad2
autoreconf -vif
./configure --prefix=/usr --with-mp4v2 --enable-shared
make
make install
   faac的编译
cd faac
chmod +x bootstrap
./bootstrap
./configure --prefix=/usr --with-mp4v2 --enable-shared
make
make install
在编译ffmpeg,在configure时加上--enable-amr_nb --enable-faad --enable-faac参数。


* 支持3gp格式,这也是现在好多手机支持的格式,所以也得支持编译
编译的时候加上--enable-amr_nb --enable-amr_wb参数就行,根据编译系统的提示,所以我们得下载一些编译3gp所需得文件。
源码网址:http://www.3gpp.org/ftp/Specs
wget http://www.3gpp.org/ftp/Specs/ar ... 6.204/26204-510.zip
解压以后把里面的文件都拷贝到libavcodec/amrwb_float
wget http://www.3gpp.org/ftp/Specs/ar ... 6.104/26104-510.zip
解压以后把里面的文件都拷贝到libavcodec/amr_float


* ffmpeg支持VC1格式
    微软ASF格式的三个版本,WMV1,WMV2,WMV3分别对应MediaPlayer的版本7,8和9,所以很多时候会称VC1为WMV3或 WMV9,都是它了,有时候在代码里,也能看到称呼它为VC9的。因为微软还没有正式公开这种格式,所以当前对VC1的支持还很不完善。本文基本是根据Multimedia Mike的一篇博客翻译和完善而来。
    (1) 首先要下载 SMPTE VC-1 reference decoder,这个组织是要收费的,可以从这里下载免费的。
    (2) 在ffmpeg目录下的libavcodec目录下面,建立目录libvc1。
    (3) 将VC1_reference_decoder_release6/decoder/目录中的*.c和*.h文件全部copy到libvc1目录下。
    (4) 将VC1_reference_decoder_release6/shared/目录中的*.c和*.h文件全部copy到libvc1目录下。
    (5) 将 libvc1-makefile.txt放到libvc1下的Makefile文件。
    (6) 将smpte-vc1.c文件放到libavcodec目录下。
    (7) 修改libavcodec目录下的vc9.c,将文件最后的wmv3_decoder这个AVCodec的structure,用#if 0和#endif包含起来,也就是使它失效了。
    (8) 修改libavcodec目录下的allcodecs.c,将register_avcodec(&wmv3_decoder)上下的注释去掉,使它发挥作用。
    (9) 修改libavcodec目录下的Makefile,把OBJS的列表中加入smpte-vc1.o。
    (10)修改ffmpeg主目录下的Makefile文件,把-L./libavcodec/libvc1 -lvc1$(BUILDSUF)加入到FFLIBS后面。
    (11) 进入ffmpeg/libavcodec/libav1,执行make
    (12) 到ffmpeg主目录下,执行config;make;make install。config时根据实际情况带参数。


* 采用ffmpeg转码制作FLV文件的方法
    采用ffmpeg转码制作FLV文件,和转码成其它媒体类型的重要差别是一定要有lame库支持,因为FLV的声音编码采用mp3格式,非lame这个东东不行。编译ffmpeg中加入lame库真是一场灾难,特别在windows下,很多参数都不能发挥作用,最后直接手工copy和改一些文件,记录如下:
    (1) 如果在Windows下编译,第一步当然是下载MinGW和MSYS来装上了。到http://mingw.sourceforge.net/去下载最新版的MinGW-5.0.2.exe和MSYS-1.0.11-2004.04.30-1.exe。
    (2) 先安装MinGW,直接运行MinGW-5.0.2.exe安装,选择目录,譬如选择D:\MinGW为安装目录。安装时需要选择gcc和make模块,安装文件本身很小,会从网上下载模块来安装。
    (3) 然后安装MSYS,也是直接运行MSYS-1.0.11-2004.04.30-1.exe安装。安装目录一般选择D:\MinGW\bin \1.0。,安装过程会询问刚才安装MinGW的目录,输入D:\MinGW,其它都回答'Y'就搞定了。如果不清楚,可以看这个图片效果。
    (4) 运行MSYS,桌面上有个图标,双击就运行了,运行结果是一个模拟unix的命令窗口,后面的编译都在这种状态下进行。前面4步在linux不需要。
    (5) 到http://lame.sourceforge.net/去下载最新版的lame-3.97b2.tar.gz,copy到你认为合适的地方,解压后进入lame解压出来的目录中。执行
        ./configure--prefix=PREFIX
        make
        make install
    (6) 就把编译出来的include下的lame目录copy到/usr/include目录下,把lib下的几个库文件都copy到/usr/lib目录 下。这里注意有个变化,如果只copy lib目录下的静态库到/usr/lib下,就是只copy libmp3lame.a文件,编译出来的ffmpeg最终就不会对libmp3lame的动态库有依赖关系,这是因为编译首先找动态库,动态库没有才找静态库。如果不做这个copy,后面编译ffmpeg时无论如何指定参数,都会报错LAME not found,不知道是哪里的bug。
    (7) 从http://ffmpeg.mplayerhq.hu/取得最新的ffmpeg,现在自由软件都大量采用SVN了,要先装一个SVN,可以去http://tortoisesvn.tigris.org/下载windows版的SVN,去http://subversion.tigris.org/下载linux版的SVN。SVN如何编译安装这里就省略了。
    (8) 如果在windows下,打开解压后的ffmpeg目录下的Makefile文件,在FFLIBS的那一行后面加上-lmp3lame$(BUILDSUF)。这个也不知道是哪个bug引起的,搞了好长时间才搞出来,郁闷。Linux下不用这样。


4 ffmpeg的编译

配置编译
for x86
#./configure --prefix=/usr --enable-gpl --enable-shared--enable-mp3lame --enable-amr_nb --enable-amr_wb --enable-amr_if2--enable-libogg --enable-vorbis --enable-xvid --enable-a52 --enable-a52bin--enable-faadbin --enable-dts --enable-pp --enable-faad --enable-faac--enable-x264 --enable-pthreads --disable-ffserver --disable-ffplay
make
make install

补充1:
关于3gp的编译,如果大家要编译--enable-amr_nb-fixed,那就不能跟--enable-amr_nb同时编译,我不大清楚这两者到底有什么区别,似乎

fixed是修正版,管他呢,编译的方法:
wget http://www.3gpp.org/ftp/Specs/ar ... 6.073/26073-510.zip
解压以后把里面的文件都拷贝到libavcodec/amr目录下

修改libavcodec/amr/makefile 找到CFLAGS =-Wall -pedantic-errors -I. $(CFLAGS_$(MODE)) -D$(VAD) 换成CFLAGS = -Wall -I.

$(CFLAGS_$(MODE)) -D$(VAD) -DMMS_IO

整体编译参数就是
#./configure --prefix=/usr --enable-gpl --enable-shared--enable-mp3lame --enable-amr_nb-fixed --enable-amr_wb --enable-amr_if2--enable-libogg --enable-vorbis --enable-xvid --enable-a52 --enable-a52bin--enable-dts --enable-pp --enable-faad --enable-faadbin --enable-faac--enable-x264 --enable-pthreads --disable-ffserver --disable-ffplay
make
make install

for x86的简易配置
#./configure --prefix=./install --disable-shared--enable-pthreads --enable-libx264 --enable-libxvid --arch=i686 --enable-gpl
#make
#make install

for arm
配置编译
#./configure--prefix=/home/zht/redhatzht/sources/image-colletct/ffmpeg/install--enable-static --disable-shared --enable-libx264 --enable-libxvid--cross-compile --cc=arm-linux-gcc --arch=arm --enable-gpl --disable-strip--disable-network --disable-ipv6 --disable-vhook --disable-audio-beos--disable-audio-oss --disable-mpegaudio-hp  --enable-pthreads--enable-small --disable-parsers --disable-debug
#make
#make install

注意:

(1)“/home/zht/redhatzht/sources/image-colletct/ffmpeg”为ffmpeg源码所在目录。
(2)“/usr/local/arm”为arm-linux-gcc交叉编译器所在目录。
(3) 如果库文件安装在/usr/local/lib目录中导致配置失败,可以在/etc/ld.so.conf文件中添加/usr/local/lib目录,然后执行#ldconfig。
    x86上的ldconfig不能在arm上运行,arm上的ldconfig工具是在建立交叉编译器时,编译glibc是产生的,可以拷贝到arm-linux中。
(4) 本文大部分内容来自网络,其中xvid,x264的库,我亲手安装过,ffmpeg的配置编译for x86的简易配置,for arm,我亲手配置编译过,并在x86,arm上可用,编译配置都是采用静态库。


5 ffmpeg用法
ffmpeg作为媒体文件处理软件,基本用法如下:
ffmpeg -i INPUTfile [OPTIONS] OUTPUTfile
输入输出文件通常就是待处理的多媒体文件了。可以是纯粹的音频文件,纯粹的视频文件,或者混合的。ffmpeg支持绝大部分的常见音频,视频格式,象常见的 各种mpeg,AVI封装的DIVX和Xvid等等,具体的格式支持列表可以使用ffmpeg -formats查看或直接查阅文档。
另外,由于Linux把设备视为文件,因此-i选项后可以跟设备名。比如DV,视频卡,光驱或者其它的各类设备。输出的内容通过

Options调整,其主要的选项如下:
-vcodec  视频流编码方式
-b        视频流码率(默认只有200k,一般都需要手动设置,具体的数值视codec选择而定)
-r        视频流帧数(一般说来PAL制式通常用25,NTSC制式通常用29)
-s         视频解析度(分辨率,也要视codec和你的需要而定。另:具体写法使用“数字x数字”的形式)
-t         处理持续时间。
-acodec   音频流编码方式
-ab          音频流码率(默认是同源文件码率,也需要视codec而定)
-ar           音频流采样率(大多数情况下使用44100和48000,分别对应PAL制式和NTSC制式,根据需要选择)
-vn  屏蔽视频流
-an  屏蔽音频流
-author  设置媒体文件的作者
-title  设置媒体文件的题目
-f  强制使用某种格式
-target type 使用预置的格式转换(可以转成dvd,vcd或svcd)

除此之外还有些更高级的选项,如设定vbr,或设定high quality,或者设定vbr的buff和max/min码率,象一般我们自用的dvd抓轨啦,DV转vcd dvd啦,网上下载的电影转成vcd或dvd都不一定需要用到它们。

常用命令选项说明
-fromats 显示可用的格式
-f fmt 强迫采用格式fmt
-I filename 输入文件
-y 覆盖输出文件
-t duration 设置纪录时间hh:mm:ss[.xxx]格式的记录时间也支持(截图需要)
-ss position 搜索到指定的时间[-]hh:mm:ss[.xxx]的格式也支持
-title string 设置标题
-author string 设置作者
-copyright string 设置版权
-comment string 设置评论
-target type 设置目标文件类型(vcd,svcd,dvd),所有的格式选项(比特率,编解码以及缓冲区大小)自动设置,只需要输入如下的就可以了:ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
-hq 激活高质量设置

-b bitrate 设置比特率,缺省200kb/s
-r fps 设置帧频,缺省25
-s size 设置帧大小,格式为WXH,缺省160X128.下面的简写也可以直接使用:Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576
-aspect aspect 设置横纵比 4:316:9 或 1.3333 1.7777
-croptop/botton/left/right size 设置顶部切除带大小,像素单位
-padtop/botton/left/right size 设置顶部补齐的大小,像素单位
-padcolor color 设置补齐条颜色(hex,6个16进制的数,红:绿:蓝排列,比如 000000代表黑色)
-vn 不做视频记录
-bt tolerance 设置视频码率容忍度kbit/s
-maxrate bitrate设置最大视频码率容忍度
-minrate bitreate 设置最小视频码率容忍度
-bufsize size 设置码率控制缓冲区大小
-vcodec codec 强制使用codec编解码方式. 如果用copy表示原始编解码数据必须被拷贝.(很重要)

-ab bitrate 设置音频码率
-ar freq 设置音频采样率
-ac channels 设置通道,缺省为1
-an 不使能音频纪录
-acodec codec 使用codec编解码

-vd device 设置视频捕获设备,比如/dev/video0
-vc channel 设置视频捕获通道DV1394专用
-tvstd standard 设置电视标准 NTSC PAL(SECAM)
-dv1394 设置DV1394捕获
-av device 设置音频设备 比如/dev/dsp

-map file:stream 设置输入流映射
-debug 打印特定调试信息
-benchmark 为基准测试加入时间
-hex 倾倒每一个输入包
-bitexact 仅使用位精确算法 用于编解码测试
-ps size 设置包大小,以bits为单位
-re 以本地帧频读数据,主要用于模拟捕获设备
-loop 循环输入流。只工作于图像流,用于ffserver测试


5 example
(1) ffmpeg的使用

"Video and Audio grabbing"
FFmpeg can use a video4linux compatible video sourceand any Open Sound System audio source:         
        ffmpeg/tmp/out.mpg
Note that you must activate the right video source andchannel before launching ffmpeg. You can use any TV viewer such as

xawtv (<http://bytesex.org/xawtv/>) by Gerd Knorr which I findvery good. You must also set correctly the audio recording

levels with a standard mixer.
"Video and Audio file format conversion"

* You can input from YUV files:     
        ffmpeg -i /tmp/test%d.Y/tmp/out.mpg
The Y files usetwice the resolution of the U and V files. They are raw files, without header.They can be generated by all decent video decoders. You must specify the sizeof the image with the -s option if ffmpeg cannot guess it.

* You can input from a RAW YUV420P file:        
        ffmpeg -i/tmp/test.yuv /tmp/out.avi
The RAW YUV420P is a file containing RAW YUV planar,for each frame first come the Y plane followed by U and V planes, which arehalf vertical and horizontal resolution.

* You can output to a RAW YUV420P file:        
        ffmpeg -imydivx.avi -o hugefile.yuv

* You can set several input files and outputfiles:         
        ffmpeg -i/tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg
Convert the audio file a.wav and the raw yuv video filea.yuv to mpeg file a.mpg

* You can also do audio and video conversions at thesame time:         
        ffmpeg -i/tmp/a.wav -ar 22050 /tmp/a.mp2
Convert the sample rate of a.wav to 22050 Hz and encodeit to MPEG audio.

* You can encode to several formats at the same timeand define a mapping from input stream to output streams:        
        ffmpeg -i/tmp/a.wav -ab 64 /tmp/a.mp2 -ab 128 /tmp/b.mp2 -map 0:0 -map 0:0
Convert a.wav to a.mp2 at 64 kbits and b.mp2 at 128kbits. "-map file:index" specify which input stream is used for eachoutput stream, in the order of the definition of output streams.

* You can transcode decrypted VOBs        
        ffmpeg -isnatch_1.vob -f avi -vcodec mpeg4 -b 800 -g 300 -bf 2 -acodec mp3 -ab 128snatch.avi
This is a typical DVD ripper example, input from a VOBfile, output to an AVI file with MPEG-4 video and MP3 audio, note that in this command we use B frames so theMPEG-4 stream is DivX5 compatible, GOP size is 300 that means an INTRA frameevery 10

seconds for 29.97 fps input video.  Also theaudio stream is MP3 encoded so you need LAME support which is enabled using--enable-mp3lame when configuring.  The mapping is particularlyuseful for DVD transcoding to get the desired audio language.

NOTE: to see the supported input formats, use ffmpeg-formats.


(2) ffplay的使用

ffplay - FFplay media player
SYNOPSIS

ffplay [options] input_file
DESCRIPTION

FFplay is a very simple and portable media player usingthe FFmpeg libraries and the SDL library. It is mostly used as a test bench forthe various APIs of FFmpeg.
OPTIONS

"Main options"

show help force displayed width force displayed heightdisable audio disable video disable graphical display force format
"Advanced options"

show the stream duration, the codec parameters, thecurrent position in the stream, and the audio/video synchronisation drift.force RTP/TCP protocol usage instead of RTP/UDP. It is only meaningful if youare doing stream with the RTSP protocol.

set the master clock to audio ( type=audio), video (type=video) or external ( type=ext). Default is audio. The master clock is usedto control audio-video synchronization. Most media players use audio as masterclock, but in some cases (streaming or high quality broadcast) it is necessaryto change that. This option is mainly used for debugging purposes.


(3) ffserver的使用
ffsserver - FFserver video server
SYNOPSIS

ffserver [options]
DESCRIPTION

FFserver is a streaming server for both audio andvideo. It supports several live feeds, streaming from files and time shiftingon live feeds (you can seek to positions in the past on each live feed,provided you specify a big enough feed

storage in ffserver.conf).

This documentation covers only the streaming aspects offfserver / ffmpeg. All questions about parameters for ffmpeg, codec questions,etc. are not covered here. Read ffmpeg-doc.html for more information.
OPTIONS

print the license print the help use configfile insteadof /etc/ffserver.conf

6 其他(参考)

(1)mencoder篇
   首先获取mplayer软件包极其mplayer官网上自带的codecs.如果喜欢mplayer,也可以下载gui和font.关于mplayer-1.0rc1在71.21的/home/zhengyu/tools中能找到.如果需要网上下载,可以去官网:http://www.mplayerhq.hu/de...下载rc1地址如

下:http://www1.mplayerhq.hu/M...最新的svn版本:http://www1.mplayerhq.hu/M...官网同时也给出了一些codec,其中就有rm格式的codec:http://www1.mplayerhq.hu/M...   xplore也提供下载,mplayer1.0rc1下载,codec下载.

   下载完成之后,将tar vxjf essential-20061022.tar.bz2;sudo mkdir -p/usr/lib/codecs;sudo cp -rf essential-20061022/*

/usr/lib/codecs;然后解包mplayer,按如下方式编译:

./configure --prefix=/usr/local --enable-gui--enable-largefiles  --enable-gif --enable-png --enable-jpeg--language=zh_CN --with-codecsdir=/usr/lib/codecs/
make
(sudo make install)

   然后就可以使用mencoder,当然也有一个没有gui的mplayer可以播放各种视频了.不过我们需要的是mencoder.至此,ffmpeg+mencoder搭建完成.

(2) 常见操作说明
对于ffmpeg,可以将除swf,rmvb,wmav9以外的视频/音频格式转换成flv/mp3,同时可以截取这些视频文件中的某个时间的该帧图片.这些实际上就是一个视频播客显示的部分.对于mencoder,支持各种常见格式的视频/音频转换成flv/mp3.或者转换成avi.

1) ffmpeg进行操作的常用方法:

   * 转换成flv文件:ffmpeg -i infile.* -y (-ss second_offset -ar ar -ab ab -r vr -b vb-s vsize) outfile.flv
        其中second_offset是从开始的多好秒钟.可以支持**:**:**格式,至于ar,ab是音频的参数,可以指定ar= 22050,24000,44100(PAL制式),48000(NTSC制式),后两种常见,ab=56(视音频协议的codec而定,如果要听高品质,则80以上).vr,vb,vsize是视频参数,可以指定vr=15,25(PAL),29(NTSC),vb=200,500,800,1500 (视视频协议的codec而定,可以通过查看专业的codec说明文档获取,如果你手头有一份详细的各种codec的文档,请提供一份给我,不胜感 激.),还有一些参数-acodec ac -vcodec vc(ac指定音频codec,ar和ab可以省去,vc指定视频codec,vr和vb可以省去,自动采用相应的codec参数)还有很多高级参数,如 -qmin,-qcale等,请查看详细文档。还有-an和-vn参数,分别从多媒体文件中提取出纯粹视频和音频。另,如果你是用shell批量处理,请使用-y参数覆盖生成flv.

   * 截取图片:ffmpeg-i infile.* -y (-ss second_offset) -t 0.001 -s msize (-f image_fmt) outfile.jpg
            其中second_offset同上,msize同vsize,图片大小.image_fmt=image2强制使用 jpg,image_fmt=gif,强制使用gif格式.还可以用-vframes fn指定截取某帧图片,fn=1,2,3,...


2)mencoder操作
    mencoder的作用主要在视频转码方面.在安装完mplayer后,mencoder也编译生成了.可以man mencoder获取mencoder的说明文档. mencoder的参数更加复杂,不过也无非是音频处理视频处理两个方面,可以参看网络例子:http://www.masoncn.com/pos...这里不作详细的列举了.

   mencoder进行操作的常用方法: mencoder infile.* -o outfile.* [-ovc 目标视频格式] [-oac 目标音频格式] [-of 目标文件格式]

   * 转换成flv文件: mencoder infile.* -o outfile.flv -of lavf -oac mp3lame -lameoptsabr:br=56 -ovc lavc -lavcopts

vcodec=flv:vbitrate=150:mbd=2:mv0:trell:v4mv:cbp:last_pred=3-srate 22050

   * 转换成avi文件: mencoder infile.* -o outfile.avi -of avi -oac mp3lame -lameoptspreset=64 -ovc xvid -xvidencopts

bitrate=600

   * 转换成wmv文件(复杂写法,其中高级参数可以省去): mencoder infile.* -o outfile.wmv -of lavf -ofps 25 -oac mp3lame-lameopts

cbr:preset=128 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=768:mbd=2:mv0:trell:v4mv:cbp:last_pred=3-vf scale=320:240 -srate

22050 -sws 9 -subcp cp936 -subpos 0 -subalign 0-subfont-text-scale 3 -lavfopts i_certify_that_my_video_strea
   其中-ovc,-oac和-of是必须的,-ovc是指定视频codec,指定了ovc之后通常带一个该codec的opt参数,-oac是指定音频 codec,也会在其后带一个codec的opt参数.可以指定细节以决定视频音频质量和转换速率.具体的细节可以参看专业的技术文档.

7  ffmpeg配置选项

[root@web ffmpeg]# ./configure --help
Usage: configure [options]
Options: [defaults in brackets after descriptions]

Standard options:   基本选项参数
  --help                  显示此帮助信息|print this message
  --log[=FILE|yes|no]     记录测试并输出到config.err文件|log tests and output to FILE [config.err]
  --prefix=PREFIX         安装程序到指定目录(默认/usr/local)|install in PREFIX [/usr/local]
  --libdir=DIR            安装库到指定目录(默认prefix/lib)|install libs in DIR [PREFIX/lib]
  --shlibdir=DIR          指定共享库路径(默认prefix/lib)|install shared libs in DIR [PREFIX/lib]
  --incdir=DIR            指定includes路径(默认prefix/include/ffmpeg)|installincludes in DIR[PREFIX/include/ffmpeg]
  --mandir=DIR            指定man page路径(默认prefix/man)install manpage in DIR [PREFIX/man]
  --enable-mp3lame        启用mp3编码libmp3lame(默认关闭)enableMP3 encoding via libmp3lame[default=no]
  --enable-libogg         启用ogg支持libogg(默认关闭)enable Oggsupport via libogg [default=no]
  --enable-vorbis         启用Vorbis支持libvorbis(默认关闭)enableVorbis support via libvorbis [default=no]
  --enable-faad           启用faad支持libfaad(默认关闭)enable FAADsupport via libfaad [default=no]
  --ena

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值