Linux系统下视频转换:Mencoder和Ffmpeg资料汇总

 

Linux下的视频转换:mencoder

制作适合在智能手机和PDA上观看的mpeg4视频。

Linux上有一个很强大的视频音频转换软件,就是Mplayer自带的mencoder (MPlayer's MovIE Encoder)。mencoder就象是一台全手动的照相机,可调整的选项非常多,不过这儿只是把最常见的情况说一下。

转换avi文件,并把字幕内嵌到视频中。首先假设一下下列的条件:

文件名:video.avi

字幕文件名:video.srt

目标文件:new.avi

目标文件格式:mpeg4

目标文件视频码率:200

目标文件音频码率:64

目标文件分辨率: 320:240

制作内嵌字幕所需的字体:simsun.ttf

(上面各项都可以根据实际情况进行调整)

转换命令如下:

mencoder-oac MP3lame -lameopts vbr=3:br=64 -ovc lavc -lavcoptsvcodec=mpeg4:mbd=1:vbitrate=200 -sub video.srt -o new.avi -fontsimsun.ttf video.avi -subcp cp936 -subfont-text-scale 4 -vfscale=320:240

各选项的含义:

-oac 编码文件的音频部分。这儿是用lame将音频encode成MP3,即mp3lame。其他可用的选项可以调用mencoder的man page查看。

-lameopts 顾名思义,即lame选项,这儿只需定义一下码率就可以了。

vbr 设定音频码率的方法,格式为vbr=<0-4>

0 cbr average bitrate

1 mt

2 rh constant bitrate Also forces CBR mode encoding on subsequent ABR presets modes.

3 abr

4 mtrh

在这儿用的是3,abr。

br 就是设定我们所需要的码率值,格式为br=<0-1024>,只能在vbr为0和3的情况下才能使用该选项。

-ovc 编码文件的视频部分。主要有以下几个选项

-ovc copy

不进行编码,只是复制视频流

-ovc divx4

编码成DivX4/DivX5

-ovc raw

编码成任意不压缩的格式(用‘-vf format’设定具体的格式)

-ovc lavc

使用libavcodec进行编码

-lavcopts 就是libavcodec的选项。

vcodec=使用指定的视频编码,下面列一下几个主要的值

h264

H.264

h263

H.263

h263p

H.263+

mpeg4

MPEG-4 (DivX 4/5)

msmpeg4

DivX 3

msmpeg4v2

MS MPEG4v2

wmv1

Windows Media Video, version 1 (又称 WMV7)

wmv2

Windows Media Video, version 2 (又称 WMV8)

rv10

旧的RealVideo格式

mpeg1video

MPEG-1 video

mpeg2video

MPEG-2 video

mbd 决定视频宏块的算法,这儿只需要mbd=1即可。其余的可以查看man page。

vbitrate 设定视频的码率(默认为800)。

-sub 设定字幕文件

-o 目标视频文件

-font 制作内嵌字幕所需字体的路径

-subcp 字幕的编码,简体中文就是cp936

-subfont-text-scale 字幕字体的大小

-vf scale 视频的分辨率

如果不需要将字幕内嵌入视频文件,只需要去掉-sub、-font、-subcp、-subfont-text-scale这几个选项。将rmvb转换成mpeg4也是如此。

Linux下的视频转换:ffmpeg

格式:ffmpeg [[输入文件选项]- i 输入文件名] {[输入文件选项] 输出文件名}

主要选项:

-L 显示ffmpeg的版权说明

-h 显示帮助

-version 显示版本

-formats 显示支持的文件格式,编码和协议

-f 格式名 强制使用格式

-img 文件格式名 强制使用片格式

-i 文件名 待转换文件名字

-y 覆盖同名输出文件

-t 时间 设置影片时间长度

-fs 最大尺寸 设置文件的最大尺寸

-ss 时间点 设置开始转换的时间点

-title 文字 设置标题

-author 文字 设置作者

-copyright 文字 设置版权声明

-comment 文字 设置备注

视频选项:

-b 比特率 设置文件比特率 (单位是kbit/s)

-r 速度 桢速度 (Hz value)

-s 大小 设置大小,宽乘高

-newvideo 在现在的视频流后面加入信的视频流

Audio options:

-aframes 数字 设置转换多少桢(frame)的音频

-ab bitrate 设置音乐的比特率(单位:kbit/s)

-aq 质量 这只音频质量 (指定编码)

-ar 采样率 设置音频采样率 (单位:Hz)

-ac 声道数字 设置声道数

-an 取消音频

-acodec 编码 强制音频 编码 ('copy' to copy stream)

-vol volume 改变音量 (256为普通)

-newaudio 追加音乐

 

本文链接: http://www.php-oa.com/2009/03/09/ffmpeg_x264.html  

转帖:http://rhingheart.blogspot.com/2009/03/ffmpegx264-ffmpeg-x264.html  

使用ffmpeg进行.264编码的相关文章比较少,google了一下,特总结如下:  

qscale的取值可以是0.01-255但实际使用超过50就很糟糕了  
ffmpeg的cbr模式可以把码率控制的不错,但是vbr无法限制最高码率(虽然有max的设置,但是程序没有实现)  
x264标准的封装是x264+aac in flv或者x264+aac in MP4  
接下来说明下ffmpeg命令行的语法规则(本块内容来自2009-03-02官方文档):  

语法规则结构:  

ffmpeg [[infile options][`-i' infile]]... {[outfile options] outfile}...  
一个最简单的命令形式:  

ffmpeg -i input.avi -b 64k output.avi  
这个命令把视频以64k的码率重编码。  

显然,输入文件前面要加一个-i选项下面介绍一些有用的全局参数:  

-formats 参数。会显示你机器当前支持的封装、编码、解码器的信息  
-y参数,会指示ffmpeg覆盖输出文件  
-t 指定视频流持续的时常,支持以秒为单位的数字或"时:分:秒[.毫秒]"  
-fs 指定输出文件大小的限制  
-ss 指定开始的时间,和-t的单位一样  
-target 直接设定你想要转成的目标格式,所有的相关设置都会采用内设值,当然也你也可以加上自己要修改的参数。可用的选择有:  
"vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", …  
这个例子把视频转换成vcd的格式  
ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg  
接下来介绍视频选项:  

-b 指定码率注意单位是bit/s,所以我们一般要加k,比如 -b 1000k 就是1000kb/s  
-g 设置组的大小  
-vframes 指定要编码的帧数,比如-vframes 1 就是编码1帧,截图的时候就这样写.  
-r 指定帧率,默认是25  
-s 指定图像分辨率,用wxh的格式,比如320×240  
-aspect 指定宽高比 可以些16:9这种,也可以写小数比如1.3333  
-croptop 指定顶部裁减多少像素,类似的还有-cropleft -cropright -cropbuttom  
-bt 设置比特率容许的误差,默认4000k,在第一阶段时使用这个参数会告诉码率控制器能够偏移平均码率多远,这个选项和最大最小码率无关.设太小了不利于质量  
-maxrate 和-minrate 指定允许的最大和最小码率,一般如果要用cbr模式编码的话会用这个:  
ffmpeg -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v  
否则用处不大  
-vcodec 强制使用某种编码器  
-sameq 使用和源文件相同的质量,这个选项是动态码率的  
-pass 指定编码阶段,这个只有1和2,第一阶段的时候应该不处理音频,并且把输出导向空,比如:  
ffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y NULffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y /dev/null  
-qscale 使用固定量化因子来量化视频这个是在vbr模式的,前面有提到,越小质量越好,不要超过50,相关的参数还有-qmin –qmax用来设定最大最小可使用的量化值  
-qdiff 指定固定量化器因子允许的最大偏差  
-qblur 指定量化器模糊系数,可用范围是0.0-1.0越大使得码率在时间上分配的越平均  
-qcomp 指定视频量化器压缩系数,默认0.5  
-me_method 指定运动估计方法(motion estimation method),可用的选择从垃圾到好排列如下:  
zero (0向量)  
phods  
log  
x1  
hex  
umh  
epzs (默认)  
full (完全搜索,很慢又好不到哪里去)  
-mbd 设定宏模块决策,可用的值:  
0 使用mb_cmp,不知道是什么东西,所以这些参数我参考一下mencoder里面的  
1 选用需要比特最少的宏块模式  
2 选用码率失真最优的宏块模式  
-4mv 使用宏块的4个运动向量,只支持mpeg4  
-part 使用数据划分,只支持mpeg4  
-ilme 强制允许交错的编码,只支持mpeg2和mpeg4,你可以选择用-deinterlace来去交错  
音频部分:  



-ar 设置采样频率,默认44100hz  
-ab 设置比特率,默认64k  
-an 禁用音频录制  
-acodec 指定音频编码器  


下面举几个x264编码的例子:  



我使用mencoder调用x264编码一个psp用的视频:  

x264+aac in mp4 (我修改过的,原作者的不能使用)  
mencoder test_video.vob -oac lavc -lavcopts acodec=libfaac:abitrate=94 -ovc x264 -x264encopts\  
cabac=1:ref=1:deblock=1,0,0:analyse=0x1,0x111:me=hex:subme=6:psy_rd=1.0,0.0:mixed_refs=0:me_range=32:chroma_me=1:trellis=1:8x\
8dct=0:no-chroma-me=0:chroma_qp_offset=-\  
2:nr=0:dct_decimate=1:bframes=3:b_pyramid=0:b_adapt=1:b_bias=0:direct=3:keyint=250:keyint_min=25:scenecut=40:qp=18:bitrate=80\
0 -lavdopts er=2 -of lavf -lavfopts format=mp4 -vf scale=720:480 -o men.mp4  

对应的ffmpeg编码参数是:  

ffmpeg  
ffmpeg -i inputfile.avi -f psp -acodec libfaac -ab 94k -vcodec libx264 -cqp 28 -coder 1 -refs 3 -deblockalpha 1 -deblockbeta -1 -me_method umh -subq 9 -me_range 32 -trellis 2 -chromaoffset -2 -nr 0 -bf 2 -b_strategy 1 -bframebias 0 -directpred 3 -g 250 -i_qfactor 1.3 -b_qfactor 1.4 -flags2 +bpyramid+wpred+mixed_refs+8x8dct -er 2 -s 480x320  

需要注意的是,flags2里面那块,似乎要按照一定顺序才能正常工作,其他地方都差不多,详细情况可以从下面两篇文章得出:  

第一篇是这个在网上被传了很多,但有些问题的对照表格,我修改了有问题的部分:  

FFmpeg option x264 option  
-g <frames> –keyint  
-b <bits per second> –bitrate  
-bufsize <bits> –vbv-bufsize  
-maxrate <bits> –vbv-maxrate  
-pass <1,2,3> –pass  
-crf <float> –crf  
-cqp <int> –qp  
-bf <int> –bframes  
-coder <0,1> –no-cabac  
-bframebias <int> –b-bias  
-keyint_min <int> –min-keyint  
-sc_threshold <int> –scenecut  
-deblockalpha <int>-deblockbeta <int> –deblock  
-qmin <int> –qpmin  
-qmax <int> –qpmax  
-qdiff <int> –qpstep  
-qcomp <float> –qcomp  
-qblur <float> –qblur  
-complexityblur <float> –cplxblur  
-refs <int> –ref  
-directpred <int> –direct  
-me_method <epzs,hex,umh,full> –me  
-me_range <int> –merange  
-subq <int> –subme  
-bidir_refine <0,1> –bime  
-trellis <0,1,2> –trellis  
-nr <int> –nr  
-level <int> –level  
-bt <bits> –ratetol = -bt / -b  
-rc_init_occupancy <bits> –vbv-init = -rc_init_occupancy / -bufsize  
-i_qfactor <float> –ipratio = 1 / -i_qfactor  
-b_qfactor <float> –pbratio  
-chromaoffset <int> –chroma-qp-offset  
-rc_eq <string> –rc_eq  
-threads <int> –threads  
-cmp <-chroma/+chroma> –no-chroma-me  
-partitions –partitions  
+parti8×8 i8×8  
+parti4×4 i4×4  
+partp8×8 p8×8  
+partp4×4 p4×4  
+partb8×8 b8×8  
-flags
-loop/+loop –no-deblock/–deblock  
-psnr/+psnr –no-psnr/nothing  
-flags2
+bpyramid –b-pyramid  
+wpred –weightb  
+brdo –b-rdo 我这里的ffmpeg已经不能用这个了  
+mixed_refs –mixed-refs  
+dct8×8 –8×8dct  
-fastpskip/+fastpskip –no-fast-pskip  
+aud –aud  


下面是一篇关于这些参数详细解释的文章,转自:http://ffmpeg.x264.googlepages.com/mapping  



一下是这篇文章在2008年11月19日更新的版本:  



Frame-type options:  
–keyint <integer> (x264)  
-g <integer> (FFmpeg)  
Keyframe interval, also known as GOP length. This determines the maximum distance between I-frames. Very high GOP lengths will result in slightly more efficient compression, but will make seeking in the video somewhat more difficult. Recommended default: 250  
–min-keyint <integer> (x264)  
-keyint_min <integer> (FFmpeg)  
Minimum GOP length, the minimum distance between I-frames. Recommended default: 25  
–scenecut <integer> (x264)  
-sc_threshold <integer> (FFmpeg)  
Adjusts the sensitivity of x264′s scenecut detection. Rarely needs to be adjusted. Recommended default: 40  
–pre-scenecut (x264)  
UNKNOWN (FFmpeg)  
Slightly faster (but less precise) scenecut detection. Normal scenecut detection decides whether a frame is a scenecut after the frame is encoded, and if so then re-encodes the frame as an I-frame. This is not compatible with threading, however, and so –pre-scenecut is automatically activated when multiple encoding threads are used.  
–bframes <integer> (x264)  
-bf <integer> (FFmpeg)  
B-frames are a core element of H.264 and are more efficient in H.264 than any previous standard. Some specific targets, such as HD-DVD and Blu-Ray, have limitations on the number of consecutive B-frames. Most, however, do not; as a result, there is rarely any negative effect to setting this to the maximum (16) since x264 will, if B-adapt is used, automatically choose the best number of B-frames anyways. This parameter simply serves to limit the max number of B-frames. Note that Baseline Profile, such as that used by iPods, does not support B-frames. Recommended default: 16  
–b-adapt <integer> (x264)  
-b_strategy <integer> (FFmpeg)  
x264, by default, adaptively decides through a low-resolution lookahead the best number of B-frames to use. It is possible to disable this adaptivity; this is not recommended. Recommended default: 1  
0: Very fast, but not recommended. Does not work with pre-scenecut (scenecut must be off to force off b-adapt).  

1: Fast, default mode in x264. A good balance between speed and quality.  

2: A much slower but more accurate B-frame decision mode that correctly detects fades and generally gives considerably better quality. Its speed gets considerably slower at high bframes values, so its recommended to keep bframes relatively low (perhaps around 3) when using this option. It also may slow down the first pass of x264 when in threaded mode.  
–b-bias 0 (x264)  
-bframebias 0 (FFmpeg)  
Make x264 more likely to choose higher numbers of B-frames during the adaptive lookahead. Not generally recommended. Recommended default: 0  
–b-pyramid (x264)  
-flags2 +bpyramid (FFmpeg)  
Allows B-frames to be kept as references. The name is technically misleading, as x264 does not actually use pyramid coding; it simply adds B-references to the normal reference list. B-references get a quantizer halfway between that of a B-frame and P-frame. This setting is generally beneficial, but it increases the DPB (decoding picture buffer) size required for playback, so when encoding for hardware, disabling it may help compatibility.  
–no-cabac (x264)  
-coder 0,1 (FFmpeg)  
CABAC is the default entropy encoder used by x264. Though somewhat slower on both the decoding and encoding end, it offers 10-15% improved compression on live-action sources and considerably higher improvements on animated sources, especially at low bitrates. It is also required for the use of trellis quantization. Disabling CABAC may somewhat improve decoding performance, especially at high bitrates. CABAC is not allowed in Baseline Profile. Recommended default: -coder 1 (CABAC enabled)  
–ref <integer> (x264)  
-refs <integer> (FFmpeg)  
One of H.264′s most useful features is the abillity to reference frames other than the one immediately prior to the current frame. This parameter lets one specify how many references can be used, through a maximum of 16. Increasing the number of refs increases the DPB (Decoded Picture Buffer) requirement, which means hardware playback devices will often have strict limits to the number of refs they can handle. In live-action sources, more reference have limited use beyond 4-8, but in cartoon sources up to the maximum value of 16 is often useful. More reference frames require more processing power because every frame is searched by the motion search (except when an early skip decision is made). The slowdown is especially apparent with slower motion estimation methods. Recommended default: -refs 6  
–no-deblock (x264)  
-flags -loop (FFmpeg)  
Disable loop filter. Recommended default: -flags +loop (Enabled)  
–deblock (x264)  
-deblockalpha <integer>(FFmpeg)  
-deblockbeta <integer>(FFmpeg)  
One of H.264′s main features is the in-loop deblocker, which avoids the problem of blocking artifacts disrupting motion estimation. This requires a small amount of decoding CPU, but considerably increases quality in nearly all cases. Its strength may be raised or lowered in order to avoid more artifacts or keep more detail, respectively. Deblock has two parameters: alpha (strength) and beta (threshold). Recommended defaults:-deblockalpha 0 -deblockbeta 0 (Must have ‘-flags +loop’)  
–interlaced (x264)  
UNKNOWN (FFmpeg)  
Enables interlaced encoding. x264′s interlaced encoding is not as efficient as its progressive encoding; consider deinterlacing for maximum effectiveness.  
Ratecontrol:  
–qp <integer>(x264)  
-cqp <integer>(FFmpeg)  
Constant quantizer mode. Not exactly constant completely–B-frames and I-frames have different quantizers from P-frames. Generally should not be used, since CRF gives better quality at the same bitrate.  
–bitrate <integer>(x264)  
-b <integer>(FFmpeg)  
Enables target bitrate mode. Attempts to reach a specific bitrate. Should be used in 2-pass mode whenever possible; 1-pass bitrate mode is generally the worst ratecontrol mode x264 has.  
–crf <float>(x264)  
-crf <float>(FFmpeg)  
Constant quality mode (also known as constant ratefactor). Bitrate corresponds approximately to that of constant quantizer, but gives better quality overall at little speed cost. The best one-pass option in x264.  
–vbv-maxrate <integer>(x264)  
-maxrate <integer>(FFmpeg)  
Specifies the maximum bitrate at any point in the video. Requires the VBV buffersize to be set. This option is generally used when encoding for a piece of hardware with bitrate limitations.  
–vbv-bufsize <integer>(x264)  
-bufsize <integer> (FFmpeg)  
Depends on the profile level of the video being encoded. Set only if you’re encoding for a hardware device.  
–vbv-init <float>(x264)  
-rc_init_occupancy <float>(FFmpeg)  
Initial VBV buffer occupancy. Note: Don’t mess with this.  
–qpmin <integer> (x264)  
-qmin <integer> (FFmpeg)  
Minimum quantizer. Doesn’t need to be changed. Recommended default: -qmin 10  
–qpmax <integer> (x264)  
-qmax <integer> (FFmpeg)  
Maximum quantizer. Doesn’t need to be changed. Recommended default: -qmax 51  
–qpstep <integer> (x264)  
-qdiff <integer> (FFmpeg)  
Set max QP step. Recommended default: -qdiff 4  
–ratetol <float>(x264)  
-bt <float>(FFmpeg)  
Allowed variance of average bitrate  
–ipratio <float>(x264)  
-i_qfactor <float>(FFmpeg)  
Qscale difference between I-frames and P-frames.  
–pbratio <float>(x264)  
-b_qfactor <float>(FFmpeg)  
Qscale difference between P-frames and B-frames.  
–chroma-qp-offset <integer>(x264)  
-chromaoffset <integer>(FFmpeg)  
QP difference between chroma and luma.  
–aq-strength <float> (x264)  
UNKNOWN (FFmpeg)  
Adjusts the strength of adaptive quantization. Higher values take more bits away from complex areas and edges and move them towards simpler, flatter areas to maintain fine detail. Default: 1.0  
–pass <1,2,3> (x264)  
-pass <1,2,3>(FFmpeg)  
Used with –bitrate. Pass 1 writes the stats file, pass 2 reads it, and 3 both reads and writes it. If you want to use three pass, this means you will have to use –pass 1 for the first pass, –pass 3 for the second, and –pass 2 or 3 for the third.  
–stats <string>(x264)  
UNKNOWN (FFmpeg)  
Allows setting a specific filename for the firstpass stats file.  
–rceq <string>(x264)  
-rc_eq <string>(FFmpeg)  
Ratecontrol equation. Recommended default: -rc_eq ‘blurCplx^(1-qComp)’  
–qcomp <float>(x264)  
-qcomp <float> (FFmpeg)  
QP curve compression: 0.0 => CBR, 1.0 => CQP. Recommended default: -qcomp 0.60  
–cplxblur <float>(x264)  
-complexityblur <float>(FFmpeg)  
Reduce fluctuations in QP (before curve compression) [20.0]  
–qblur <float>(x264)  
-qblur <float>(FFmpeg)  
Reduce fluctuations in QP (after curve compression) [0.5]  
–zones /(x264)  
UNKNOWN (FFmpeg)  
Allows setting a specific quantizer for a specific region of video.  
–qpfile (x264)  
UNKNOWN (FFmpeg)  
Allows one to read in a set of frametypes and quantizers from a file. Useful for testing various encoding options while ensuring the exact same quantizer distribution.  
Analysis:  
–partitions <string> (x264)  
-partitions <string> (FFmpeg)  
p8x8 (x264) /+partp8x8 (FFmpeg)  

p4x4 (x264) /+partp4x4 (FFmpeg)  

b8x8 (x264) /+partb8x8 (FFmpeg)  

i8x8 (x264) /+parti8x8 (FFmpeg)  

i4x4 (x264) /+parti4x4 (FFmpeg)  

One of H.264′s most useful features is the ability to choose among many combinations of inter and intra partitions. P-macroblocks can be subdivided into 16×8, 8×16, 8×8, 4×8, 8×4, and 4×4 partitions. B-macroblocks can be divided into 16×8, 8×16, and 8×8 partitions. I-macroblocks can be divided into 4×4 or 8×8 partitions. Analyzing more partition options improves quality at the cost of speed. The default is to analyze all partitions except p4x4 (p8x8, i8x8, i4x4, b8x8), since p4x4 is not particularly useful except at high bitrates and lower resolutions. Note that i8x8 requires 8x8dct, and is therefore a High Profile-only partition. p8x8 is the most costly, speed-wise, of the partitions, but also gives the most benefit. Generally, whenever possible, all partition types except p4x4 should be used.  

–direct <integer>(x264)  
-directpred <integer>(FFmpeg)  
B-frames in H.264 can choose between spatial and temporal prediction mode. Auto allows x264 to pick the best of these; the heuristic used is whichever mode allows more skip macroblocks. Auto should generally be used.  
–direct-8×8 (x264)  
UNKONWN (FFmpeg)  
This should be left at the default (-1).  
–weightb (x264)  
-flags2 +wpred(FFmpeg)  
This allows B-frames to use weighted prediction options other than the default. There is no real speed cost for this, so it should always be enabled.  
–me  
–merange <integer>(x264)  
-me_range <integer>(FFmpeg)  
MErange controls the max range of the motion search. For HEX and DIA, this is clamped to between 4 and 16, with a default of 16. For UMH and ESA, it can be increased beyond the default 16 to allow for a wider-range motion search, which is useful on HD footage and for high-motion footage. Note that for UMH and ESA, increasing MErange will significantly slow down encoding.  
–mvrange(x264)  
UNKNOWN (FFmpeg)  
Limits the maximum motion vector range. Since x264 by default limits this to 511.75 for standards compliance, this should not be changed.  
–subme 6(x264)  
-subq 6(FFmpeg)  
1: Fastest, but extremely low quality. Should be avoided except on first pass encoding.  

2-5: Progressively better and slower, 5 serves as a good medium for higher speed encoding.  
6-7: 6 is the default. Activates rate-distortion optimization for partition decision. This can considerably improve efficiency, though it has a notable speed cost. 6 activates it in I/P frames, and subme7 activates it in B frames.  

8-9: Activates rate-distortion refinement, which uses RDO to refine both motion vectors and intra prediction modes. Slower than subme 6, but again, more efficient.  

An extremely important encoding parameter which determines what algorithms are used for both subpixel motion searching and partition decision.  

–psy-rd <float>:<float> (x264)  
UNKNOWN (FFmpeg)  
First value represents the amount that x264 biases in favor of detail retention instead of max PSNR in mode decision. Requires subme >= 6. Second value is psy-trellis, an experimental algorithm that tries to improve sharpness and detail retention at the expense of more artifacting. Recommended starting values are 0.1-0.2. Requires trellis >= 1. Recommended default: 1.0:0.0  
–mixed-refs(x264)  
-flags2 +mixed_refs(FFmpeg)  
H.264 allows p8x8 blocks to select different references for each p8x8 block. This option allows this analysis to be done, and boosts quality with little speed impact. It should generally be used, though it obviously has no effect with only one reference frame.  
–no-chroma-me(x264)  
UNKNOWN (FFmpeg)  
Chroma is used in the last steps of the subpixel refinement by default. For a slight speed increase, this can be disabled (at the cost of quality).  
–8x8dct (x264)  
-flags2 +dct8x8(FFmpeg)  
Gives a notable quality boost by allowing x264 to choose between 8×8 and 4×4 frequency transform size. Required for i8x8 partitions. Speed cost for this option is near-zero both for encoding and decoding; the only reason to disable it is when one needs support on a device not compatible with High Profile.  
–trellis <0,1,2>(x264)  
-trellis <0,1,2>(FFmpeg)  
0: disabled  

1: enabled only on the final encode of a MB  

2: enabled on all mode decisions  

The main decision made in quantization is which coefficients to round up and which to round down. Trellis chooses the optimal rounding choices for the maximum rate-distortion score, to maximize PSNR relative to bitrate. This generally increases quality relative to bitrate by about 5% for a somewhat small speed cost. It should generally be enabled. Note that trellis requires CABAC.  

–no-fast-pskip(x264)  
-flags2 -fastpskip(FFmpeg)  
By default, x264 will skip macroblocks in P-frames that don’t appear to have changed enough between two frames to justify encoding the difference. This considerably speeds up encoding. However, for a slight quality boost, P-skip can be disabled. In this case, the full analysis will be done on all P-blocks, and the only skips in the output stream will be the blocks whose motion vectors happen to match that of the skip vector and motion vectors happen to match that of the skip vector and which have no residual. The speed cost of enabling no-fast-pskip is relatively high, especially with many reference frames. There is a similar B-skip internal to x264, which is why B-frames generally encode much faster than P-frames, but it cannot be disabled on the commandline.  
–no-dct-decimate(x264)  
UNKNOWN (FFmpeg)  
By default, x264 will decimate (remove all coefficients from) P-blocks that are extremely close to empty of coefficents. This can improve overall efficiency with little visual cost, but may work against an attempt to retain grain or similar. DCT decimation should be left on unless there’s a good reason to disable it.  
–nr(x264)  
UNKNOWN (FFmpeg)  
a fast, built-in noise reduction routine. Not as effective as external filters such as hqdn3d, but faster. Since x264 already naturally reduces noise through its quantization process, this parameter is not usually necessary.  
–deadzone-inter(264)  
–deadzone-intra (x264)  
UNKNOWN (FFmpeg)  
UNKNOWN (FFmpeg)  
When trellis isn’t activated, deadzone parameters determine how many DCT coefficients are rounded up or down. Rounding up results in higher quality and more detail retention, but costs more bits–so rounding is a balance between quality and bit cost. Lowering these settings will result in more coefficients being rounded up, and raising the settings will result in more coefficients being rounded down. Recommended: keep them at the defaults.  
–cqm (264)  
–cqpfile(x264)UNKNOWN (FFmpeg)  
UNKNOWN (FFmpeg)  
Allows the use of a custom quantization matrix to weight frequencies differently in the quantization process. The presets quant matrices are "jvt" and "flat". –cqpfile reads a custom quant matrices from a JM-compatible file. Recommended only if you know what you’re doing.
【转载】 ffmpeg 参数设置详解
2009年10月20日 星期二 上午 11:35

ffmpeg 参数使用说明2007-02-10 09:28    ffmpeg.exe -i F:\闪客之家\闪客之歌.mp3 -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 f:\11.flv ffmpeg -i F:\01.wmv -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 f:\test.flv 使用-ss参数 作用(time_off set the start time offset),可以从指定时间点开始转换任务。如:

转换文件格式的同时抓缩微图:

ffmpeg -i "test.avi" -y -f image2 -ss 8 -t 0.001 -s 350x240 'test.jpg'

对已有flv抓图:

ffmpeg -i "test.flv" -y -f image2 -ss 8 -t 0.001 -s 350x240 'test.jpg'

-ss后跟的时间单位为秒 Ffmpeg转换命令

ffmpeg -y -i test.mpeg -bitexact -vcodec h263 -b 128 -r 15 -s 176x144 -acodec aac -ac 2 -ar 22500 -ab 24 -f 3gp test.3gp

或者

ffmpeg -y -i test.mpeg -ac 1 -acodec amr_nb -ar 8000 -s 176x144 -b 128 -r 15 test.3gp       ffmpeg参数设定解说

-bitexact 使用标准比特率

-vcodec xvid 使用xvid压缩

-s 320x240 指定分辨率

-r 29.97 桢速率(可以改,确认非标准桢率会导致音画不同步,所以只能设定为15或者29.97)

画面部分,选其一

-b <比特率> 指定压缩比特率,似乎ffmpeg是自动VBR的,指定了就大概是平均比特率,比如768,1500这样的就是原来默认项目中有的

-qscale <数值> 以<数值>质量为基础的VBR,取值0.01-255,约小质量越好

-qmin <数值> 设定最小质量,与-qmax(设定最大质量)共用,比如-qmin 10 -qmax 31

-sameq 使用和源同样的质量 声音部分

-acodec aac 设定声音编码

-ac <数值> 设定声道数,1就是单声道,2就是立体声,转换单声道的TVrip可以用1(节省一半容量),高品质的DVDrip就可以用2

-ar <采样率> 设定声音采样率,PSP只认24000

-ab <比特率> 设定声音比特率,前面-ac设为立体声时要以一半比特率来设置,比如192kbps的就设成96,转换君默认比特率都较小,要听到较高品质声音的话建议设到160kbps(80)以上

-vol <百分比> 设定音量,某些DVDrip的AC3轨音量极小,转换时可以用这个提高音量,比如200就是原来的2倍 这样,要得到一个高画质音质低容量的MP4的话,首先画面最好不要用固定比特率,而用VBR参数让程序自己去判断,而音质参数可以在原来的基础上提升一 点,听起来要舒服很多,也不会太大(看情况调整       例子:ffmpeg -y -i "1.avi" -title "Test" -vcodec xvid -s 368x208 -r 29.97 -b 1500 -acodec aac -ac 2 -ar 24000 -ab 128 -vol 200 -f psp -muxvb 768 "1.***"

解释:以上命令可以在Dos命令行中输入,也可以创建到批处理文件中运行。不过,前提是:要在ffmpeg所在的目录中执行(转换君所在目录下面的cores子目录)。

参数:

-y(覆盖输出文件,即如果1.***文件已经存在的话,不经提示就覆盖掉了)

-i "1.avi"(输入文件是和ffmpeg在同一目录下的1.avi文件,可以自己加路径,改名字)

-title "Test"(在PSP中显示的影片的标题)

-vcodec xvid(使用XVID编码压缩视频,不能改的)

-s 368x208(输出的分辨率为368x208,注意片源一定要是16:9的不然会变形)

-r 29.97(帧数,一般就用这个吧)

-b 1500(视频数据流量,用-b xxxx的指令则使用固定码率,数字随便改,1500以上没效果;还可以用动态码率如:-qscale 4和-qscale 6,4的质量比6高)

-acodec aac(音频编码用AAC)

-ac 2(声道数1或2)

-ar 24000(声音的采样频率,好像PSP只能支持24000Hz)

-ab 128(音频数据流量,一般选择32、64、96、128)

-vol 200(200%的音量,自己改)

-f psp(输出psp专用格式)

-muxvb 768(好像是给PSP机器识别的码率,一般选择384、512和768,我改成1500,PSP就说文件损坏了)

"1.***"(输出文件名,也可以加路径改文件名)

开几个批处理文件,让它们并行处理。 E:\ffmpeg.exe -i I:\1.wmv -b 360 -r 25 -s 320x240 -hq -deinterlace -ab 56 -ar 22050 -ac 1 D:\2.flv

Ffmpeg使用语法

ffmpeg [[options][`-i' input_file]]... {[options] output_file}...

如果没有输入文件,那么视音频捕捉就会起作用。

作为通用的规则,选项一般用于下一个特定的文件。如果你给 -b 64选项,改选会设置下一个视频速率。对于原始输入文件,格式选项可能是需要的。

缺省情况下,ffmpeg试图尽可能的无损转换,采用与输入同样的音频视频参数来输出。

3.选项

a) 通用选项

-L license

-h 帮助

-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 激活高质量设置

-itsoffset offset 设置以秒为基准的时间偏移,该选项影响所有后面的输入文件。该偏移被加到输入文件的时戳,定义一个正偏移意味着相应的流被延迟了 offset秒。 [-]hh:mm:ss[.xxx]的格式也支持

b) 视频选项

-b bitrate 设置比特率,缺省200kb/s

-r fps 设置帧频 缺省25

-s size 设置帧大小 格式为WXH 缺省160X128.下面的简写也可以直接使用:

Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576

-aspect aspect 设置横纵比 4:3 16:9 或 1.3333 1.7777

-croptop size 设置顶部切除带大小 像素单位

-cropbottom size -cropleft size -cropright size

-padtop size 设置顶部补齐的大小 像素单位

-padbottom size -padleft size -padright size -padcolor color 设置补齐条颜色(hex,6个16进制的数,红:绿:兰排列,比如 000000代表黑色)

-vn 不做视频记录

-bt tolerance 设置视频码率容忍度kbit/s

-maxrate bitrate设置最大视频码率容忍度

-minrate bitreate 设置最小视频码率容忍度

-bufsize size 设置码率控制缓冲区大小

-vcodec codec 强制使用codec编解码方式。 如果用copy表示原始编解码数据必须被拷贝。

-sameq 使用同样视频质量作为源(VBR)

-pass n 选择处理遍数(1或者2)。两遍编码非常有用。第一遍生成统计信息,第二遍生成精确的请求的码率

-passlogfile file 选择两遍的纪录文件名为file

c)高级视频选项

