FFmpeg中常用的工具主要是ffmpeg、ffprobe、ffplay,分別用于多媒體的編解碼,內(nèi)容分析、播放。本文主要介紹這三個(gè)工具的常用命令
1.ffmpeg 常用命令
# 查看ffmpeg命令的基礎(chǔ)信息
ffmpeg --help
# 查看ffmpeg命令高級(jí)參數(shù)部分
ffmpeg --help long
#查看ffmpeg命令全部參數(shù)
ffmpeg --help full
#查詢指令具體信息
ffmpeg -h muxer=flv
ffmpeg -h encoder=h264
ffmpeg -h filter=colorkey
通過(guò)ffmpeg --help 可以看到ffmpeg常見(jiàn)的命令大概分為6個(gè)部分,具體如下:
- ffmpeg信息查詢部分
- 公共操作參數(shù)部分
- 文件主要操作參數(shù)
- 視頻操作參數(shù)
- 音頻操作參數(shù)
- 字幕操作參數(shù)
參數(shù)介紹
ffmpeg信息查詢參數(shù)
| 參數(shù) | 釋義 |
|---|---|
| -L | show license |
| -h topic | show help |
| -? topic | show help |
| -help topic | show help |
| --help topic | show help |
| -version | show version |
| -buildconf | show build configuration # 構(gòu)建選項(xiàng),支持哪些功能模塊, 比如libfdk-aac libx264 libvpx |
| -formats | show available formats # 文件格式(協(xié)議標(biāo)準(zhǔn)) ,比如rtmp,hls,rtp |
| -muxers | show available muxers # 封裝格式 比如flv,mp3 mp4 |
| -demuxers | show available demuxers # 解封裝格式 比如mp3 h264 |
| -devices | show available devices # 封裝/解封裝的設(shè)備 ,比如sdl sdl2 xv |
| -codecs | show available codecs # 編解碼器 比如aac,h264 |
| -decoders | show available decoders # 解碼器 比如aac,h264 |
| -encoders | show available encoders # 編碼器 比如aac, libx264 |
| -bsfs | show available bit stream filters # 字節(jié)流過(guò)濾 比如aac_adtstoasc |
| -protocols | show available protocols # 協(xié)議 比如rtmp,hls |
| -filters | show available filters # 過(guò)濾器, 比如vflip |
| -pix_fmts | show available pixel formats # 像素格式,比如yuv420p,rgb24 |
| -layouts | show standard channel layouts # 聲道格式, 比如stereo(立體聲) |
| -sample_fmts | show available audio sample formats # 音頻采樣格式, 比如s16 s16p, fltp |
| -colors | show available color names # 顏色支持,比如Red, Green, Blue |
| -sources device | list sources of the input device # 采集設(shè)備,比如攝像頭 |
| -sinks device | list sinks of the output device # 水印 |
| -hwaccels | show available HW acceleration methods # HW加速 |
公共參數(shù)
| 參數(shù) | 釋義 |
|---|---|
| -loglevel loglevel | set logging level |
| -v loglevel | set logging level |
| -report | generate a report |
| -max_alloc bytes | set maximum size of a single allocated block |
| -y | overwrite output files # 覆蓋文件 |
| -n | never overwrite output files |
| -ignore_unknown | Ignore unknown stream types |
| -filter_threads | number of non-complex filter threads |
| -filter_complex_threads | number of threads for -filter_complex |
| -stats | print progress report during encoding # 過(guò)程信息 |
| -max_error_rate maximum error rate | ratio of errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success. |
| -bits_per_raw_sample number | set the number of bits per raw sample |
| -vol volume | change audio volume (256=normal) |
主要參數(shù)
| 參數(shù) | 釋義 |
|---|---|
| -f fmt | force format # 強(qiáng)轉(zhuǎn)碼 |
| -c codec | codec name # 指定編碼格式 |
| -codec codec | codec name |
| -pre preset | preset name |
| -map_metadata outfile[,metadata]:infile[,metadata] | set metadata information of outfile from infile |
| -t duration | record or transcode "duration" seconds of audio/video # 處理時(shí)長(zhǎng) |
| -to time_stop | record or transcode stop time |
| -fs limit_size | set the limit file size in bytes |
| -ss time_off | set the start time offset # 開(kāi)始事件 |
| -sseof time_off | set the start time offset relative to EOF |
| -seek_timestamp | enable/disable seeking by timestamp with -ss |
| -timestamp time | set the recording timestamp ('now' to set the current time) |
| -metadata string=string | add metadata |
| -program title=string:st=number... | add program with specified streams |
| -target type | specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-") |
| -apad | audio pad |
| -frames number | set the number of frames to output # 指定幀數(shù)顯示 |
| -filter filter_graph | set stream filtergraph # 過(guò)濾器 |
| -filter_script filename | read stream filtergraph description from a file |
| -reinit_filter | reinit filtergraph on input parameter changes |
| -discard | discard |
| -disposition | disposition |
視頻參數(shù)
| 參數(shù) | 釋義 |
|---|---|
| -vframes number | set the number of video frames to output # 輸出視頻幀數(shù), 60/25 |
| -r rate | set frame rate (Hz value, fraction or abbreviation) # 視頻碼率 |
| -s size | set frame size (WxH or abbreviation) # 畫面大小,widthxheight |
| -aspect aspect | set aspect ratio (4:3, 16:9 or 1.3333, 1.7777) # 縱橫比 |
| -bits_per_raw_sample number | set the number of bits per raw sample |
| -vn | disable video # 禁用視頻 |
| -vcodec codec | force video codec ('copy' to copy stream) # 指定編解碼器 |
| -timecode hh:mm:ss[:;.]ff | set initial TimeCode value. |
| -pass n | select the pass number (1 to 3) |
| -vf filter_graph | set video filters # 視頻過(guò)濾器 |
| -ab bitrate | audio bitrate (please use -b:a) # 音頻碼率 |
| -b bitrate | video bitrate (please use -b:v) # 視頻碼率 |
| -dn | disable data |
音頻參數(shù)
| 參數(shù) | 釋義 |
|---|---|
| -aframes number | set the number of audio frames to output # 設(shè)置要輸出的音頻幀數(shù) |
| -aq quality | set audio quality (codec-specific) # 指定音頻編碼質(zhì)量 fltp |
| -ar rate | set audio sampling rate (in Hz) # 采樣率,如44100hz |
| -ac channels | set number of audio channels # 采樣通道,比如雙通道 |
| -an | disable audio # 禁用聲音 |
| -acodec codec | force audio codec ('copy' to copy stream) # 指定編解碼器 |
| -vol volume | change audio volume (256=normal) # 設(shè)置起始聲音 |
| -af filter_graph | set audio filters # 指定過(guò)濾器 |
| -b:a bitrate | audio bitrate (please use -b:a) # 音頻碼率 比如192kbps |
字幕參數(shù)
| 參數(shù) | 釋義 |
|---|---|
| -s size | set frame size (WxH or abbreviation) |
| -sn | disable subtitle |
| -scodec codec | force subtitle codec ('copy' to copy stream) |
| -stag fourcc/tag | force subtitle tag/fourcc |
| -fix_sub_duration | fix subtitles duration |
| -canvas_size size | set canvas size (WxH or abbreviation) |
| -spre preset | set the subtitle options to the indicated preset |
1.1 ffmpeg 封裝轉(zhuǎn)換
ffmpeg轉(zhuǎn)封裝功能包含在AVFormat模塊中,通過(guò)libavformat庫(kù)進(jìn)行Mux和Demux操作;多媒體文件的格式有很多種,這些格式的很多參數(shù)在Mux和Demux的操作參數(shù)中是公用的
| 參數(shù) | 類型 | 釋義 |
|---|---|---|
| -avioflags | 標(biāo)記 | format的緩沖設(shè)置,默認(rèn)為0,就是有緩沖 |
| direct | 無(wú)緩沖狀態(tài) | |
| -probesize | 整數(shù) | 在進(jìn)行媒體數(shù)據(jù)處理前獲得文件內(nèi)容的大小,可用在預(yù)讀取文件頭時(shí)提高速度,也可以設(shè)置設(shè)置足夠大的值來(lái)讀取到足夠多的音視頻數(shù)據(jù)信息 |
| -formatprobesize | 整數(shù) | 文件格式的字節(jié)數(shù) (0~ 2.14748e+09) (default 1048576) |
| -fflags | 標(biāo)記 | |
| flush_packets | 立即將packets數(shù)據(jù)刷新寫入文件中 | |
| ignidx | 忽略index | |
| genpts | 輸出時(shí)按照正常規(guī)則產(chǎn)生pts | |
| nofillin | 不填寫可以精確計(jì)算缺失的值 | |
| igndts | 忽略dts | |
| discardcorrupt | 丟失損壞的幀 | |
| sortdts | 嘗試以dts的順序?yàn)闇?zhǔn)輸出 | |
| fastseek | 快速seek(定位)操作,但不夠精確 | |
| nobuffer | 直接讀取或?qū)懗?,不存入buffer,用于在直播采集時(shí)降低延遲 | |
| bitexact | 不寫入隨機(jī)或不穩(wěn)定的數(shù)據(jù) | |
| -seek2any | BOOL | 支持時(shí),允許在解復(fù)用器級(jí)別查找非關(guān)鍵幀 (default false) |
| -analyzeduration | 整數(shù) | 指定解析媒體所需要花銷的時(shí)間,這里設(shè)置值越高,解析越準(zhǔn)確,如果在直播中為了降低延遲,這個(gè)值可以設(shè)置得更低些(0 ~ I64_MAX) (default 0) |
| -output_ts_offset | 整數(shù) | 設(shè)置輸出文件的起始時(shí)間 |
| -codec_whitelist | 列表 | 設(shè)置可以解析的codec的白名單 |
| -format_whitelist | 列表 | 設(shè)置可以解析的format的白名單 |