ffmpeg命令使用实例

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 sea
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值