-g gop_size 设置图像组大小

-intra 仅适用帧内编码

-qscale q 使用固定的视频量化标度(VBR)

-qmin q 最小视频量化标度(VBR)

-qmax q 最大视频量化标度(VBR)

-qdiff q 量化标度间最大偏差 (VBR)

-qblur blur 视频量化标度柔化(VBR)

-qcomp compression 视频量化标度压缩(VBR)

-rc_init_cplx complexity 一遍编码的初始复杂度

-b_qfactor factor 在p和b帧间的qp因子

-i_qfactor factor 在p和i帧间的qp因子

-b_qoffset offset 在p和b帧间的qp偏差

-i_qoffset offset 在p和i帧间的qp偏差

-rc_eq equation 设置码率控制方程 默认tex^qComp

-rc_override override 特定间隔下的速率控制重载

-me method 设置运动估计的方法 可用方法有 zero phods log x1 epzs(缺省) full

-dct_algo algo 设置dct的算法 可用的有 0 FF_DCT_AUTO 缺省的DCT 1 FF_DCT_FASTINT 2 FF_DCT_INT 3 FF_DCT_MMX 4 FF_DCT_MLIB 5 FF_DCT_ALTIVEC

-idct_algo algo 设置idct算法。可用的有 0 FF_IDCT_AUTO 缺省的IDCT 1 FF_IDCT_INT 2 FF_IDCT_SIMPLE 3 FF_IDCT_SIMPLEMMX 4 FF_IDCT_LIBMPEG2MMX 5 FF_IDCT_PS2 6 FF_IDCT_MLIB 7 FF_IDCT_ARM 8 FF_IDCT_ALTIVEC 9 FF_IDCT_SH4 10 FF_IDCT_SIMPLEARM

