现在flash做的播放器相当的流行的,但是一般都只能播放mp3的声音文件和flv的视频文件,所以很大程度上限制了播放的内容.要解决这个问题就是把文件转换成mp3或者flv格式的视频.下面主要的讲flv格式的转变.
flv格式的转变大家都知道的一种就是导入视频,然后转换的方法,网上有很多的相同的教程,所以我在这里就不浪费大家的时间和论坛的空间了,请上百度搜索.
大家如果用手动的转换,少量的FLV还可以,那么大量的文件将会使工作变的相当的复杂的,所以解决的方法就是在服务器端,用程序让视频文件格式转变.
视频文件的转变的方法就是根据视频格式的编码的不相同,来转变的,当然我们如果要写一个转变的文件将会使工作变的相当的繁杂的,还好,有一个叫ffmpeg的解决方案.
我们需要做的就是把ffmpeg编译成exe文件,然后通过asp(或者php来调用exe文件.). 在asp中使用WScript.Shell可以很简单的调用,关键的难点在于,ffmpeg的编译,和使用的方法,编译的教程,原文件本身有,但是是英文的,所以我翻译后贴在了闪吧.
We install the Minimalist GNU for Windows MinGW (Compiler) and MSYS (Minimal SYStem) which is a kind of UNIX-shell to access the MinGW-commands. Next we download, compile and install Lame, an open-source mp3-codec, with MSYS. Next we install WinCVS and checkout the latest cvs-release of FFMPEG. Finally we compile ffmpeg and I will show a few examples how to work with Flash Video (FLV).
翻译:我们首先安装windows编译程序Minimalist GNU和一个UNIX-核心的 MSYS (Minimal SYStem)来成功的编译程序。接下来,我们下载、编译和用MSYS安装开源的MP3编码程序。然后我们安装WinCVS,找出FFMPEG的最新版本的cvs.最后我们编译FFMPEG,接下来,我将给大家展示如何来使用FLV。
Download MinGW " MSYS current releases (Window Exe Binaries MSYS-1.0.10.exe & MinGW-3.1.0-1.exe)
下载MinGW的当前的版本(Window Exe Binaries MSYS-1.0.10.exe & MinGW-3.1.0-1.exe)
Install MinGW
安装MinGW
Install MSYS
安装MSYS
HINT: During the Post install be sure to set the right path to MinGW with a "/" instead of a Windows-"". If you did it wrong anyway re-install MSYS to the same directory and do the post install right (I missed it a few times)
提示:在安装位置的时候必须给MinGW用“/”来代替windows中的” ”设置正确的路径,如果你安装过程不正确,请一定要重新的安装到同一个地址并且保证安装正确(我就安装错了好几次的)。
Download and compile Lame
下载并且编译lame
Extract Lame to your MSYS home-directory
把lame提取到你的 MSYS的根目录。
Open MSYS and change to your lame-directory (cd ../lame-XXX)
打开你 MSYS并且跳转到你lame所在的目录(cd ../lame-XXX)
Enter the following commands:
输入下面的命令:
CODE:
代码:
./configure //(takes a few minutes)
make //(lame is being comiled; takes a few minutes, too)
make install
After installing you will recognize that there are new directories and files in MSYS/local which we will use while compiling ffmpeg with mp3-support make //(lame is being comiled; takes a few minutes, too)
make install
等你安装完成了以后你会发现在MSYS/local下有几个我们在用mp3-support编译ffmpeg的时候用到的几个文件和文件目录。
Download WinCVS (http://www.wincvs.org) and install it
然后下载WinCVS(http://www.wincvs.org)安装
Open the Command-Line window (CTRL-L) and enter the command:
打开window命令行(ctrl-l)并且键入下列命令
CODE:
命令为:
cvs -z9 -d:pserver:anonymous@mplayerhq.hu:/cvsroot/ffmpeg co ffmpeg
Select "Execute for directory" and browse to you MSYS-Directory and select your home-directory ("home")
选择"Execute for directory"并且浏览你的MSYS目录,然后选择你的根目录("home")
Press "OK" and the current cvs release will be checked out into your home-directory
点OK,然后现在的CVS版本将会检测到你的根目录下的。
Compile FFMPEG
开始编译FFMPEG
Change the directory in MSYS to your ffmpeg-directory (cd ../ffmpeg)
改变 MSYS中的目录到你的ffmpeg的安装目录(cd ../ffmpeg)
Enter the command:
键入下列命令
CODE:
命令
./configure --enable-memalign-hack --enable-mingw32 --enable-mp3lame --extra-cflags=-I/local/include --extra-ldflags=-L/local/lib
HINT: you can paste into MSYS by pressing your center mouse-button 提示:你可以按你的鼠标左键暂停MSYS。
"enabled-me malign-hack" is a Windows hack. Without this option ffmpeg always crashs with the
message "removing common factors from framerate" when encoding AVIs.
"--enabled-me malign-hack"是一个windows hack,如果没有这个选项,通常ffmpeg将显“removing common factors from frame rate(从框架中删除命令)“的错误信息当编译AVI文件的时候。
"--enable-mingw32". I see no difference without it but we compile with MinGW and it would not do a harm when ffmpeg knows this
"--enable-mingw32"没有这个选项我没有看出有什么不同 ,但是当我们编译MinGW的时候让ffmpeg 知道这个,也没有什么坏处。
"--enable-mp3lame": Enable transcoding audio with the open-source mp3-lame-codec
"--enable-mp3lame":能够用开源的mp3-lame-codec转换视频文件。
"--extra-cflags=-I/local/include --extra-ldflags=-L/local/lib": The cflags- and ldflags-parameter sets the right path to your lame-installation which you did in step 3.d.
"--extra-cflags=-I/local/include --extra-ldflags=-L/local/lib":等你安装3.d.的时候,cflags- and ldflags-parameter将正确设置你的lame安装路径的。
Enter command: make (ffmpeg is being compiled; takes a few minutes)
输入命令 make(ffmpeg将在编译; 请等待几分钟)
With "make install" you could now copy the ffmpeg.exe to c rogram Filesffmpeg. But there is no need
用"make install"你可以现在就拷贝ffmpeg.exe到你想要的文件中,但是这个是没有用的。
to.
Use FFMPEG
Copy your compiled ffmpeg.exe from your MSYS directory to the directory where you like to transcode with ffmpeg
把你编译好的ffmpeg.exe从你的MSYS目录下面复制到任何你想的地方就可以了
Open the Dos-Shell and change to the directory where you copied the ffmpeg.exe
打开DOS窗口。把目录换成你想copy的地方,
Copy a test.mpg into your directory and enter the following command:
复制一个测试的影片到你目录,输入以下的代码
CODE:
ffmpeg -i test.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 test.flv
你的的一个flv文件就成功了
Your first FLV should be encoded now
Render Images from a Video
保存图片文件
Enter command: 输入命令
CODE:
ffmpeg -an -y -t 0:0:0.001 -i test.flv -f image2 test%d.jpg
HINT: With -t you set the length of images to be extracted. Above we entered 1 millisecond the extract one image. If you miss this parameter
all images of the video will be extracted
提示:如果用 –t你将设置抽出图片的长度,上面我们输入的是 I millisecon的抽出的的一个图片的。如果你不用这个参数,那么这个的视频将全部被抽出来的。
ZLib Support (e.g. for TSCC and Quicktime codecs). This should be compiled into FFMPEG. It is not an explicit compile in the configure
statement. Do the following steps and after configure you should see that zlib is "on"
ZLib Support (e.g. for TSCC and Quicktime codecs).这个将被编译到 FFMPEG中间的。它不能直接的编译到配置中的。按照下面的步骤,
等配置成功后,你将能看到这个被编译上了。
Download and compile ZLib
现在并且编译ZLib
Extract the files to your mysys directory
提出文件到你的mysys 目录下面的
Change the directory in MSYS to that directory
跳转的MSYS目录
输入命令
Enter command ./confugure, make and make install.
CODE:
cp /local/lib/libz.a /mingw/lib/.
cp /local/include/zlib.h /mingw/include/.
cp /local/include/zconf.h /mingw/include/.
AC3 Support
如果要支持 AC3j加上下面的命令
Add "--enable-a52 --enable-gpl" to your configure command
3GP Support
3GP的支持,如果你想支持#GP,你需要加上AMR audio代码,现在TS26.104
REL-5 V5.1.0 26104-5??.zip,提取出libavcodec/amr_float的代码,然后加上--enable-amr_nb"命令
If you want to enable 3GP support you have to add the AMR audio codec. Download the TS26.104
REL-5 V5.1.0 26104-5??.zip here. Extract the codec into libavcodec/amr_float and add "--enable-amr_nb" to your configure command
XVID Support (thanks to garvin.thornten at datel.co.uk)
XVID支持(多亏了garvin.thornten)
下载并且安装www.xlib.org (see xvidcore-xxxx/doc/install).加上"--enable-xvid --enable-gpl"命令
当编译的时候在MinGW用XVOD或者在cygwin你将得到一个"mkstemp"错误,安装"libavcodec/xvidff.c"
编辑器,在#includes后面加上下面的内容。这个将、安装到配置中。
Download and install the codec from www.xlib.org (see xvidcore-xxxx/doc/install). Add "--enable-xvid --enable-gpl" to your configure command. When compiling with xvid codec in MinGW or cygwin you will get a "mkstemp" error when compiling
"xvidff.c". To fix this edit "libavcodec/xvidff.c" and add the following after the #includes. This will probably be fixed in a future ffmpeg release: ´
C:
/* Added for windows compile ----------------- */
#include <windows .h>
int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); void xvid_correct_framerate(AVCodecContext *avctx);
int mkstemp(char* template)
{
char temppath[512];
if(GetTempPath(512,temppath)!=0)
{
if(GetTempFileName(temppath,"fil",0,template)!=0)
{
FILE *pFile;
pFile=fopen(template,"w+");
if(pFile!=NULL)
return (int)pFile;
}
}
return -1;
}
/* ------------------------------------------- */
Link about qscale #include <windows .h>
int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); void xvid_correct_framerate(AVCodecContext *avctx);
int mkstemp(char* template)
{
char temppath[512];
if(GetTempPath(512,temppath)!=0)
{
if(GetTempFileName(temppath,"fil",0,template)!=0)
{
FILE *pFile;
pFile=fopen(template,"w+");
if(pFile!=NULL)
return (int)pFile;
}
}
return -1;
}
/* ------------------------------------------- */
removed "-f singlejpeg" as its identical to "-f mjpeg"
以上的翻译如果有什么不懂的地方可以回帖,我将会尽力解释的.
付上自己翻译的文挡.