安装ffmpeg

 

Youtube技术原理
1. 网页文件允许上传视频文件(这个和上传其他文件一样的)(作者用的是python的架构)
2. 后台调用ffmpeg对上传的视频进行压缩,输出flv格式的文件。这个开源程序win32和linux都有实现,所以可以适应不用的主机环境。
3. 使用flvtools处理flv文件,标记上时长、帧速、关键帧等元数据,这样的flash文件才可以拖放。
4. 使用 ffmpeg 产生flv文件的缩略,和大图像文件的缩略图是一个道理。
5. 使用适当的flv播放器在网页中播放服务器端生成的flv文件。


ffmpeg安装:
1、环境winxp-sp2下:
http://ffdshow.faireal.net/mirror/ffmpeg/ 下载
最新版本的 FFMpeg.exe直接用就行(须rar解压)。

以下的东西是为对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等)转换用的,
http://mediacoder.sourceforge.net/download_zh.htm下载
最新版本的mediacoder的安装后;找到其中的mencoder.exe;drv43260.dll和pncrt.dll三个文件。

2、环境linuxas4。3下:

a、先装mp3在linux下的包:lame-3.97.tar.gz;
tar -xvzf lame-3.97.tar.gz;
cd lame-3.97;
//(默认是装在/usr/local下);
//--prefix=/usr/此参数一定要(便于调用os的其它系统包)
//--enable-shared此参数一定要
./configure --enable-shared --prefix=/usr/;
make;
make install;

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

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

amr-wb:http://ftp.penguin.cz/pub/users/utx/amr/amrwb-7.0.0.1.tar.bz2
amr-nb:http://ftp.penguin.cz/pub/users/utx/amr/amrnb-6.1.0.4.tar.bz2
然后 configure make make install 就可以了.

c、mpg4 aac格式支持,由于服务器还针对手机用户服务,所以,类似aac,mpg4铃声格式的支持,我们也得做。这里我们安装faad2和faac就行
下载请到http://www.audiocoding.com/modules/mydownloads/

tar zxvf faad2-2.5.tar.gz
cd faad2
echo > plugins/Makefile.am
echo > plugins/xmms/src/Makefile.am
sed -i '/E_B/d' configure.in
autoreconf -vif
./configure --prefix=/usr
make &&
make install

tar zxvf faac-1.25.tar.gz
cd faac
sed -i '/[2de].M/d' configure.in
echo "AC_OUTPUT(common/Makefile common/mp4v2/Makefile libfaac/Makefile frontend/Makefile include/Makefile Makefile)" >> configure.in
autoreconf -vif
./configure --prefix=/usr
make &&
make install

d、支持xvid; x264,现在最流行的两种高质量的压缩格式
xvid的编译安装
wget http://downloads.xvid.org/downloads/xvidcore-1.1.2.tar.gz
tar zvxf xvidcore-1.1.2.tar.gz

cd xvidcore-1.1.2/build/generic
./configure --prefix=/usr --enable-shared
make
make install

x264的获取同样是采用svn方式:
svn co svn://svn.videolan.org/x264/trunk x264

linux下须从http://www.kernel.org/pub/software/devel/nasm/binaries/linux/下载nasm-0.98.39-1.i386.rpm

在linux下安装就行了。。。

rpm -ivh nasm-0.98.39-1.i386.rpm(如-ivh不行就用-Uvh)

cd x264
./configure --prefix=/usr --enable-shared
make
make install

e、安装ffmpeg:
//as4.3系统已经支持ac3编码,只要加--enable-a52 --enable-gpl参数就行
//我加--enable-shared参数没有成功
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
./configure --prefix=/usr --enable-libmp3lame --enable-libamr_nb --enable-libamr_wb --enable-liba52 --enable-libxvid --enable-libx264 --enable-libfaad --enable-libfaac --enable-gpl --enable-pthreads --enable-nonfree
make clean;//一定要;否则有可能没声音。
make;
make install;

在相应windows和linux目录下(有ffmpeg文件的;以下用linux下说明):
3、使用ffmpeg转换视频为flv文件:
./ffmpeg -i "/opt/input/1.mpg" -y -ab 32 -ar 22050 -b 800000 -s 640*480 /opt/output/1.flv"
ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)

对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等),
可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式.
./mencoder /input/a.rmvb -oac lavc -lavcopts acodec=mp3:abitrate=64 -ovc xvid -xvidencopts bitrate=600 -of avi -o /output/a.avi
在执行./ffmpeg -i "/opt/input/a.avi" -y -ab 32 -ar 22050 -b 800000 -s 640*480 /opt/output/a.flv"就可以转了。

4、视频抓图:
./ffmpeg -i "/opt/input/a.flv" -y -f image2 -t 1 -s 300*200 "/opt/output/1.jpg" //获取静态图

./ffmpeg -i "/opt/input/a.mpg" -vframes 30 -y -f gif "/output/1.gif" //获取动态图;
不提倡抓gif文件;因为抓出的gif文件大而播放不流畅。

用mencoder在线转换视频格式并控制视频品质

 

posted @ 2009-11-22 22:19  fand  阅读(1987)  评论(2编辑  收藏  举报