-er n 设置错误残留为n 1 FF_ER_CAREFULL 缺省 2 FF_ER_COMPLIANT 3 FF_ER_AGGRESSIVE 4 FF_ER_VERY_AGGRESSIVE

-ec bit_mask 设置错误掩蔽为bit_mask,该值为如下值的位掩码 1 FF_EC_GUESS_MVS (default=enabled) 2 FF_EC_DEBLOCK (default=enabled)

-bf frames 使用frames B 帧,支持mpeg1,mpeg2,mpeg4

-mbd mode 宏块决策 0 FF_MB_DECISION_SIMPLE 使用mb_cmp 1 FF_MB_DECISION_BITS 2 FF_MB_DECISION_RD

-4mv 使用4个运动矢量 仅用于mpeg4

-part 使用数据划分 仅用于mpeg4

-bug param 绕过没有被自动监测到编码器的问题

-strict strictness 跟标准的严格性

-aic 使能高级帧内编码 h263+

-umv 使能无限运动矢量 h263+

-deinterlace 不采用交织方法

-interlace 强迫交织法编码 仅对mpeg2和mpeg4有效。当你的输入是交织的并且你想要保持交织以最小图像损失的时候采用该选项。可选的方法是不交织,但是损失更大

-psnr 计算压缩帧的psnr

