转换视频为3GPP格式

有关3GPP介绍
In todays mobile phones the 3GPP standard is widely in use for videos on the phone. Newer camera mobiles can take movies from their integrated camera which are encoded in 3GPP (usually with suffix .3gp).
现今3GPP标准广泛的使用在移动电话的视屏中,最近移动电话可以使用它自身集成的摄像头拍摄3GPP编码的电影(通常后辍为.3gp)。
3GPP stands for 3rd Generation Partnership Project and is a consortium which agrees on standards for telecommunications. The video standard is one spec that came out. See their page at http://www.3gpp.org for more information.
3GPP表示:第三代合作计划(或第三代合作伙伴计划),是一个电信标准规范协会,视屏标准的传输就是一个说明,查看更多关于他们的信息:http://www.3gpp.org。
This page describes how to convert regular video files like AVI or MPEG with freely available

open source tools like mplayer and ffmpeg into a GP3 file. I have tested this on Fedora Core 2 and copied the files to my Nokia 6230 (and watched them of course :-) This page is not meant for novice users. I will not answer questions via email about this. Fight it yourself to get it working.

For Windoze users there is a tool called Nokia Multimedia Converter that you can download from Forum Nokia at http://www.forum.nokia.com. You will need to register but the download itself is free. It is a Java application that converts the videos with a graphical interface. I have not tested if it can be used on Linux. I prefer the open source tools.
本页描述如何用自由,有效的开源工具mplayer,ffmpeg将标准的视屏文件(如AVI,MPEG)转换为GP3文件,本人在 FC2平台下测试通过,并且将转换好的文件复制到自己的NOKIA6230(观看它们运行),本页不是为初学者准备的,我不会通过邮件回答关于此页上的问 题,你必须通过自己的努力得到答案(劳动成果),

:对于windows(译者注:Windoze 这单词有问题)用户,有个NOKIA多媒体转换工具使用(译者注:mplayer,ffmpeg在windows下的使用估计不如NOKIA工具方便),此工具可以从NOKIA的网站:http://www.forum.nokia.com 下载得到,虽然下载软件本身免费,但是下载前你需要注册,它是一个以JAVA开发图形界面的视屏转换应用程序,我没有测试他是否能在LINUX下使用,我喜欢这个开源工具。

Theory

==原理==

I do not know the video standard completely but here are some information that you should know when dealing with those videos (this is not yet integrated into the different programs and so you will need to do some handwork, see below)

The video is encoded in H.263 (for more info ask Google) and the audio in narrow-band AMR (adaptive multi-rate) audio codec (for more info see [RFC 3267]).

:我不是非常了解视屏标准,但是当你转换那些视屏格式时这里有一些信息你应该明白(这些<视屏文件格式>不同的文件但是要整合到不同的程序,因此你将会遇到困难,看下面), :视屏用H.263(关于H.263可以问问GOOGLE)编码,音频用窄带AMR(多路适配)音频编解码(更多信息请参看[RFC 3267]),

What you need

==你需要什么==

You will need the following packages. If you are using a distro like Fedora Core you can get these easily from third-party apt repositories like [FreshRPMS]. [MPlayer] [FFMPEG] with additional files. See below These packages have many dependencies by themselves. Read their pages on what that is or use a package management system that cares for you about that.

:你需要以下软件包,如果你在使用一个distro(译者注:无能未知)如Fedora Core操作系统,你能很容易的从第三方网站空间得到[FreshRPMS]. [MPlayer].[FFMPEG] 和其它文件。看下面 这些程序工具包有很多依赖关系,可以去它们的网站了解这些依赖,或者使用包管理系统,它将告诉你注意这个包的有哪些依赖关系。(译者注:LINUX下的程序有太多这程序依赖关系,还好有yum这样了不得的工具,但是这里估计就只能靠官方网站或包管理工具了)。

Setup of MPlayer and FFMPEG

==MPlayer 和 FFMPEG 的安装==

Install MPlayer. I have used a 1.0 pre. FFMPEG needs some additional files that are not part of the distribution (I guess because of licensing issues). I have tested this with FFMPEG version 0.4.8. Get the source code and unpack it. If you use version 0.4.8 read on below. Otherwise read the notes here on how to determine which files you need: Go to the directory, open the file "configure" and search for "amr" or "3gpp". At the very end of the file you should find some notes that tells you which files to get. There should be a note like

 echo "AMR NB FLOAT NOTICE ! Make sure you have downloaded TS26.104"
echo "REL-5 V5.1.0 from "
echo "http://www.3gpp.org/ftp/Specs/latest/Rel-5/26_series/26104-510.zip"
echo "and extracted the source to libavcodec/amr_float"

The name before the .zip (here 26104-510) is the interesting part. The path is wrong. If you use version 0.4.8 you need 26104-510.

安装MPlayer。我用的是1.0 pre(译者注:估计是pro)。FFMPEG需要一些依赖文件不是发行版本的一部分(我猜测是由于许可发行的原因),我有测试FFMPEG 0.4.8版本。得到这源代码包,如果你使用的是0.1.8版本请读下面。如是其它版本请看后面的注释,以确定哪些文件是你需要的:进入源代码目录,打开 “configure”文件并找到“amr”或“3gpp”字符,在文件偏后的部分你能找到一些注释,这些将告诉你哪些文件是你需要的,下面是一个注释样 本

 echo "AMR NB FLOAT NOTICE ! Make sure you have downloaded TS26.104"
echo "REL-5 V5.1.0 from "
echo "http://www.3gpp.org/ftp/Specs/latest/Rel-5/26_series/26104-510.zip"
echo "and extracted the source to libavcodec/amr_float"

