使用 ffmpeg 缩放、裁剪、剪辑视频

使用 ffmpeg 缩放、裁剪、剪辑视频

我们平时使用手机拍摄的视频一般都在1080p及以上,在实际应用中,比如共享给朋友等,可能需要处理一下会比较方便。下面列出几个 ffmpeg 常用的处理视频方法(如果只需要格式转换,可以参考我之前的一篇文章《使用H264编码转换视频》

缩小视频

假设原始视频尺寸是 1080p(即 1920×1080 px,16:9),使用下面命令可以缩小到 480p:

$ ffmpeg -i a.mov -vf scale=853:480 -acodec aac -vcodec h264 out.mp4

各个参数的含义:

  • -i a.mov 指定待处理视频的文件名
  • -vf scale=853:480 vf 参数用于指定视频滤镜,其中 scale 表示缩放,后面的数字表示缩放至 853×480 px,其中的 853px 是计算而得,因为原始视频的宽高比为 16:9,所以为了让目标视频的高度为 480px,则宽度 = 480 x 9 / 16 = 853
  • -acodec aac 指定音频使用 aac 编码。注:因为 ffmpeg 的内置 aac 编码目前(写这篇文章时)还是试验阶段,故会提示添加参数 “-strict -2” 才能继续,尽管添加即可。又或者使用外部的 libfaac(需要重新编译 ffmpeg)。
  • -vcodec h264 指定视频使用 h264 编码。注:目前手机一般视频拍摄的格式(封装格式、文件格式)为 mov 或者 mp4,这两者的音频编码都是 aac,视频都是 h264。
  • out.mp4 指定输出文件名

上面的参数 scale=853:480 当中的宽度和高度实际应用场景中通常只需指定一个,比如指定高度为 480 或者 720,至于宽度则可以传入 “-1” 表示由原始视频的宽高比自动计算而得。即参数可以写为:scale=-1:480,当然也可以 scale=480:-1

 裁剪视频

有时可能只需要视频的正中一块,而两头的内容不需要,这时可以对视频进行裁剪(crop),比如有一个竖向的视频 1080 x 1920,如果指向保留中间 1080×1080 部分,可以使用下面的命令:

$ ffmpeg -i a.mov -strict -2 -vf crop=1080:1080:0:420 out.mp4

其中的 crop=1080:1080:0:420 才裁剪参数,具体含义是 crop=width:height:x:y,其中 width 和 height 表示裁剪后的尺寸,x:y 表示裁剪区域的左上角坐标。比如当前这个示例,我们只需要保留竖向视频的中间部分,所以 x 不用偏移,故传入0,而 y 则需要向下偏移:(1920 – 1080) / 2 = 420

视频缩放和裁剪是可以同时进行的,如下命令则为将视频缩小至 853×480,然后裁剪保留横向中间部分:

$ ffmpeg -i IMG_4940.MOV -strict -2 -vf scale=853:480,crop=480:480:186:0 out.mp4

剪辑视频

如果有一段很长的视频只需保留其中的一段,可以使用下面命令对视频进行剪辑。

$ ffmpeg -i a.mov -ss 00:00:21 -t 00:00:10 -acodec aac -vcodec h264 -strict -2 out.mp4

其中 -ss 00:00:21 表示开始剪辑的位置(时间点),-t 00:00:10 表示剪辑的长度,即 10 秒钟。

当然一段视频是可以在一个命令里同时进行剪辑、缩放、裁剪的,只需把相关的参数合在一起即可。

使用H264编码转换视频

使用H264编码转换视频

H264(即MPEG4 AVC)是目前比较流行的视频编码格式,相对MPEG2编码而言,在画质大致相同的情况下能将视频大小再压缩到50%~25%,即如果一个MPEG2(如DVD)视频大小是1GB,用H264编码能缩小到250MB左右。另外H264编码的视频还能直接在浏览器(如Chrome)和移动设备(如iPhone、Android手机)上直接播放。
如果你有一堆家庭视频(旧款的家用DV一般是MPEG2格式)想刻录到光盘保存,或者有一堆手机不直接支持的格式的视频想在手机上播放,那么用H264编码转换和压缩它们是一个不错的选择。

mencoder 是一个很方便的视频编码程序,它几乎支持所有的视频格式,而且参数丰富、速度快。

首选你需要安装 mencoder 程序(下面分别是 Archlinux, Fedora, Ubuntu下的安装方式):

$ sudo pacman -S memcoder
$ sudo yum install mencoder
$ sudo apt-get install mencoder

然后就可以查看你当前系统支持哪些视频和音频编码器,以及支持哪些封装格式了:

$ mencoder -ovc help
$ mencoder -oac help
$ mencoder -of help

如果看到有x264视频编码器、有mp3lame音频编码器、以及有mp4封装格式,那么就可以开始下面的编码转换了,否则你可能需要安装相应的音频和视频编码器,一般安装 ffmpeg 组件就会同时附带这些编码器。

压缩一段MPEG2视频:

$ mencoder m001.mpg -o m001.mp4 -oac mp3lame -ovc x264 -of lavf -vf lavcdeint

上面命令中的 m001.mpg 和 m001.mp4 分别是输入和输出文件名,-oac 用于指定音频编码器,-ovc 指定视频编码器, -of 指定输出文件封装方式,lavf表示输出文件封装方式由输出的文件名(的扩展名)决定(比如m001.mp4表示用mp4封装,m001.avi表示用avi封装),最后 -vf lavcdeint 参数用于去除视频中的拉丝条纹(锯齿纹),如果没有的话不要这个参数也可以。

h264的编码过程比较耗时,比如 AMD 四核2.8G的编码速度大概是 30fps,大概是视频正常播放所需的时间。

如果待编码转换的视频文件很多,则最好写一个批量处理的脚本:

#!/bin/bash
find . -type f ( -name "*.mpg" -o -name "*.mpeg" )|while read line;do
echo $line
mencoder $line -o ${line}.mp4 -oac mp3lame -ovc x264 -of lavf -vf lavcdeint
done

执行上面的脚本会将当前目录里所有后缀名为“mpg”和“mpeg”的视频编码为H264格式。

最后,除了mencoder之外,还可以使用ffmpeg来编码,详细方法请参考这里

FFMPEG Install for CentOS 5


 FFMPEG Install for CentOS 5



A little while back, I posted a basic install of ffmpeg for CentOS 5. After working with that build over the last month, I found I needed to expand it to include many different video codecs. Because of licensing restrictions, binaries of the build cannot be distributed. However, instructions for a similar build can! I spent several days (or more) researching the packages I would need and I must have combed dozens of blogs to find this information. The build I made strips sound from videos [See update at the end of this post for more information on this subject], this decreases the final file size. If you need sound, you will not want to follow these steps exactly. I also stripped ffserver and ffplay from my build.


These packages were executed in the following order. I cannot say for certain this exact order must be followed, it was the order in which ffmpeg threw the errors. This tutorial assumes you have wget, bzip2, tar and subversion installed on your system. If you do not, please find and install the lastest versions of these utilities for CentOS 5. Additionally, I have allowed all packages to install into their default directories, typically this is /usr/local/[bin | lib]. If at any point during the process of a ‘make’ you run into errors, be sure and run ‘make clean’ before running ‘make’ again. You will either need root access of su access to install ffmpeg. The marker ‘codec:$’ is my prompt, it is merely to indicate separate commands.



Getting Started



codec:$
codec:$ mkdir -p ./tmp/ffmpeg-packages
codec:$ cd ./tmp/ffmpeg-packages


Installing a52



codec:$ wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
codec:$ tar -zxf a52dec-0.7.4.tar.gz
codec:$ cd a52dec-0.7.4
codec:$ ./configure –enable-shared=PKGS
codec:$ make && make install
codec:$ cd ..


Installing FAAD2



codec:$ wget http://downloads.sourceforge.net/faac/faad2-2.6.1.tar.gz
codec:$ tar zxf faad2-2.6.1.tar.gz
codec:$ cd faad2
codec:$ autoreconf -vif
codec:$ ./configure –disable-drm –disable-mpeg4ip
codec:$ make && make install
codec:$ cd ..


Installing FAAC



codec:$ wget http://downloads.sourceforge.net/faac/faac-1.26.tar.gz
codec:$ tar zxfv faac-1.26.tar.gz
codec:$ cd faac
codec:$ ./bootstrap
codec:$ ./configure –disable-mp4v2
codec:$ make && make install
codec:$ cd ..


Installing LAME



codec:$ wget \
http://superb-east.dl.sourceforge.net/sourceforge/lame/\
lame-3.98b8.tar.gz
codec:$ tar zxfv lame-3.98b8.tar.gz
codec:$ cd lame-3.98b8
codec:$ ./configure
codec:$ make && make install
codec:$ cd ..


Installing yasm


YASM is a modular assembler, it is required by the x264 package.



codec:$ wget \
http://www.tortall.net/projects/yasm/releases/yasm-0.7.0.tar.gz
codec:$ tar zfvx yasm-0.7.0.tar.gz
codec:$ cd yasm-0.7.0
codec:$ ./configure
codec:$ make && make install
codec:$ cd ..


Installing x264
The x264 package is under git revision control, which is much like CVS or SVN. Thankfully, they provide daily tarballs. I grabbed this one:



codec:$ wget \
ftp://ftp.videolan.org:21//pub/videolan/x264/snapshots/\
x264-snapshot-20080513-2245.tar.bz2


I just did a little exploring via an FTP program to find the snapshot I was after. If you are feeling adventurous, download git and try checking out the latest version from their repository.



codec:$ bzip2 -d x264-snapshot-20080513-2245.tar.bz2
codec:$ tar xfv x264-snapshot-20080513-2245.tar
codec:$ cd x264-snapshot-20080513-2245
codec:$ ./configure –enable-mp4-output –enable-shared –enable-pthread
codec:$ make && make install
codec:$ cd ..


Installing Xvid



codec:$ wget http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz
codec:$ tar zxfv xvidcore-1.1.3.tar.gz
codec:$ cd xvidcore-1.1.3/build/generic
codec:$ ./configure
codec:$ make && make install
codec:$ cd ../../..


Installing libraw1394



codec:$ wget http://www.linux1394.org/dl/libraw1394-1.3.0.tar.gz
codec:$ tar zxfv libraw1394-1.3.0.tar.gz
codec:$ cd libraw1394-1.3.0
codec:$ ./configure
codec:$ make dev
codec:$ make && make install
codec:$ cd ..


Installing libdc1394


This project requires libraw1394, you must build it first. This project is a little confusing there is both a libdc1394 and a libdc1394-2. I have only installed the former. Visit Sourceforge here. I grabbed the tarball here:



codec:$ wget \
http://superb-west.dl.sourceforge.net/sourceforge/libdc1394/\
libdc1394-1.2.2.tar.gz
codec:$ tar zxfv libdc1394-1.2.2.tar.gz
codec:$ cd libdc1394-1.2.2
codec:$ ./configure
codec:$ make && make install
codec:$ cd ..


Installing ffmpeg


For FFMPEG, you will need to get the latest out of SVN. FFMPEG doesn’t ever make releases. To do so, run:



codec:$ svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
codec:$ cd ffmpeg



codec:$ ./configure –enable-gpl –enable-postproc –enable-nonfree –enable-postproc –enable-libfaad –enable-swscale –enable-avfilter –enable-pthreads –enable-libxvid –enable-libx264 –enable-libmp3lame –enable-libdc1394 –enable-liba52 –enable-libfaac –disable-ffserver –disable-ffplay
codec:$ make
codec:$ make install


It usually takes at least 5 mins for ‘make’ to run, be sure you have a good file before attempting to install. You will need to be sure and run the ldconfig setting if you have to re-compile, otherwise ffmpeg will throw an error that it cannot find library files. Here is a good resource for using ffmpeg.


Post-Installation Actions


After the install in complete, you may need to add the /usr/local/lib directory to your ld.so.config file. Do the following:



codec:$ cd /etc/
codec:$ cd ld.so.conf.d
codec:$ vi ffmpeg.conf


You need to add ‘/usr/local/lib’ [sans-quotes] to this file and save it. Press Esc, :, x to do so in vi. Afterwords you need to run the following from the commandline



codec:$ ldconfig

That’s it, you now have a fairly robust build of ffmpeg that can take almost anything you can throw at it. Sadly, licensing restrictions prevent binaries from being made of the above steps. Happy (video) encoding!


Update: This build doesn’t actually strip sound from videos, I am doing that with a flag when I run ffmpeg, however, it should be noted that all the audio codecs you may find in many common video formats may not be supported in this build of ffmpeg, which is why I am choosing to strip audio entirely from videos.

ffmpeg和Mencoder使用实例小全(转贴)


ffmpeg和Mencoder使用实例小全(转贴)

下载电影的时候,我们总希望在全部下载完成之前能够预览一下影片内容,于是发布者时常会放一些影片截图在种子文件中,或者直接贴到网上,也有一些截图是一张图片,但包含很多幅影片在一起,就像下面这张:
imagemagick-montage-sample

有很多软件能够截取影片图像、合并图像,但如果影片太多,比如视频网站为用户上传的图像生成预览图之类的,人工在gui方式下操作就不可取了,我们需要在命令行方式下来截取、合并。

首先,截取影片图像使用最多的就是mplayer或者ffmpeg,我用mplayer比较熟,本文就以此为例了,ffmpeg功能也是非常强大的,但据说支持的文件格式却不丰富。mplayer截取影片图像的基本命令为:

mplayer -ss START_TIME -noframedrop -nosound -vo jpeg -frames N NAME_OF_VIDEO_FILE   
上例中,-ss指定开始的时间,结合-frames参数,限定从某个时间开始、截取几帧图像。为了体现整个影片的内容,我需要在影片中间隔时间相同的几个 点、每个点截取1帧图像,所以按道理应该用-frames 1,但是mplayer这样截图的情况下,第一帧似乎永远都会截取到一个黑屏,所以我常用-frames 2。截取下来的图像保存在了当前目录,名称从00000001.jpg开始依次递增,按照-frames 2,就是取00000002.jpg为结果,删除00000001.jpg即可。经过简单实验,在截取wmv、rmvb影片时,前面的好几帧都会是黑屏, 也只能参考上面的做法多取几帧了。

为了取影片中间隔大致相同的几个点,可以用-ss指定时间,也可以用-sb指定开始字节,在我的实际使用中,使用-sb只会得到黑屏,所以通过文件大小来 设置间隔点的办法不行,只能用-ss时间间隔了,这就需要首先得到影片的总时间。好在mplayer为我们提供了类似的功能:

mplayer -identify movie-filename -nosound -vc dummy -vo null   
这样会输出一大堆影片信息,从中截取所需内容即可,在bash shell中,取得影片总时间长度(以秒为单位)的命令如下:

FILESIZE=`mplayer -identify -nosound -vc dummy -vo null $1 | grep ID_LENGTH | sed -r ‘s/ID_LENGTH=([[:digit:]]*)(.[[:digit:]]*)?/1/g’`   
有了影片的总时长,我们就可以根据所要截取的帧数,计算出每个间隔点的时间位移了。不过要注意一般影片的开始-ss 0和结束-ss TOTAL_TIME_OF_VIDEO截取下来都会是黑屏,在处理的时候要分别加上和减去若干秒。

截取工作完成后,我们拥有了一堆000000xx.jpg文件,如果能把这些文件都放到一个文件中,每行2张,成为一张大图片,在发布的时候会很方便。所 以,我们使用imagemagick([url]http://www.imagemagick.org/script/index.php [/url])中的montage命令来实现:

montage -geometry +0+0 -tile 2 *.jpg montage.jpg   
-geometry +0+0是设定使用原始图片大小,-tile 2参数设定每行放2张图片,最后一个参数是要生成的目标文件名,现在,我们就能够得到像刚才那张一样的图片了。

原理已经讲清楚了,可以自己写一个bash脚本来方便调用,我在网上找到了一个很不错的例子([url]http: //www.linuxquestions.org/questions/showthread.php?t=361072[/url]),可以在这个基 础上进行修改,过程不再详述了。

下面再列一些在网上找到的其他mplayer、mencoder、ffmpeg的使用实例:

mplayer获取影片信息
mplayer -identify movie-filename -nosound -vc dummy -vo null
从所有输出中可以grep到如下信息:
– filetype: ASF file format detected.
– dimensions and format: VIDEO: [MP43] 320×240 24bpp 1000.000 fps 0.0 kbps ( 0.0 kbyte/s)
– video format: ID_VIDEO_FORMAT=MP43
– width (dimensions): ID_VIDEO_WIDTH=320
– height (dimensions): ID_VIDEO_HEIGHT=240
– length in seconds: ID_LENGTH=98.00
参考8([url]http://gallery.menalto.com/node/40548[/url])

mencoder图片做成电影
#用当前目录中的所有JPEG文件创建DivX4文件:
mencoder *.jpg -mf on:w=800:h=600:fps=25 -ovc divx4 -o output.avi
#用当前目录中的一些JPEG文件创建DivX4文件:
mencoder -mf on:w=800:h=600:fps=25 -ovc divx4 -o output.avi *.jpg
#用当前目录中的所有JPEG文件创建Motion JPEG(MJPEG)文件:
mencoder -mf on:w=800:h=600:fps=25 -ovc copy -o output.avi *.jpg
#用当前目录中的所有PNG文件创建一个非压缩的文件:
mencoder -mf on:w=800:h=600:fps=25:type=png -ovc rawrgb -o output.avi *.png
简单用法:
mencoder *.jpg -mf on:fps=15 -o output.avi -ovc xvid
参考6 参考7([url]http://huangjiahua.livejournal.com/99358.html[/url])

ffmpeg屏幕录像
ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -vd x11:0,0 -s 1024×768 ~/test.avi
其中,-vd x11:0,0 指录制所使用的偏移为 x=0 和 y=0,-s 1024×768 指录制视频的大小为 1024×768。录制的视频文件为 test.avi,将保存到用户主目录中。其他选项可查阅其说明文档。
如果你只想录制一个应用程序窗口或者桌面上的一个固定区域,那么可以指定偏移位置和区域大小。使用xwininfo -frame命令可以完成查找上述参数。
你也可以重新调整视频尺寸大小,如:./ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -i ~/test.avi -s 800×600 ~/test-800-600.avi。
参考5([url]http://linuxtoy.org/archives/ffmpeg.html[/url])

mplayer对video进行截屏 截图(wmv mpeg mov flv all works)
mplayer 78.mov -ss 1 -nosound -vo jpeg:outdir=./ -frames 2
我截的第一张图不知为何全部都是黑屏
参考4([url]http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=165254[/url])

转换为flv文件
mencoder NOW.wmv -ffourcc FLV1 -of lavf -ovc lavc -lavcopts vcodec=flv:acodec=mp3:abitrate=56 -srate 22050 -oac mp3lame -o NOW.flv
ffmpeg -i a.asf -ab 56 -ar 22050 -b 500 -r 15 -s 320×240 asf.flv
参考3([url]http://www.roading.net/blog/article.asp?id=114[/url])

使用ffmpeg抓图
ffmpeg -i test2.asf -y -f image2 -ss 08.010 -t 0.001 -s 352×240 b.jpg
jpg: ffmpeg -i test.asf -y -f image2 -t 0.001 -s 352×240 -ss a.jpg //注意-ss就是要提取视频文件中指定时间的图像
jpg: ffmpeg -i asf.flv -y -f image2 -t 1 asf.jpg
gif: ffmpeg -i test.asf -vframes 30 -y -f gif a.gif
参考3 参考2([url]http://www.killflash.net/blog/article.asp?id=77[/url])

如何合并几个视频片段
mencoder -oac copy -ovc copy -idx -o output.avi video1.avi video2.avi video3.avi
* 其中,-oac copy 选项告诉 mencoder 要正确拷贝音频流。而 -ovc copy 选项则是拷贝视频流。
* 如果在视频文件中没有找到索引的话,那么 -idx 选项会要求 mencoder 建立它。
* -o 选项指定输出文件的名称。
* 最后几个参数为需要合并的几个视频片段。
参考1 ([url]http://linuxtoy.org/archives/join_several_videos.html[/url])

大杂烩
服务器端转换工具(Server-Side-FLV-Conversion)
场景:想把 MPG 或 AVI 上传到你的服务器并自动转换成 FLV 吗?
1,FFmpeg ([url]http://sourceforge.net/projects/ffmpeg[/url]) | 教程一 ([url]http://soenkerohde.com/tutorials/ffmpeg[/url]) | 教程二 ([url]http://klaus.geekserver.net/flash/streaming.html[/url])(Google Video 使用的就是这个东东.)
2,Flix Engine ([url]http://www.on2.com/developer/flix-engine-sdk[/url]) | 教程 ([url]http://www.flexauthority.com/articlesIndex.cfm[/url]) | 范例 ([url]http://www.flexauthority.com/Samples/FlixEngine/index.html[/url])
3,Turbine Video Engine ([url]http://www.blue-pacific.com/products/turbinevideosdk/default.htm[/url])
4,Video to Flash Console ([url]http://www.geovid.com/Video_to_Flash_Console[/url])

录像/实时广播(Record/Broadcast)
场景:想制作一个语音视频Blog满足自恋的欲望吗?
1,RED5 ([url]http://www.osflash.org/red5[/url])
2,Flash Media Server ([url]http://www.macromedia.com/go/fms[/url])
在线编码,分享视频(Online Encode & Share)
场景:想不花钱就可以在线分享你的视频吗?
1,Google Video ([url]http://video.google.com/[/url])
2,You Tube ([url]http://www.youtube.com/[/url])
本地 FLV 文件播放器(FLV Player)
场景:拿到了 FLV 文件不知道怎么播放了.
1,martijndevisser FLV Player ([url]http://www.martijndevisser.com/2005/10/flv_player_updated.html[/url])
2,FlashGuru FLV Player ([url]http://www.flashguru.co.uk/free-tool-flash-video-player[/url])
3,FCZone FLV Player ([url]http://fczone.com/2006/01/fms-media-player.cfm[/url])
在线 FLV 文件播放器(Online FLV Player)
场景:知道一个在线FLV地址,又懒得下载和安装播放器.
1,Loadr ([url]http://dengjie.com/loadr[/url])
2,Google Player Generator ([url]http://dengjie.com/loadr/r.swf?file=/temp/google_player.swf&clr=000FFF[/url])
更多相关软件看这篇文章:Flash 网站的视频策略 ([url]http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14571[/url])

此文章转自 shadow

ffmpeg 参数

利用ffmpeg+mencoder视频转换的总结
[url]http://www.yitian130.com/article.asp?id=69[/url]

flv视频转换和flash播放的解决方案笔记
[url]http://blog.verycd.com/dash/showentry=35982[/url]

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

安装和使用ffmpeg转换视频为flv文件(windows和linux)

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

以下的东西是为对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等)转换用的,
从[url]http://mediacoder.sourceforge.net/download_zh.htm[/url]下载
最新版本的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所需得文件。

wget [url]http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-510.zip[/url]
解压以后把里面的文件都拷贝到libavcodec/amrwb_float/

wget [url]http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-510.zip[/url]
解压以后把里面的文件都拷贝到libavcodec/amr_float/

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

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 [url]http://downloads.xvid.org/downloads/xvidcore-1.1.2.tar.gz[/url]
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下须从[url]http://www.kernel.org/pub/software/devel/nasm/binaries/linux/[/url]下载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参数没有成功
./configure –prefix=/opt/ffmpeg/ –enable-mp3lame –enable-amr_nb –enable-amr_wb –enable-a52 –enable-xvid –enable-x264 –enable-faad –enable-faac –enable-gpl –enable-pthreads;
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在线转换视频格式并控制视频品质
[url]http://blog.sina.com.cn/u/490343a7010006z6[/url]