-vstats 输出视频编码统计到vstats_hhmmss.log

-vhook module 插入视频处理模块 module 包括了模块名和参数,用空格分开

D)音频选项

-ab bitrate 设置音频码率

-ar freq 设置音频采样率

-ac channels 设置通道 缺省为1

-an 不使能音频纪录

-acodec codec 使用codec编解码

E)音频/视频捕获选项

-vd device 设置视频捕获设备。比如/dev/video0

-vc channel 设置视频捕获通道 DV1394专用

-tvstd standard 设置电视标准 NTSC PAL(SECAM)

-dv1394 设置DV1394捕获

-av device 设置音频设备 比如/dev/dsp

F)高级选项

-map file:stream 设置输入流映射

-debug 打印特定调试信息

-benchmark 为基准测试加入时间

-hex 倾倒每一个输入包

-bitexact 仅使用位精确算法 用于编解码测试

-ps size 设置包大小,以bits为单位

-re 以本地帧频读数据,主要用于模拟捕获设备

-loop 循环输入流。只工作于图像流,用于ffserver测试

从FLV中截图以及相关PHP代码

从FLV中截图以及相关PHP代码

使用-ss参数 作用(time_off set the start time offset),可以从指定时间点开始转换任务。如:

转换文件格式的同时抓缩微图:

ffmpeg -i "test.avi" -y -f image2 -ss 8 -t 0.001 -s 350x240 'test.jpg" οnlοad="resize(this,466,0)'

对已有flv抓图:

ffmpeg -i "test.flv" -y -f image2 -ss 8 -t 0.001 -s 350x240 'test.jpg'

-ss后跟的时间单位为秒

$streamPath = "./test.flv";

$newName = "myConvertedPic.jpg";

$imgW = 320;

$imgH = 240;

$imgQuality = 80;

$resultPath = "http://www.meinserver.de/snapit/".$newName.".jpg";

exec ("flv2jpg.exe", $streamPath, $newName, $imgW, $imgH, $imgQuality);

==================================================================================================

/usr/bin/ffmpeg -i /root/239.mpg -ar 22050 -b 1000k /root/239_4.flv

截取一张352x240尺寸大小的,格式为jpg的图片:

ffmpeg -i test.asf -y -f image2 -t 0.001 -s 352x240 a.jpg

把视频的前30帧转换成一个Animated Gif :

ffmpeg -i test.asf -vframes 30 -y -f gif a.gif

使用-ss参数,可以从指定的时间开始处理转换任务.如:

ffmpeg -i test2.asf -y -f image2 -ss 08.010 -t 0.001 -s 352x240 b.jpg

ffmpeg 转 FLV 的参数

ffmpeg -i x:\*.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 x:\*.flv

 

ffmpeg参数

  (2011-09-19 15:15:30)

标签: 

杂谈

 

参数

FFmpeg可使用众多参数,参数内容会根据ffmpeg版本而有差异,使用前建议先参考参数及编解码器的叙述。此外,参数明细可用 ffmpeg -h 显示;编解码器名称等明细可用 ffmpeg -formats 显示。

下列为较常使用的参数。

主要参数

  • -i 设定输入档名。
  • -f 设定输出格式。
  • -y 若输出档案已存在时则覆盖档案。
  • -fs 超过指定的档案大小时则结束转换。
  • -ss 从指定时间开始转换。
  • -title 设定标题。
  • -timestamp 设定时间戳。
  • -vsync 增减Frame使影音同步。

影像参数

  • -b 设定影像流量,默认为200Kbit/秒。( 单位请参照下方注意事项 )
  • -r 设定FrameRate值,默认为25。
  • -s 设定画面的宽与高。
  • -aspect 设定画面的比例。
  • -vn 不处理影像,于仅针对声音做处理时使用。
  • -vcodec 设定影像影像编解码器,未设定时则使用与输入档案相同之编解码器。

声音参数

  • -ab 设定每Channel(最近的SVN版为所有Channel的总合)的流量。( 单位请参照下方注意事项 )
  • -ar 设定采样率。
  • -ac 设定声音的Channel数。
  • -acodec 设定声音编解码器,未设定时与影像相同,使用与输入档案相同之编解码器。
  • -an 不处理声音,于仅针对影像做处理时使用。
  • -vol 设定音量大小,256为标准音量。(要设定成两倍音量时则输入512,依此类推。)

注意事项

  • 以-b及ab参数设定流量时,根据使用的ffmpeg版本,须注意单位会有kbits/sec与bits/sec的不同。(可用ffmpeg -h显示说明来确认单位。)

例如,单位为bits/sec的情况时,欲指定流量64kbps时需输入‘ -ab 64k ’;单位为kbits/sec的情况时则需输入‘ -ab 64 ’。

  • 以-acodec及-vcodec所指定的编解码器名称,会根据使用的ffmpeg版本而有所不同。例如使用AAC编解码器时,会有输入aac与libfaac的情况。此外,编解码器有分为仅供解码时使用与仅供编码时使用,因此一定要利用ffmpeg -formats确认输入的编解码器是否能运作。

范例

  • 将MPEG-1影片转换成MPEG-4格式之范例

ffmpeg -i inputfile.mpg -f mp4 -acodec libfaac -vcodec mpeg4 -b 256k -ab 64k outputfile.mp4

  • 将MP3声音转换成MPEG-4格式之范例

ffmpeg -i inputfile.mp3 -f mp4 -acodec libaac -vn -ab 64k outputfile.mp4

  • 将DVD的VOB档转换成VideoCD格式的MPEG-1档之范例

ffmpeg -i inputfile.vob -f mpeg -acodec mp2 -vcodec mpeg1video -s 352x240 -b 1152k -ab 128k outputfile.mpg

  • 将AVI影片转换成H.264格式的M4V档之范例

ffmpeg -i inputfile.avi -f mp4 -acodec libfaac -vcodec libx264 -b 512k -ab 320k outputfile.m4v

  • 将任何影片转换成东芝REGZA可辨识的MPEG2格式之范例

ffmpeg -i inputfile -target ntsc-svcd -ab 128k -aspect 4:3 -s 720x480 outputfile.mpg

  • 连接复数的AVI影片档之范例(在此范例中须一度暂时将AVI档转换成MPEG-1档(MPEG-1, MPEG-2 PS, DV格式亦可连接))

ffmpeg -i input1.avi -sameq inputfile_01.mpg

ffmpeg -i input2.avi -sameq inputfile_02.mpg

cat inputfile_01.mpg inputfile_02.mpg > inputfile_all.mpg

ffmpeg -i inputfile_all.mpg -sameq outputfile.avi

 

-g <integer> (FFmpeg)
Keyframe interval, also known as GOP length. This determines the maximum distance between I-frames. Very high GOP lengths will result in slightly more efficient compression, but will make seeking in the video somewhat more difficult. Recommended default: 250

 

--min-keyint <integer> (x264)
-keyint_min <integer> (FFmpeg)
Minimum GOP length, the minimum distance between I-frames. Recommended default: 25

 

--scenecut <integer> (x264)
-sc_threshold <integer> (FFmpeg)
Adjusts the sensitivity of x264's scenecut detection. Rarely needs to be adjusted. Recommended default: 40

 

--pre-scenecut (x264)
none (FFmpeg)
Slightly faster (but less precise) scenecut detection. Normal scenecut detection decides whether a frame is a scenecut after the frame is encoded, and if so then re-encodes the frame as an I-frame. This is not compatible with threading, however, and so --pre-scenecut is automatically activated when multiple encoding threads are used.

 

--bframes <integer> (x264)
-bf <integer> (FFmpeg)
B-frames are a core element of H.264 and are more efficient in H.264 than any previous standard. Some specific targets, such as HD-DVD and Blu-Ray, have limitations on the number of consecutive B-frames. Most, however, do not; as a result, there is rarely any negative effect to setting this to the maximum (16) since x264 will, if B-adapt is used, automatically choose the best number of B-frames anyways. This parameter simply serves to limit the max number of B-frames. Note that Baseline Profile, such as that used by iPods, does not support B-frames. Recommended default: 16

 

--b-adapt <integer> (x264)
-b_strategy <integer> (FFmpeg)
x264, by default, adaptively decides through a low-resolution lookahead the best number of B-frames to use. It is possible to disable this adaptivity; this is not recommended. Recommended default: 1

0: Very fast, but not recommended. Does not work with pre-scenecut (scenecut must be off to force off b-adapt).