后面这个.zip(这里是26104-510)应注意的部分,这是错误的,如果你用的是0.4.8应该用26104-510.(译者注:估计有仁兄|仁妹将此原文:“ echo "http://www.3gpp.org/ftp/Specs/latest/Rel-5/26_series/26104-510.zip"”改动过,不过希望不要改动为好,必竟新人也多。)


Do this for the version you determined: go to http://www.3gpp.org/ftp/Specs/archive/ open the folder that is mentioned last in the URL, here: 26_series open the folder matchin your version, for the version mentioned: 26.104 get the zip mentioned, for the example: 26104-510.zip

Now unpack the FFMPEG source and do:

mkdir -p libavcodec/amr_float
cd libavcodec/amr_float
unzip 26104-510.zip
unzip 26104-510_ANSI_C_source_code.zip
cp -f makefile.gcc makefile

Now go to the ffmpeg dir and configure as usual with an additional "--enable-amr_nb" argument. Example: ./configure --enable-amr_nb. make and make install as usual. Note for RPM users: Get the src RPM (if you use apt: apt-get source ffmpeg) and install it. Go to /usr/src/redhat/SPECS and edit ffmpeg.spec. Add at the top where it says Source Source1: 26104-510.zip. Copy the zip file to /usr/src/redhat/SOURCES Add the following to the %prep section after the %setup macro:

mkdir -p libavcodec/amr_float
cd libavcodec/amr_float
unzip %SOURCE1
unzip 26104-510_ANSI_C_source_code.zip
cp -f makefile.gcc makefile

And add the --enable-amr_nb flag to the configure line. Now rpmbuild -ba ffmpeg.spec && rpm -Uvh --force ../RPMS/i386/ffmpeg*. (you should install ffmpeg before this via apt or something like that to resolve all dependencies!).

Encode Videos

Now that you got everything setup we can finally encode some nice videos :-) To get an actual example I will describe here how to convert Undo from [Platige Image] for your mobile. You can get the video on their page at http://www.undomovie.com/ Also have a look at "The Cathedral" which is even more impressive! Get the undo.mpg file and store in in a directory. Go to that directory. Now we do the following

mencoder undo.mpg -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:-2 -o movie.avi -ofps 12

This will scale the movie down to QCIF resolution (176x144), remove the sound (will care about that later) and store it as MPEG4 in an AVI container with 12 frames per second. You may want to play with the frames per second. I found 12 frames per second to be just fine. Do not change the resolution however. The Nokia 6230 that I have also only has 128x128 pixel display, but 3GPP only defines a small set of resolutions supportd. QCIF is one of them and should be used. The later steps will fail if you change this.


Now we want to get the sound from the video:

mplayer -vo null -ao pcm -af resample=8000,volume=+4db:sc undo.mpg

This extracts the audio from the file and resamples the sound to 8 kHz (seems to be a requirement for AMR) and makes the sound 4 dB louder. It also applies a soft clip filter. The result is a file called audiodump.wav that contains the sound.


Now we put both files together and merge it into a 3GPP file:

ffmpeg -i movie.avi -i audiodump.wav -b 48 -ac 1 -ab 12 -map 0.0 -map 1.0 undo.3gp

We use ffmpeg to merge the two inputs movie.avi and audiodump.avi into the file undo.3gp. We use a bitrate of 48 kbit/sec for the video and 12 kbit/sec for the audio. We only use one audio channel (mono) and map the video and audio streams appropriately into the new file.


Done. Now you can copy the file to your mobile (see NokiaCopyViaBluetooth) and enjoy the show :-)

Enhancements

In some cases you may want to apply a few enhancements to the video material you have got. In Undo you may have noticed the black bars. These could be removed for more real video information. For Undo this is not really useful, since this involves scaling and this makes the video look narrow. For other vids it may fit better. In general what you need are images that can be easily scaled down to QCIF (176x144) or SQCIF (128x96) resolutions (for the Nokia 6230, other phones, other resolutions... But 3GPP/H.263 is pretty strict about allowed resolutions (see this [page about H.263] for a listing. I guess all of these are supported by 3GPP, but I have no clue which cell phones can decode which resolutions). To find out what to crop mencoder has s nice filter that will tell you just that:

mencoder undo.mpg -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vf cropdetect

This will give you output lines like

crop area: X: 512..0 Y: 202..207 (-vf crop=-512:6:512:202)00 [0:0]

So wwe create a cropped.avi with the cropped movie:

mencoder undo.mpg -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vf crop=-512:6:512:20 -o cropped.avi -ofps 12

Now you can rescale the movie. To actually make use of the space and stretch the movie we will use the following command:

mencoder cropped.avi -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:144 -o movie.avi -ofps 12

Then extract the sound and merge the files using ffmpeg as described above.

精简步骤

先到www.3gpp.org下载以下三个文件:

http://www.3gpp.org/ftp/Specs/2004-03/Rel-5/26_series/26204-520.zip

http://www.3gpp.org/ftp/Specs/2004-03/Rel-5/26_series/26073-530.zip

http://www.3gpp.org/ftp/Specs/2004-03/Rel-5/26_series/26104-540.zip


分别解压缩到以下文件夹:

26204-520.zip into libavcodec/amrwb_float
26073-530.zip into libavcodec/amr
26104-540.zip into libavcodec/amr_float

重新编译ffmpeg,记得加上–enable-amr_nb –enable-amr_wb

执行以下命令即可完成转换,具体参数含义查看man

ffmpeg -i test.avi -y -b 20 -s sqcif -r 10 -acodec amr_wb -ab 23.85 -ac 1 -ar 16000 test.3gp
posted @ 2009-12-30 21:05  与时俱进  阅读(4634)  评论(0编辑  收藏  举报
友情链接:同里老宅院民居客栈