1: Fast, default mode in x264. A good balance between speed and quality.

2: A much slower but more accurate B-frame decision mode that correctly detects fades and generally gives considerably better quality. Its speed gets considerably slower at high bframes values, so its recommended to keep bframes relatively low (perhaps around 3) when using this option. It also may slow down the first pass of x264 when in threaded mode.

 

--b-bias 0 (x264)
-bframebias 0 (FFmpeg)
Make x264 more likely to choose higher numbers of B-frames during the adaptive lookahead. Not generally recommended. Recommended default: 0

 

--b-pyramid (x264)
-flags2 +bpyramid (FFmpeg)
Allows B-frames to be kept as references. The name is technically misleading, as x264 does not actually use pyramid coding; it simply adds B-references to the normal reference list. B-references get a quantizer halfway between that of a B-frame and P-frame. This setting is generally beneficial, but it increases the DPB (decoding picture buffer) size required for playback, so when encoding for hardware, disabling it may help compatibility.

 

--no-cabac (x264)
-coder 0 (FFmpeg)
CABAC is the default entropy encoder used by x264. Though somewhat slower on both the decoding and encoding end, it offers 10-15% improved compression on live-action sources and considerably higher improvements on animated sources, especially at low bitrates. It is also required for the use of trellis quantization. Disabling CABAC may somewhat improve decoding performance, especially at high bitrates. CABAC is not allowed in Baseline Profile. Recommended default: -coder 1 (CABAC enabled)

 

--ref <integer> (x264)
-refs <integer> (FFmpeg)
One of H.264's most useful features is the abillity to reference frames other than the one immediately prior to the current frame. This parameter lets one specify how many references can be used, through a maximum of 16. Increasing the number of refs increases the DPB (Decoded Picture Buffer) requirement, which means hardware playback devices will often have strict limits to the number of refs they can handle. In live-action sources, more reference have limited use beyond 4-8, but in cartoon sources up to the maximum value of 16 is often useful. More reference frames require more processing power because every frame is searched by the motion search (except when an early skip decision is made). The slowdown is especially apparent with slower motion estimation methods. Recommended default: -refs 6

 

--no-deblock (x264)
-flags -loop (FFmpeg)
Disable loop filter. Recommended default: -flags +loop (Enabled)

 

--deblock <alpha:beta> (x264)
-deblockalpha <integer> (FFmpeg)
-deblockbeta <integer> (FFmpeg)
One of H.264's main features is the in-loop deblocker, which avoids the problem of blocking artifacts disrupting motion estimation. This requires a small amount of decoding CPU, but considerably increases quality in nearly all cases. Its strength may be raised or lowered in order to avoid more artifacts or keep more detail, respectively. Deblock has two parameters: alpha (strength) and beta (threshold). Recommended defaults:-deblockalpha 0 -deblockbeta 0 (Must have '-flags +loop')

 

--interlaced (x264)
none(FFmpeg)
Enables interlaced encoding. x264's interlaced encoding is not as efficient as its progressive encoding; consider deinterlacing for maximum effectiveness.

Ratecontrol:

--qp <integer> (x264)
-cqp <integer> (FFmpeg)
Constant quantizer mode. Not exactly constant completely--B-frames and I-frames have different quantizers from P-frames. Generally should not be used, since CRF gives better quality at the same bitrate.

 

--bitrate <integer> (x264)
-b <integer> (FFmpeg)
Enables target bitrate mode. Attempts to reach a specific bitrate. Should be used in 2-pass mode whenever possible; 1-pass bitrate mode is generally the worst ratecontrol mode x264 has.

 

--crf <float> (x264)
-crf <float> (FFmpeg)
Constant quality mode (also known as constant ratefactor). Bitrate corresponds approximately to that of constant quantizer, but gives better quality overall at little speed cost. The best one-pass option in x264.

 

--vbv-maxrate <integer> (x264)
-maxrate <integer> (FFmpeg)
Specifies the maximum bitrate at any point in the video. Requires the VBV buffersize to be set. This option is generally used when encoding for a piece of hardware with bitrate limitations.

 

--vbv-bufsize <integer> (x264)
-bufsize <integer> (FFmpeg)
Depends on the profile level of the video being encoded. Set only if you're encoding for a hardware device.

 

--vbv-init <float> (x264)
-rc_init_occupancy <float> (FFmpeg)
Initial VBV buffer occupancy. Note: Don't mess with this.

 

--qpmin <integer> (x264)
-qmin <integer> (FFmpeg)
Minimum quantizer. Doesn't need to be changed. Recommended default: -qmin 10

 

--qpmax <integer> (x264)
-qmax <integer> (FFmpeg)
Maximum quantizer. Doesn't need to be changed. Recommended default: -qmax 51

 

--qpstep <integer> (x264)
-qdiff <integer> (FFmpeg)
Set max QP step. Recommended default: -qdiff 4

 

--ratetol <float> (x264)
-bt <float> (FFmpeg)
Allowed variance of average bitrate

 

--ipratio <float> (x264)
-i_qfactor <float> (FFmpeg)
Qscale difference between I-frames and P-frames. Note: -i_qfactor is handled a little differently than --ipratio. Recommended: -i_qfactor 0.71

 

--pbratio <float> (x264)
-b_qfactor <float> (FFmpeg)
Qscale difference between P-frames and B-frames.

 

--chroma-qp-offset <integer> (x264)
-chromaoffset <integer> (FFmpeg)
QP difference between chroma and luma.

 

--aq-strength <float> (x264)
none (FFmpeg)
Adjusts the strength of adaptive quantization. Higher values take more bits away from complex areas and edges and move them towards simpler, flatter areas to maintain fine detail. Default: 1.0

 

--pass <1,2,3> (x264)
-pass <1,2,3> (FFmpeg)
Used with --bitrate. Pass 1 writes the stats file, pass 2 reads it, and 3 both reads and writes it. If you want to use three pass, this means you will have to use --pass 1 for the first pass, --pass 3 for the second, and --pass 2 or 3 for the third.

 

--stats <string> (x264)
none (FFmpeg)
Allows setting a specific filename for the firstpass stats file.

 

--rceq <string> (x264)
-rc_eq <string> (FFmpeg)
Ratecontrol equation. Recommended default: -rc_eq 'blurCplx^(1-qComp)'
--qcomp <float> (x264)
-qcomp <float> (FFmpeg)
QP curve compression: 0.0 => CBR, 1.0 => CQP. Recommended default: -qcomp 0.60

 

--cplxblur <float> (x264)
-complexityblur <float>(FFmpeg)


Reduce fluctuations in QP (before curve compression) [20.0]

 

--qblur <float> (x264)
-qblur <float> (FFmpeg)
Reduce fluctuations in QP (after curve compression) [0.5]

 

--zones <zone0>/<zone1> (x264)
none (FFmpeg)
Allows setting a specific quantizer for a specific region of video.

 

--qpfile (x264)
none (FFmpeg)
Allows one to read in a set of frametypes and quantizers from a file. Useful for testing various encoding options while ensuring the exact same quantizer distribution.

Analysis:

--partitions <string> (x264)
-partitions <string> (FFmpeg)

p8x8 (x264) /+partp8x8 (FFmpeg)

p4x4 (x264) /+partp4x4 (FFmpeg)

b8x8 (x264) /+partb8x8 (FFmpeg)

i8x8 (x264) /+parti8x8 (FFmpeg)

i4x4 (x264) /+parti4x4 (FFmpeg)

One of H.264's most useful features is the ability to choose among many combinations of inter and intra partitions. P-macroblocks can be subdivided into 16x8, 8x16, 8x8, 4x8, 8x4, and 4x4 partitions. B-macroblocks can be divided into 16x8, 8x16, and 8x8 partitions. I-macroblocks can be divided into 4x4 or 8x8 partitions. Analyzing more partition options improves quality at the cost of speed. The default is to analyze all partitions except p4x4 (p8x8, i8x8, i4x4, b8x8), since p4x4 is not particularly useful except at high bitrates and lower resolutions. Note that i8x8 requires 8x8dct, and is therefore a High Profile-only partition. p8x8 is the most costly, speed-wise, of the partitions, but also gives the most benefit. Generally, whenever possible, all partition types except p4x4 should be used.

 

--direct <integer> (x264)
-directpred <integer> (FFmpeg)
B-frames in H.264 can choose between spatial and temporal prediction mode. Auto allows x264 to pick the best of these; the heuristic used is whichever mode allows more skip macroblocks. Auto should generally be used.

 

--weightb (x264)
-flags2 +wpred (FFmpeg)
This allows B-frames to use weighted prediction options other than the default. There is no real speed cost for this, so it should always be enabled.

 

--me <dia,hex,umh,esa> (x264)
-me_method <epzs,hex,umh,full> (FFmpeg)

dia (x264) / epzs (FFmpeg) is the simplest search, consisting of starting at the best predictor, checking the motion vectors at one pixel upwards, left, down, and to the right, picking the best, and repeating the process until it no longer finds any better motion vector.

hex (x264) / hex (FFmpeg) consists of a similar strategy, except it uses a range-2 search of 6 surrounding points, thus the name. It is considerably more efficient than DIA and hardly any slower, and therefore makes a good choice for general-use encoding.

umh (x264) / umh (FFmpeg) is considerably slower than HEX, but searches a complex multi-hexagon pattern in order to avoid missing harder-to-find motion vectors. Unlike HEX and DIA, the merange parameter directly controls UMH's search radius, allowing one to increase or decrease the size of the wide search.

esa (x264) / full (FFmpeg) is a highly optimized intelligent search of the entire motion search space within merange of the best predictor. It is mathematically equivalent to the bruteforce method of searching every single motion vector in that area, though faster. However, it is still considerably slower than UMH, with not too much benefit, so is not particularly useful for everyday encoding.

One of the most important settings for x264, both speed and quality-wise.

 

--merange <integer> (x264)
-me_range <integer> (FFmpeg)
MErange controls the max range of the motion search. For HEX and DIA, this is clamped to between 4 and 16, with a default of 16. For UMH and ESA, it can be increased beyond the default 16 to allow for a wider-range motion search, which is useful on HD footage and for high-motion footage. Note that for UMH and ESA, increasing MErange will significantly slow down encoding.

 

--mvrange (x264)
none (FFmpeg)
Limits the maximum motion vector range. Since x264 by default limits this to 511.75 for standards compliance, this should not be changed.

 

--subme 6 (x264)
-subq 6 (FFmpeg)

1: Fastest, but extremely low quality. Should be avoided except on first pass encoding.

2-5: Progressively better and slower, 5 serves as a good medium for higher speed encoding.

6-7: 6 is the default. Activates rate-distortion optimization for partition decision. This can considerably improve efficiency, though it has a notable speed cost. 6 activates it in I/P frames, and subme7 activates it in B frames.

8-9: Activates rate-distortion refinement, which uses RDO to refine both motion vectors and intra prediction modes. Slower than subme 6, but again, more efficient.

An extremely important encoding parameter which determines what algorithms are used for both subpixel motion searching and partition decision.

 

--psy-rd <float>:<float> (x264)
none (FFmpeg)
First value represents the amount that x264 biases in favor of detail retention instead of max PSNR in mode decision. Requires subme >= 6. Second value is psy-trellis, an experimental algorithm that tries to improve sharpness and detail retention at the expense of more artifacting. Recommended starting values are 0.1-0.2. Requires trellis >= 1. Recommended default: 1.0:0.0

 

--mixed-refs (x264)
-flags2 +mixed_refs (FFmpeg)
H.264 allows p8x8 blocks to select different references for each p8x8 block. This option allows this analysis to be done, and boosts quality with little speed impact. It should generally be used, though it obviously has no effect with only one reference frame.

 

--no-chroma-me (x264)
none (FFmpeg)
Chroma is used in the last steps of the subpixel refinement by default. For a slight speed increase, this can be disabled (at the cost of quality).

 

--8x8dct (x264)
-flags2 +dct8x8 (FFmpeg)
Gives a notable quality boost by allowing x264 to choose between 8x8 and 4x4 frequency transform size. Required for i8x8 partitions. Speed cost for this option is near-zero both for encoding and decoding; the only reason to disable it is when one needs support on a device not compatible with High Profile.

 

--trellis <0,1,2> (x264)
-trellis <0,1,2> (FFmpeg)

0: disabled

1: enabled only on the final encode of a MB

2: enabled on all mode decisions

The main decision made in quantization is which coefficients to round up and which to round down. Trellis chooses the optimal rounding choices for the maximum rate-distortion score, to maximize PSNR relative to bitrate. This generally increases quality relative to bitrate by about 5% for a somewhat small speed cost. It should generally be enabled. Note that trellis requires CABAC.

 

--no-fast-pskip (x264)
-flags2 -fastpskip (FFmpeg)
By default, x264 will skip macroblocks in P-frames that don't appear to have changed enough between two frames to justify encoding the difference. This considerably speeds up encoding. However, for a slight quality boost, P-skip can be disabled. In this case, the full analysis will be done on all P-blocks, and the only skips in the output stream will be the blocks whose motion vectors happen to match that of the skip vector and motion vectors happen to match that of the skip vector and which have no residual. The speed cost of enabling no-fast-pskip is relatively high, especially with many reference frames. There is a similar B-skip internal to x264, which is why B-frames generally encode much faster than P-frames, but it cannot be disabled on the commandline.

 

--no-dct-decimate(x264)
none(FFmpeg)
By default, x264 will decimate (remove all coefficients from) P-blocks that are extremely close to empty of coefficents. This can improve overall efficiency with little visual cost, but may work against an attempt to retain grain or similar. DCT decimation should be left on unless there's a good reason to disable it.

 

--nr(x264)
none(FFmpeg)
a fast, built-in noise reduction routine. Not as effective as external filters such as hqdn3d, but faster. Since x264 already naturally reduces noise through its quantization process, this parameter is not usually necessary.

 

--deadzone-inter (264)
--deadzone-intra (x264)
none (FFmpeg)
none (FFmpeg)
When trellis isn't activated, deadzone parameters determine how many DCT coefficients are rounded up or down. Rounding up results in higher quality and more detail retention, but costs more bits--so rounding is a balance between quality and bit cost. Lowering these settings will result in more coefficients being rounded up, and raising the settings will result in more coefficients being rounded down. Recommended: keep them at the defaults.

 

--cqm (264)
--cqpfile (x264)
none (FFmpeg)
none (FFmpeg)
Allows the use of a custom quantization matrix to weight frequencies differently in the quantization process. The presets quant matrices are "jvt" and "flat". --cqpfile reads a custom quant matrices from a JM-compatible file. Recommended only if you know what you're doing.

 

 

 

使用ffmpeg进行.264编码的相关文章比较少,google了一下,特总结如下:

qscale的取值可以是0.01-255但实际使用超过50就很糟糕了ffmpeg的cbr模式可以把码率控制的不错,但是vbr无法限制最高码率(虽然有max的设置,但是程序没有实现)x264标准的封装是x264+aac in flv或者x264+aac in MP4

接下来说明下ffmpeg命令行的语法规则(本块内容来自2009-03-02官方文档):
语法规则结构:
ffmpeg [[infile options][`-i'infile]]... {[outfile options] outfile}...
一个最简单的命令形式:
ffmpeg -i input.avi -b 64k output.avi
这个命令把视频以64k的码率重编码。
显然,输入文件前面要加一个-i选项下面介绍一些有用的全局参数:
-formats 参数。会显示你机器当前支持的封装、编码、解码器的信息-y参数,会指示ffmpeg覆盖输出文件-t 指定视频流持续的时常,支持以秒为单位的数字或"时:分:秒[.毫秒]"-fs 指定输出文件大小的限制-ss 指定开始的时间,和-t的单位一样-target 直接设定你想要转成的目标格式,所有的相关设置都会采用内设值,当然也你也可以加上自己要修改的参数。可用的选择有:
"vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...
这个例子把视频转换成vcd的格式
ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg接下来介绍视频选项:
-b 指定码率注意单位是bit/s,所以我们一般要加k,比如 -b 1000k 就是1000kb/s-g 设置组的大小
-vframes 指定要编码的帧数,比如-vframes 1 就是编码1帧,截图的时候就这样写.-r 指定帧率,默认是25-s 指定图像分辨率,用wxh的格式,比如320x240-aspect 指定宽高比 可以些16:9这种,也可以写小数比如1.3333-croptop 指定顶部裁减多少像素,类似的还有-cropleft -cropright -cropbuttom-bt 设置比特率容许的误差,默认4000k,在第一阶段时使用这个参数会告诉码率控制器能够偏移平均码率多远,这个选项和最大最小码率无关.设太小了不利于质量-maxrate 和-minrate 指定允许的最大和最小码率,一般如果要用cbr模式编码的话会用这个:
ffmpeg -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v
否则用处不大-vcodec 强制使用某种编码器-sameq 使用和源文件相同的质量,这个选项是动态码率的-pass 指定编码阶段,这个只有1和2,第一阶段的时候应该不处理音频,并且把输出导向空,比如:
ffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y NUL
ffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y /dev/null-qscale 使用固定量化因子来量化视频这个是在vbr模式的,前面有提到,越小质量越好,不要超过50,相关的参数还有-qmin --qmax用来设定最大最小可使用的量化值-qdiff 指定固定量化器因子允许的最大偏差-qblur 指定量化器模糊系数,可用范围是0.0-1.0越大使得码率在时间上分配的越平均-qcomp 指定视频量化器压缩系数,默认0.5-me_method 指定运动估计方法(motion estimation method),可用的选择从垃圾到好排列如下:
zero (0向量)
phods
log
x1
hex
umh
epzs (默认)
full (完全搜索,很慢又好不到哪里去)-mbd 设定宏模块决策,可用的值:
0 使用mb_cmp,不知道是什么东西,所以这些参数我参考一下mencoder里面的
1 选用需要比特最少的宏块模式
2 选用码率失真最优的宏块模式-4mv 使用宏块的4个运动向量,只支持mpeg4-part 使用数据划分,只支持mpeg4-ilme 强制允许交错的编码,只支持mpeg2和mpeg4,你可以选择用-deinterlace来去交错
音频部分:
-ar 设置采样频率,默认44100hz-ab 设置比特率,默认64k-an 禁用音频录制-acodec 指定音频编码器


下面举几个x264编码的例子:
我使用mencoder调用x264编码一个psp用的视频:
x264+aac in mp4 for psp
mencoder -oac lavc -lavcopts acodec=libfaac:abitrate=94 -ovc x264 -x264encopts cabac=1:ref=3:deblock=1,-1,-1:analyse=0x1:0x111:me=umh:subme=9:psy_rd=0.9,0.0:mixed_ref=1:me_range=32:chroma_me=1:trellis=2:8x8dct=0:cmp=0:deadzone=21,11:chroma_qp_offset=-2:nr=0:decimate=0:mbaff=0:bframes=2:b_pyramid=0:b_adapt=1:b_bias=0:direct=3:wpredb=1:keyint=250:keyint_min=25:scenecut=40:rc=cqp:qp=18:ip_ratio=1.40:pb_ratio=1.30:aq=0 -lavdopts er=2 -pp 6 -of lavf -lavfopts format=psp -vf scale=480:-3
对应的ffmpeg编码参数是:
ffmpeg
ffmpeg -i inputfile.avi -f psp -acodec libfaac -ab 94k -vcodec libx264 -cqp 28 -coder 1 -refs 3 -deblockalpha 1 -deblockbeta -1 -me_method umh -subq 9 -me_range 32 -trellis 2 -chromaoffset -2 -nr 0 -bf 2 -b_strategy 1 -bframebias 0 -directpred 3 -g 250 -i_qfactor 1.3 -b_qfactor 1.4 -flags2 +bpyramid+wpred+mixed_refs+8x8dct -er 2 -s 480x320
需要注意的是,flags2里面那块,似乎要按照一定顺序才能正常工作,其他地方都差不多,详细情况可以从下面两篇文章得出:
第一篇是这个在网上被传了很多,但有些问题的对照表格,我修改了有问题的部分:

   

-g <frames>

--keyint

-b <bits per second>

--bitrate

-bufsize <bits>

--vbv-bufsize

-maxrate <bits>

--vbv-maxrate

-pass <1,2,3>

--pass

-crf <float>

--crf

-cqp <int>

--qp

-bf <int>

--bframes

-coder <0,1>

--no-cabac

-bframebias <int>

--b-bias

-keyint_min <int>

--min-keyint

-sc_threshold <int>

--scenecut

-deblockalpha <int>-deblockbeta <int>

--deblock

-qmin <int>

--qpmin

-qmax <int>

--qpmax

-qdiff <int>

--qpstep

-qcomp <float>

--qcomp

-qblur <float>

--qblur

-complexityblur <float>

--cplxblur

-refs <int>

--ref

-directpred <int>

--direct

-me_method <epzs,hex,umh,full>

--me

-me_range <int>

--merange

-subq <int>

--subme

-bidir_refine <0,1>

--bime

-trellis <0,1,2>

--trellis

-nr <int>

--nr

-level <int>

--level

-bt <bits>

--ratetol = -bt / -b

-rc_init_occupancy <bits>

--vbv-init = -rc_init_occupancy / -bufsize

-i_qfactor <float>

--ipratio = 1 / -i_qfactor

-b_qfactor <float>

--pbratio

-chromaoffset <int>

--chroma-qp-offset

-rc_eq <string>

--rc_eq

-threads <int>

--threads

-cmp <-chroma/+chroma>

--no-chroma-me

-partitions

--partitions

+parti8×8

i8×8

+parti4×4

i4×4

+partp8×8

p8×8

+partp4×4

p4×4

+partb8×8

b8×8

-flags

 

-loop/+loop

--no-deblock/–deblock

-psnr/+psnr

--no-psnr/nothing

-flags2

 

+bpyramid

--b-pyramid

+wpred

--weightb

+brdo

--b-rdo 我这里的ffmpeg已经不能用这个了

+mixed_refs

--mixed-refs

+dct8×8

--8×8dct

-fastpskip/+fastpskip

--no-fast-pskip

+aud

--aud



下面是一篇关于这些参数详细解释的文章,转自:http://ffmpeg.x264.googlepages.com/mapping
一下是这篇文章在2008年11月19日更新的版本:
Frame-type options:--keyint <integer> (x264)
-g <integer>
 (FFmpeg)
Keyframe interval, also known as GOP length. This determines the maximum distance between I-frames. Very high GOP lengths will result in slightly more efficient compression, but will make seeking in the video somewhat more difficult. Recommended default: 250
--min-keyint <integer> (x264)
-keyint_min <integer> (FFmpeg)
Minimum GOP length, the minimum distance between I-frames. Recommended default: 25
--scenecut <integer> (x264)
-sc_threshold <integer> (FFmpeg)
Adjusts the sensitivity of x264's scenecut detection. Rarely needs to be adjusted. Recommended default: 40
--pre-scenecut (x264)
UNKNOWN (FFmpeg)
Slightly faster (but less precise) scenecut detection. Normal scenecut detection decides whether a frame is a scenecut after the frame is encoded, and if so then re-encodes the frame as an I-frame. This is not compatible with threading, however, and so --pre-scenecut is automatically activated when multiple encoding threads are used.

--bframes <integer> (x264)
-bf <integer> (FFmpeg)
B-frames are a core element of H.264 and are more efficient in H.264 than any previous standard. Some specific targets, such as HD-DVD and Blu-Ray, have limitations on the number of consecutive B-frames. Most, however, do not; as a result, there is rarely any negative effect to setting this to the maximum (16) since x264 will, if B-adapt is used, automatically choose the best number of B-frames anyways. This parameter simply serves to limit the max number of B-frames. Note that Baseline Profile, such as that used by iPods, does not support B-frames. Recommended default: 16

--b-adapt <integer> (x264)
-b_strategy <integer> (FFmpeg)
x264, by default, adaptively decides through a low-resolution lookahead the best number of B-frames to use. It is possible to disable this adaptivity; this is not recommended. Recommended default: 1

0: Very fast, but not recommended. Does not work with pre-scenecut (scenecut must be off to force off b-adapt).

1: Fast, default mode in x264. A good balance between speed and quality.

2: A much slower but more accurate B-frame decision mode that correctly detects fades and generally gives considerably better quality. Its speed gets considerably slower at high bframes values, so its recommended to keep bframes relatively low (perhaps around 3) when using this option. It also may slow down the first pass of x264 when in threaded mode.


--b-bias 0 (x264)
-bframebias 0 (FFmpeg)
Make x264 more likely to choose higher numbers of B-frames during the adaptive lookahead. Not generally recommended. Recommended default: 0
--b-pyramid (x264)
-flags2 +bpyramid (FFmpeg)
Allows B-frames to be kept as references. The name is technically misleading, as x264 does not actually use pyramid coding; it simply adds B-references to the normal reference list. B-references get a quantizer halfway between that of a B-frame and P-frame. This setting is generally beneficial, but it increases the DPB (decoding picture buffer) size required for playback, so when encoding for hardware, disabling it may help compatibility.
--no-cabac (x264)
-coder 0,1 (FFmpeg)
CABAC is the default entropy encoder used by x264. Though somewhat slower on both the decoding and encoding end, it offers 10-15% improved compression on live-action sources and considerably higher improvements on animated sources, especially at low bitrates. It is also required for the use of trellis quantization. Disabling CABAC may somewhat improve decoding performance, especially at high bitrates. CABAC is not allowed in Baseline Profile. Recommended default: -coder 1 (CABAC enabled)

--ref <integer> (x264)
-refs <integer> (FFmpeg)
One of H.264's most useful features is the abillity to reference frames other than the one immediately prior to the current frame. This parameter lets one specify how many references can be used, through a maximum of 16. Increasing the number of refs increases the DPB (Decoded Picture Buffer) requirement, which means hardware playback devices will often have strict limits to the number of refs they can handle. In live-action sources, more reference have limited use beyond 4-8, but in cartoon sources up to the maximum value of 16 is often useful. More reference frames require more processing power because every frame is searched by the motion search (except when an early skip decision is made). The slowdown is especially apparent with slower motion estimation methods. Recommended default: -refs 6
--no-deblock (x264)
-flags -loop (FFmpeg)
Disable loop filter. Recommended default: -flags +loop (Enabled)
--deblock (x264)
-deblockalpha <integer>(FFmpeg)
-deblockbeta <integer>(FFmpeg)
One of H.264's main features is the in-loop deblocker, which avoids the problem of blocking artifacts disrupting motion estimation. This requires a small amount of decoding CPU, but considerably increases quality in nearly all cases. Its strength may be raised or lowered in order to avoid more artifacts or keep more detail, respectively. Deblock has two parameters: alpha (strength) and beta (threshold). Recommended defaults:-deblockalpha 0 -deblockbeta 0 (Must have '-flags +loop')
--interlaced (x264)
UNKNOWN (FFmpeg)
Enables interlaced encoding. x264's interlaced encoding is not as efficient as its progressive encoding; consider deinterlacing for maximum effectiveness.Ratecontrol:--qp <integer>(x264)
-cqp <integer>(FFmpeg)
Constant quantizer mode. Not exactly constant completely--B-frames and I-frames have different quantizers from P-frames. Generally should not be used, since CRF gives better quality at the same bitrate.
--bitrate <integer>(x264)
-b <integer>(FFmpeg)
Enables target bitrate mode. Attempts to reach a specific bitrate. Should be used in 2-pass mode whenever possible; 1-pass bitrate mode is generally the worst ratecontrol mode x264 has.

--crf <float>(x264)
-crf <float>(FFmpeg)
Constant quality mode (also known as constant ratefactor). Bitrate corresponds approximately to that of constant quantizer, but gives better quality overall at little speed cost. The best one-pass option in x264.
--vbv-maxrate <integer>(x264)
-maxrate <integer>(FFmpeg)
Specifies the maximum bitrate at any point in the video. Requires the VBV buffersize to be set. This option is generally used when encoding for a piece of hardware with bitrate limitations.
--vbv-bufsize <integer>(x264)
-bufsize <integer> (FFmpeg)
Depends on the profile level of the video being encoded. Set only if you're encoding for a hardware device.
--vbv-init <float>(x264)
-rc_init_occupancy <float>(FFmpeg)
Initial VBV buffer occupancy. Note: Don't mess with this.
--qpmin <integer> (x264)
-qmin <integer> (FFmpeg)
Minimum quantizer. Doesn't need to be changed. Recommended default: -qmin 10
--qpmax <integer> (x264)
-qmax <integer> (FFmpeg)
Maximum quantizer. Doesn't need to be changed. Recommended default: -qmax 51
--qpstep <integer> (x264)
-qdiff <integer> (FFmpeg)
Set max QP step. Recommended default: -qdiff 4
--ratetol <float>(x264)
-bt <float>(FFmpeg)
Allowed variance of average bitrate
--ipratio <float>(x264)
-i_qfactor <float>(FFmpeg)
Qscale difference between I-frames and P-frames.
--pbratio <float>(x264)
-b_qfactor <float>(FFmpeg)
Qscale difference between P-frames and B-frames.
--chroma-qp-offset <integer>(x264)
-chromaoffset <integer>(FFmpeg)
QP difference between chroma and luma.
--aq-strength <float> (x264)
UNKNOWN (FFmpeg)
Adjusts the strength of adaptive quantization. Higher values take more bits away from complex areas and edges and move them towards simpler, flatter areas to maintain fine detail. Default: 1.0
--pass <1,2,3> (x264)
-pass <1,2,3>(FFmpeg)
Used with --bitrate. Pass 1 writes the stats file, pass 2 reads it, and 3 both reads and writes it. If you want to use three pass, this means you will have to use --pass 1 for the first pass, --pass 3 for the second, and --pass 2 or 3 for the third.

--stats <string>(x264)
UNKNOWN (FFmpeg)
Allows setting a specific filename for the firstpass stats file.
--rceq <string>(x264)
-rc_eq <string>(FFmpeg)
Ratecontrol equation. Recommended default: -rc_eq 'blurCplx^(1-qComp)'
--qcomp <float>(x264)
-qcomp <float> (FFmpeg)
QP curve compression: 0.0 => CBR, 1.0 => CQP. Recommended default: -qcomp 0.60
--cplxblur <float>(x264)
-complexityblur <float>(FFmpeg)
Reduce fluctuations in QP (before curve compression) [20.0]
--qblur <float>(x264)
-qblur <float>(FFmpeg)
Reduce fluctuations in QP (after curve compression) [0.5]
--zones /(x264)
UNKNOWN (FFmpeg)
Allows setting a specific quantizer for a specific region of video.
--qpfile (x264)
UNKNOWN (FFmpeg)
Allows one to read in a set of frametypes and quantizers from a file. Useful for testing various encoding options while ensuring the exact same quantizer distribution.
Analysis:--partitions <string> (x264)
-partitions <string> (FFmpeg)

p8x8 (x264) /+partp8x8 (FFmpeg)

p4x4 (x264) /+partp4x4 (FFmpeg)

b8x8 (x264) /+partb8x8 (FFmpeg)

i8x8 (x264) /+parti8x8 (FFmpeg)

i4x4 (x264) /+parti4x4 (FFmpeg)

One of H.264's most useful features is the ability to choose among many combinations of inter and intra partitions. P-macroblocks can be subdivided into 16x8, 8x16, 8x8, 4x8, 8x4, and 4x4 partitions. B-macroblocks can be divided into 16x8, 8x16, and 8x8 partitions. I-macroblocks can be divided into 4x4 or 8x8 partitions. Analyzing more partition options improves quality at the cost of speed. The default is to analyze all partitions except p4x4 (p8x8, i8x8, i4x4, b8x8), since p4x4 is not particularly useful except at high bitrates and lower resolutions. Note that i8x8 requires 8x8dct, and is therefore a High Profile-only partition. p8x8 is the most costly, speed-wise, of the partitions, but also gives the most benefit. Generally, whenever possible, all partition types except p4x4 should be used.
--direct <integer>(x264)
-directpred <integer>(FFmpeg)
B-frames in H.264 can choose between spatial and temporal prediction mode. Auto allows x264 to pick the best of these; the heuristic used is whichever mode allows more skip macroblocks. Auto should generally be used.
--direct-8x8 (x264)
UNKONWN (FFmpeg)
This should be left at the default (-1).
--weightb (x264)
-flags2 +wpred(FFmpeg)
This allows B-frames to use weighted prediction options other than the default. There is no real speed cost for this, so it should always be enabled.
--me (x264)
-me_method (FFmpeg)

dia (x264) / epzs (FFmpeg) is the simplest search, consisting of starting at the best predictor, checking the motion vectors at one pixel upwards, left, down, and to the right, picking the best, and repeating the process until it no longer finds any better motion vector.

hex (x264) / hex (FFmpeg) consists of a similar strategy, except it uses a range-2 search of 6 surrounding points, thus the name. It is considerably more efficient than DIA and hardly any slower, and therefore makes a good choice for general-use encoding.

umh (x264) / umh (FFmpeg) is considerably slower than HEX, but searches a complex multi-hexagon pattern in order to avoid missing harder-to-find motion vectors. Unlike HEX and DIA, the merange parameter directly controls UMH's search radius, allowing one to increase or decrease the size of the wide search.

esa (x264) / full (FFmpeg) is a highly optimized intelligent search of the entire motion search space within merange of the best predictor. It is mathematically equivalent to the bruteforce method of searching every single motion vector in that area, though faster. However, it is still considerably slower than UMH, with not too much benefit, so is not particularly useful for everyday encoding.

One of the most important settings for x264, both speed and quality-wise.
--merange <integer>(x264)
-me_range <integer>(FFmpeg)
MErange controls the max range of the motion search. For HEX and DIA, this is clamped to between 4 and 16, with a default of 16. For UMH and ESA, it can be increased beyond the default 16 to allow for a wider-range motion search, which is useful on HD footage and for high-motion footage. Note that for UMH and ESA, increasing MErange will significantly slow down encoding.
--mvrange(x264)
UNKNOWN (FFmpeg)
Limits the maximum motion vector range. Since x264 by default limits this to 511.75 for standards compliance, this should not be changed.
--subme 6(x264)
-subq 6(FFmpeg)

1: Fastest, but extremely low quality. Should be avoided except on first pass encoding.

2-5: Progressively better and slower, 5 serves as a good medium for higher speed encoding.

6-7: 6 is the default. Activates rate-distortion optimization for partition decision. This can considerably improve efficiency, though it has a notable speed cost. 6 activates it in I/P frames, and subme7 activates it in B frames.

8-9: Activates rate-distortion refinement, which uses RDO to refine both motion vectors and intra prediction modes. Slower than subme 6, but again, more efficient.

An extremely important encoding parameter which determines what algorithms are used for both subpixel motion searching and partition decision.
--psy-rd <float>:<float> (x264)
UNKNOWN (FFmpeg)
First value represents the amount that x264 biases in favor of detail retention instead of max PSNR in mode decision. Requires subme >= 6. Second value is psy-trellis, an experimental algorithm that tries to improve sharpness and detail retention at the expense of more artifacting. Recommended starting values are 0.1-0.2. Requires trellis >= 1. Recommended default: 1.0:0.0
--mixed-refs(x264)
-flags2 +mixed_refs(FFmpeg)
H.264 allows p8x8 blocks to select different references for each p8x8 block. This option allows this analysis to be done, and boosts quality with little speed impact. It should generally be used, though it obviously has no effect with only one reference frame.
--no-chroma-me(x264)
UNKNOWN (FFmpeg)
Chroma is used in the last steps of the subpixel refinement by default. For a slight speed increase, this can be disabled (at the cost of quality).
--8x8dct (x264)
-flags2 +dct8x8(FFmpeg)
Gives a notable quality boost by allowing x264 to choose between 8x8 and 4x4 frequency transform size. Required for i8x8 partitions. Speed cost for this option is near-zero both for encoding and decoding; the only reason to disable it is when one needs support on a device not compatible with High Profile.
--trellis <0,1,2>(x264)
-trellis <0,1,2>(FFmpeg)

0: disabled

1: enabled only on the final encode of a MB

2: enabled on all mode decisions

The main decision made in quantization is which coefficients to round up and which to round down. Trellis chooses the optimal rounding choices for the maximum rate-distortion score, to maximize PSNR relative to bitrate. This generally increases quality relative to bitrate by about 5% for a somewhat small speed cost. It should generally be enabled. Note that trellis requires CABAC.
--no-fast-pskip(x264)
-flags2 -fastpskip(FFmpeg)
By default, x264 will skip macroblocks in P-frames that don't appear to have changed enough between two frames to justify encoding the difference. This considerably speeds up encoding. However, for a slight quality boost, P-skip can be disabled. In this case, the full analysis will be done on all P-blocks, and the only skips in the output stream will be the blocks whose motion vectors happen to match that of the skip vector and motion vectors happen to match that of the skip vector and which have no residual. The speed cost of enabling no-fast-pskip is relatively high, especially with many reference frames. There is a similar B-skip internal to x264, which is why B-frames generally encode much faster than P-frames, but it cannot be disabled on the commandline.
--no-dct-decimate(x264)
UNKNOWN (FFmpeg)
By default, x264 will decimate (remove all coefficients from) P-blocks that are extremely close to empty of coefficents. This can improve overall efficiency with little visual cost, but may work against an attempt to retain grain or similar. DCT decimation should be left on unless there's a good reason to disable it.
--nr(x264)
UNKNOWN (FFmpeg)
a fast, built-in noise reduction routine. Not as effective as external filters such as hqdn3d, but faster. Since x264 already naturally reduces noise through its quantization process, this parameter is not usually necessary.
--deadzone-inter(264)
--deadzone-intra (x264)
UNKNOWN (FFmpeg)
UNKNOWN (FFmpeg)
When trellis isn't activated, deadzone parameters determine how many DCT coefficients are rounded up or down. Rounding up results in higher quality and more detail retention, but costs more bits--so rounding is a balance between quality and bit cost. Lowering these settings will result in more coefficients being rounded up, and raising the settings will result in more coefficients being rounded down. Recommended: keep them at the defaults.
--cqm (264)
--cqpfile(x264)UNKNOWN (FFmpeg)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的例子,演示如何使用OpenGL ES和MediaCodec将RGB图像转换为MP4视频。 首先,我们需要使用OpenGL ES将RGB图像渲染到纹理上。以下是一个简单的渲染器类: ```cpp class Renderer { public: Renderer(); ~Renderer(); void init(); void render(const uint8_t* data, int width, int height); private: GLuint mTexture; GLuint mProgram; GLuint mVertexShader; GLuint mFragmentShader; GLint mPositionHandle; GLint mTexCoordHandle; GLint mTextureHandle; }; ``` 在Renderer的构造函数中,我们可以编译和链接顶点着色器和片段着色器: ```cpp Renderer::Renderer() { const char* vertexShaderSrc = "attribute vec4 position;\n" "attribute vec2 texCoord;\n" "varying vec2 vTexCoord;\n" "void main() {\n" " gl_Position = position;\n" " vTexCoord = texCoord;\n" "}"; const char* fragmentShaderSrc = "precision mediump float;\n" "varying vec2 vTexCoord;\n" "uniform sampler2D texture;\n" "void main() {\n" " gl_FragColor = texture2D(texture, vTexCoord);\n" "}"; mVertexShader = loadShader(GL_VERTEX_SHADER, vertexShaderSrc); mFragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentShaderSrc); mProgram = glCreateProgram(); glAttachShader(mProgram, mVertexShader); glAttachShader(mProgram, mFragmentShader); glBindAttribLocation(mProgram, ATTRIB_VERTEX, "position"); glBindAttribLocation(mProgram, ATTRIB_TEXTURE, "texCoord"); glLinkProgram(mProgram); mPositionHandle = glGetAttribLocation(mProgram, "position"); mTexCoordHandle = glGetAttribLocation(mProgram, "texCoord"); mTextureHandle = glGetUniformLocation(mProgram, "texture"); } ``` 在render函数中,我们将RGB数据上传到纹理中,并在渲染器中绘制纹理: ```cpp void Renderer::render(const uint8_t* data, int width, int height) { if (!data) { return; } if (!mTexture) { glGenTextures(1, &mTexture); glBindTexture(GL_TEXTURE_2D, mTexture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); } glBindTexture(GL_TEXTURE_2D, mTexture); glUseProgram(mProgram); glEnableVertexAttribArray(mPositionHandle); glEnableVertexAttribArray(mTexCoordHandle); glVertexAttribPointer(mPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, gVertices); glVertexAttribPointer(mTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, gTexCoords); glUniform1i(mTextureHandle, 0); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(mPositionHandle); glDisableVertexAttribArray(mTexCoordHandle); } ``` 接下来,我们使用MediaCodec将渲染的帧编码为MP4视频。以下是一个简单的编码器类: ```cpp class Encoder { public: Encoder(); ~Encoder(); void init(int width, int height); void encodeFrame(const uint8_t* data, int64_t pts); void flush(); private: AMediaCodec* mEncoder; AMediaMuxer* mMuxer; int mTrackIndex; int mFrameIndex; bool mIsStarted; }; ``` 在Encoder的构造函数中,我们可以创建MediaCodec和MediaMuxer: ```cpp Encoder::Encoder() { mEncoder = AMediaCodec_createEncoderByType("video/avc"); AMediaFormat* format = AMediaFormat_new(); AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, "video/avc"); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_BIT_RATE, 2000000); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_FRAME_RATE, 30); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, 1); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, COLOR_FormatSurface); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_WIDTH, 720); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_HEIGHT, 1280); AMediaCodec_configure(mEncoder, format, nullptr, nullptr, AMEDIACODEC_CONFIGURE_FLAG_ENCODE); AMediaFormat_delete(format); mTrackIndex = -1; mFrameIndex = 0; mIsStarted = false; } ``` 在init函数中,我们将MediaCodec的输出Surface传递给MediaMuxer,并启动MediaCodec和MediaMuxer: ```cpp void Encoder::init(int width, int height) { if (mIsStarted) { return; } AMediaCodec_start(mEncoder); AMediaMuxer_start(mMuxer); ANativeWindow* window = AMediaCodec_createInputSurface(mEncoder); AMediaMuxer_addTrack(mMuxer, AMediaCodec_getOutputFormat(mEncoder)); AMediaMuxer_start(mMuxer); mTrackIndex = 0; mIsStarted = true; } ``` 在encodeFrame函数中,我们从输出Surface中获取编码的数据,并将其写入MediaMuxer: ```cpp void Encoder::encodeFrame(const uint8_t* data, int64_t pts) { if (!mIsStarted) { return; } ANativeWindow* window = AMediaCodec_createInputSurface(mEncoder); AMediaCodec_configure(mEncoder, nullptr, nullptr, nullptr, 0); AMediaCodec_start(mEncoder); AMediaSurface* surface = AMediaSurface_fromSurfaceTexture((ASurfaceTexture*) window); AMediaCodec_setOutputSurface(mEncoder, surface); AMediaSurface_release(surface); AMediaCodecBufferInfo bufferInfo; int outputBufferIndex = AMediaCodec_dequeueOutputBuffer(mEncoder, &bufferInfo, 0); if (outputBufferIndex >= 0) { AMediaCodec_releaseOutputBuffer(mEncoder, outputBufferIndex, true); } int inputBufferIndex = AMediaCodec_dequeueInputBuffer(mEncoder, 0); if (inputBufferIndex >= 0) { AMediaCodecInputBuffer* inputBuffer = AMediaCodec_getInputBuffer(mEncoder, inputBufferIndex); size_t bufferSize = AMediaCodec_getInputBufferSize(mEncoder); uint8_t* buffer = AMediaCodecInputBuffer_getBuffer(inputBuffer); memcpy(buffer, data, bufferSize); AMediaCodec_queueInputBuffer(mEncoder, inputBufferIndex, 0, bufferSize, pts, 0); } outputBufferIndex = AMediaCodec_dequeueOutputBuffer(mEncoder, &bufferInfo, 0); if (outputBufferIndex >= 0) { AMediaCodecBufferInfo bufferInfo; AMediaCodec_getOutputBufferInfo(mEncoder, outputBufferIndex, &bufferInfo); uint8_t* outputBuffer = AMediaCodec_getOutputBuffer(mEncoder, outputBufferIndex); AMediaMuxer_writeSampleData(mMuxer, mTrackIndex, outputBuffer, &bufferInfo); AMediaCodec_releaseOutputBuffer(mEncoder, outputBufferIndex, false); mFrameIndex++; } } ``` 在flush函数中,我们停止MediaCodec和MediaMuxer: ```cpp void Encoder::flush() { if (!mIsStarted) { return; } AMediaCodec_signalEndOfInputStream(mEncoder); AMediaCodecBufferInfo bufferInfo; while (true) { int outputBufferIndex = AMediaCodec_dequeueOutputBuffer(mEncoder, &bufferInfo, 0); if (outputBufferIndex >= 0) { AMediaCodec_releaseOutputBuffer(mEncoder, outputBufferIndex, true); } else if (outputBufferIndex == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED) { AMediaFormat* format = AMediaCodec_getOutputFormat(mEncoder); AMediaMuxer_addTrack(mMuxer, format); mTrackIndex = AMediaMuxer_addTrack(mMuxer, format); AMediaMuxer_start(mMuxer); } else { break; } } AMediaCodec_stop(mEncoder); AMediaCodec_delete(mEncoder); AMediaMuxer_stop(mMuxer); AMediaMuxer_delete(mMuxer); mIsStarted = false; } ``` 在使用时,我们可以像这样使用渲染器和编码器: ```cpp Renderer renderer; Encoder encoder; renderer.init(); encoder.init(width, height); for (int i = 0; i < numFrames; i++) { renderer.render(data[i], width, height); encoder.encodeFrame(data[i], i * 1000000 / 30); } encoder.flush(); ``` 请注意,这只是一个非常简单的例子,实际上要实现一个完整的视频编码器需要更多的步骤和细节。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值