FFmpeg 是 Fast Forward Moving Picture Experts Group (快進運動圖片專傢組) 的縮寫,是一種超快音頻 視頻編碼器。
FFmpeg 是領先的開源跨平颱多媒體框架,能解碼 編碼 轉碼 Mux Demux 流化 過濾和播放由人類 機器創建的幾乎所有內容。
FFmpeg 由 AVCodec 音視頻編解碼器、AVDevice 音視頻設備、AVFilter 音視頻濾鏡、AVFormat 音視頻格式、AVUtil 音視頻實用工具、swscale 視頻圖像轉換、swresample 音頻轉換 7 個部分組成。
另請參閱: FFmpeg 4.2.2 中文文檔編製 FFmpeg for Linux
Python ctypes 時,可能齣現此提示。
基本用法 詳細用法 源碼編譯 媒體格式 視頻轉碼 視頻濾鏡 音頻轉碼 硬編解碼 媒體錄製
查看所有可用 DirectShow 音視頻設備
X:\digital manage\bin>ffmpeg -list_devices true -f dshow -i dummy ffmpeg version N-94335-g9869e21776 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 9.1.1 (GCC) 20190716 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56. 30.100 / 56. 30.100 libavcodec 58. 53.101 / 58. 53.101 libavformat 58. 28.102 / 58. 28.102 libavdevice 58. 7.100 / 58. 7.100 libavfilter 7. 56.101 / 7. 56.101 libswscale 5. 4.101 / 5. 4.101 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 [dshow @ 00000000003e00c0] DirectShow video devices (some may be both video and audio devices) [dshow @ 00000000003e00c0] "HD WebCam" [dshow @ 00000000003e00c0] Alternative name "@device_pnp_\\?\usb#vid_1bcf&pid_2c18&mi_00#7&22116bc6&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global" [dshow @ 00000000003e00c0] "screen-capture-recorder" [dshow @ 00000000003e00c0] Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{4EA69364-2C8A-4AE6-A561-56E4B5044439}" [dshow @ 00000000003e00c0] DirectShow audio devices [dshow @ 00000000003e00c0] "麥剋風 (Realtek High Definition Au" [dshow @ 00000000003e00c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\麥剋風 (Realtek High Definition Au" [dshow @ 00000000003e00c0] "virtual-audio-capturer" [dshow @ 00000000003e00c0] Alternative name "@device_sw_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\{8E146464-DB61-4309-AFA1-3578E927E935}" dummy: Immediate exit requested X:\digital manage\bin>
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
參數 | EN 解釋 | 中文翻譯 | 備注 |
---|---|---|---|
-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 | 展示構建配置 | |
-formats | show available formats | 展示可用的格式 | |
-muxers | show available muxers | 展示可用的 Muxer | |
-demuxers | show available demuxers | 展示可用的 Demuxer | |
-devices | show available devices | 展示可用的設備 | |
-codecs | show available codecs | 展示可用的編解碼器 | |
-decoders | show available decoders | 展示可用的解碼器 | |
-encoders | show available encoders | 展示可用的編碼器 | |
-bsfs | show available bit stream filters | 展示可用的 BSF (比特流過濾器) | |
-protocols | show available protocols | 展示可用的協議 | |
-filters | show available filters | 展示可用的過濾器 | |
-pix_fmts | show available pixel formats | 展示可用的像素格式 | |
-layouts | show standard channel layouts | 展示標準通道布局 | |
-sample_fmts | show available audio sample formats | 展示可用的音頻采樣格式 | |
-colors | show available color names | 展示可用的顔色名稱 | |
-sources device | list sources of the input device | 列齣輸入設備的來源 | |
-sinks device | list sinks of the output device | 列齣輸齣設備的接收器 | |
-hwaccels | show available HW acceleration methods | 顯示可用的硬件加速方法 |
參數 | EN 解釋 | 中文翻譯 | 備注 |
---|---|---|---|
-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 | -filter_complex 的綫程數 | |
-stats | print progress report during encoding | 在編碼期間打印進度報告 | |
-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. |
錯誤率 (0.0:無錯誤,1.0:100% 錯誤) 在此之上,ffmpeg 返迴錯誤而不是成功。 |
|
-bits_per_raw_sample number | set the number of bits per raw sample | 設置每原生采樣位數 | |
-vol volume | change audio volume (256=normal) | 更改音量 (256=正常) |
參數 | EN 解釋 | 中文翻譯 | 備注 |
---|---|---|---|
-f fmt | force format | 強製格式 | |
-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 | 設置來自 infile 的 outfile 元數據信息 | |
-t duration | record or transcode "duration" seconds of audio/video | 錄製 (或轉碼) 音頻/視頻的持續時間秒數 | |
-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 | 設置開始時間偏移 | |
-sseof time_off | set the start time offset relative to EOF | 設置相對於 EOF 的開始時間偏移 | |
-seek_timestamp | enable/disable seeking by timestamp with -ss | 采用 -ss 按時間戳啓用/禁用尋址 | |
-timestamp time | set the recording timestamp ('now' to set the current time) | 設置錄製時間戳 (now 設置當前時間) | |
-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-") |
指定目標文件類型 (帶有可選前綴 pal- ntsc- 或 film- 的 vcd svcd dvd dv 或 dv50) |
|
-apad | audio pad | 音頻墊 | |
-frames number | set the number of frames to output | 設置要輸齣的幀數 | |
-filter filter_graph | set stream filtergraph | 設置流 filtergraph | |
-filter_script filename | read stream filtergraph description from a file | 從文件讀取流 filtergraph 描述 | |
-reinit_filter | reinit filtergraph on input parameter changes | 輸入參數改變時重新初始化 filtergraph | |
-discard | discard | 廢除 | |
-disposition | disposition | 處置 |
參數 | EN 解釋 | 中文翻譯 | 備注 |
---|---|---|---|
-vframes number | set the number of video frames to output | 設置要輸齣的視頻幀數 | |
-r rate | set frame rate (Hz value, fraction or abbreviation) | 設置幀速率 (Hz 值,分數或縮寫) | |
-s size | set frame size (WxH or abbreviation) | 設置幀尺寸 (WxH 或縮寫) | |
-aspect aspect | set aspect ratio (4:3, 16:9 or 1.3333, 1.7777) | 設置寬高比 (4:3 16:9 或 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) | 強製視頻編解碼器 (copy 到拷貝流) | |
-timecode hh:mm:ss[:;.]ff | set initial TimeCode value. | 設置初始 TimeCode 值。 | |
-pass n | select the pass number (1 to 3) | 選擇通過數 (1 至 3) | |
-vf filter_graph | set video filters | 設置視頻過濾器 | |
-ab bitrate | audio bitrate (please use -b:a) | 音頻比特率 (請使用 -b:a) | |
-b bitrate | video bitrate (please use -b:v) | 視頻比特率 (請使用 -b:v) | |
-dn | disable data | 禁用數據 |
參數 | EN 解釋 | 中文翻譯 | 備注 |
---|---|---|---|
-aframes number | set the number of audio frames to output | 設置要輸齣的音頻幀數 | |
-aq quality | set audio quality (codec-specific) | 設置音頻質量 (特定於編解碼器) | |
-ar rate | set audio sampling rate (in Hz) | 設置音頻采樣率 (以 Hz 為單位) | |
-ac channels | set number of audio channels | 設置音頻通道數 | |
-an | disable audio | 禁用音頻 | |
-acodec codec | force audio codec ('copy' to copy stream) | 強製音頻編解碼器 (copy 到拷貝流) | |
-vol volume | change audio volume (256=normal) | 改變音頻音量 (256=正常) | |
-af filter_graph | set audio filters | 設置音頻過濾器 |
參數 | EN 解釋 | 中文翻譯 | 備注 |
---|---|---|---|
-s size | set frame size (WxH or abbreviation) | 設置幀尺寸 (WxH 或縮寫) | |
-sn | disable subtitle | 禁用字幕 | |
-scodec codec | force subtitle codec ('copy' to copy stream) | 強製字幕編解碼器 (copy 到拷貝流) | |
-stag fourcc/tag | force subtitle tag/fourcc | 強製字幕標簽/fourcc | |
-fix_sub_duration | fix subtitles duration | 修正字幕的持續時間 | |
-canvas_size size | set canvas size (WxH or abbreviation) | 設置畫布尺寸 (WxH 或縮寫) | |
-spre preset | set the subtitle options to the indicated preset | 把字幕選項設為所指示的預置 |
功能 | 命令 | 文字解釋 |
---|---|---|
格式 | ffmpeg -formats | 展示支持的所有音 視頻文件格式 |
ffmpeg -codecs | 展示支持的所有編解碼器 | |
ffmpeg -encoders | 展示支持的所有編解器 | |
ffmpeg -decoders | 展示支持的所有解碼器 | |
信息 | ffmpeg -filters | 展示支持的所有濾鏡 |
ffmpeg -h muxer=flv | 展示 FLV 復用器信息 | |
ffmpeg -h encoder=h264 | 展示 H.264 編碼器信息 | |
ffmpeg -h encoder=libx264 | ||
ffmpeg -h filter=colorkey | 展示 colorkey 濾鏡信息 | |
ffmpeg -i d:/test.mkv | 獲取視頻信息 | |
設備 | ffmpeg -list_devices true -f dshow -i dummy | 展示 dshow 音視頻設備信息 |
ffmpeg -list_devices true -f gdigrab -i dummy | 展示 gdigrab 視頻設備相關信息 | |
ffmpeg -f dshow -list_options true -i audio="virtual-audio-capturer" | 展示 DirectShow 的 virtual-audio-capturer 音頻設備信息 | |
ffmpeg -f dshow -list_options true -i video="screen-capture-recorder" | 展示 DirectShow 的 screen-capture-recorder 視頻設備信息 | |
幫助 | ffmpeg --help | 展示幫助信息 |
ffmpeg -h | 展示幫助信息 | |
ffmpeg -h long | 展示更多選項 | |
ffmpeg -h full | 展示所有選項 (包括所有格式和編解碼器特定選項,很長) | |
ffmpeg -h type=name |
展示 name (如 decoder/encoder/demuxer/muxer/filter/bsf) 的所有選項 |
|
ffmpeg -h demuxer=mp4 |
展示 mp4 demuxer 的所有選項 |
|
版本 | ffmpeg -version | 展示版本信息 |
功能 | 命令 | 文字解釋 |
---|---|---|
AVI | ffmpeg -i input.mpg output.avi | 把 input.mpg 音視頻轉換成 output.avi 文檔 |
DV | ffmpeg -i input.avi -target pal-dv output.dv | 把 input.avi 音視頻轉換成 output.dv 文檔 |
FLV | ffmpeg -i input_ac3.mp4 -c copy -f flv output.flv | 將 input_ac3.mp4 轉換成 output.flv 文件 |
GIF | ffmpeg -i input.avi output.gif | 把 input.avi 音視頻轉換成未壓縮 output.gif 動畫 |
MP4 | ffmpeg -i input.flv -c copy -f mp4 -movflags faststart output.mp4 | 將 input.flv 轉換成 moov 在前的 output.mp4 文件 |
TS | ffmpeg -re -i input.mp4 -c copy -f mpegts output.ts | 將 input.mp4 轉換成 output.ts 文檔 |
功能 | 命令 | 文字解釋 | 備注 |
---|---|---|---|
MP4 |
編碼以適閤在 PSP 或 iPod/iPhone 上播放 ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4 ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4 |
||
ffmpeg -i input.mp4 -vcodec libx264 -preset medium -b:v 2000k output.mp4 ffmpeg -i input.mp4 -vcodec libx264 -preset ultrafast -b:v 2000k output.mp4 |
把 input.mp4 按 medium 編碼方式轉換成 output.mp4 文檔 把 input.mp4 按 ultrafast 編碼方式轉換成 output.mp4 文檔 |
||
ffmpeg -i input.mp4 -c:v libx264 -g 50 -t 60 output.mp4 ffmpeg -i input.mp4 -c:v libx264 -g 50 -sc_threshold 0 -t 60 -y output.mp4 ffmpeg -i input.mp4 -c:v libx264 -x264opts "bframes=0" -g 50 -sc_threshold 0 output.mp4 ffmpeg -i input.mp4 -c:v libx264 -x264opts "bframes=3:b-adapt=0" -g 50 -sc_threshold 0 output.mp4 |
把 input.mp4 按每 50 幀 GOP 方式轉換成 output.mp4 文檔 把 input.mp4 嚴格按每 50 幀 GOP 方式轉換成 output.mp4 文檔 把 input.mp4 嚴格按每 50 幀 GOP 無 B 幀方式轉換成 output.mp4 文檔 把 input.mp4 嚴格按每 50 幀 GOP 每 2 個 P 幀存放 3 個 B 幀方式轉換成 output.mp4 文檔 |
IDR 幀頻率 50 GOP B 幀多清晰度高,但編解碼更復雜 -sc_threshold 0 場景切換時不強行插入關鍵幀 |
|
ffmpeg -i input.mp4 -c:v copy -c:a libfdk_aac -b:a 384k output.mp4 | 把 input.mp4 的音頻按第三方 libfdk_aac 編碼 384KBit/s 碼率轉換成 output.mp4 文檔 | ||
ffmpeg -re -i input.mp4 -vcodec libx264 -an output.mp4 | 把 input.mp4 按 libx264 編碼轉換成 output.mp4 文檔 | ||
FLV | ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv | 把 .avi 視頻轉換成 .flv | |
ffmpeg -i input_ac3.mp4 -vcodec copy -acodec aac -f flv output.flv | 將 input_ac3.mp4 音頻先轉換成 AAC 格式再輸齣 output.flv 文件 | ||
ffmpeg -i input.mp4 -c copy -f flv -flvflags add_keyframe_index output.flv | 為 input.mp4 添加關鍵幀索引轉換成 output.flv 文件 | ||
M3U8 | ffmpeg -re -i input.mp4 -c copy -f hls -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻轉換成 output.m3u8 文檔 | |
ffmpeg -re -i input.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -hls_time 10 output.m3u8 | 把 input.mp4 視頻按每隔 10 秒切片轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -hls_time 10 -hls_flags split_by_time output.m3u8 | 把 input.mp4 視頻嚴格按每隔 10 秒切片轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -use_localtime 1 -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻按以本地時間作切片名方式轉換成 output.m3u8 文檔 | ||
ffmpeg -i input.mp4 -c copy -f hls -hls_time 3 -hls_list_size 0 -method PUT -t 30 http://127.0.0.1/test/output.m3u8 | 把 input.mp4 視頻按每隔 3 秒推送到服務器 http://127.0.0.1/test/output.m3u8 |
Nginx 配置
location / { client_max_body_size 10M; dav_access group:rw all:rw; dav_methods PUT DELETE MKCOL COPY MOVE; root html/; } |
|
ffmpeg -re -i input.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -hls_list_size 3 output.m3u8 | 把 input.mp4 視頻分 3 個 TS 切片轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -start_number 300 output.m3u8 | 把 input.mp4 視頻從第 300 序列起轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -hls_wrap 3 output.m3u8 | 把 input.mp4 視頻按每 3 個 TS 切片分段轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -hls_base_url http://192.168.0.1/live/ -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻按 http://192.168.0.1/live/ 路徑轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -hls_flags delete_segments -hls_list_size 4 -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻按刪除早期切片方式轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -hls_flags round_durations -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻按圓整切片持續時間方式轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -hls_flags discont_start -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻按在切片前插入 EXT-X-DISCONTINUITY 標簽方式轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -hls_flags omit_endlist -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻按不在結尾添加 EXT-X-ENDLIST 標簽方式轉換成 output.m3u8 文檔 | ||
ffmpeg -re -i input.mp4 -c copy -f hls -hls_segment_filename test_output-%d.ts -bsf:v h264_mp4toannexb output.m3u8 | 把 input.mp4 視頻按 test_output-%d.ts 分段文件名模塊轉換成 output.m3u8 文檔 | ||
DV | ffmpeg -i input.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 output.dv | 把 input.avi 音視頻轉換成 output.dv 文檔 | |
TS | ffmpeg -re -i input.mp4 -vcodec libx264 -acodec copy -f mpegts output.ts | 將 input.mp4 編碼轉換成 output.ts 文檔 | |
ffmpeg -i input.mp4 -vcodec libx264 -profile:v high -level 3.1 -s 352x288 -an -y -t 10 output.ts ffprobe -v quiet -show_frames -select_streams v output.ts | grep "pict_type=B" | WC -l |
將 input.mp4 按 high profile 編碼方式轉換成 output.ts 文檔 查看 output.ts 文檔是否包含 B 幀 (包含) |
||
ffmpeg -i input.mp4 -vcodec libx264 -profile:v baseline -level 3.1 -s 352x288 -an -y -t 10 output.ts ffprobe -v quiet -show_frames -select_streams v output.ts | grep "pict_type=B" | WC -l |
將 input.mp4 按 baseline profile 編碼方式轉換成 output.ts 文檔 查看 output.ts 文檔是否包含 B 幀 (不包含) |
||
ffmpeg -i input.mp4 -c:v libx264 -x264opts "bframes=10:b-adapt=0" -b:v 1000k -maxrate 1000k -minrate 1000k -bufsize 50k -nal-hrd cbr -g 50 -sc_threshold 0 output.ts | 把 input.mp4 嚴格按每 50 幀 GOP 每 2 個 P 幀存放 10 個 B 幀,1000KBit/s 恒定碼率 50 KB 緩衝大小方式轉換成 output.mp4 文檔 | H.264 編碼 HRD 信號形式為 CBR 恒定碼率 |
功能 | 命令 | 文字解釋 | 備注 |
---|---|---|---|
水印文字 | ffmpeg -i input.mp4 -vf "drawtext=fontsize=100:fontfile=FreeSerif.ttf:text='Hello World':x=20:y=20" output.mp4 | 在 input.mp4 左上角添加 100 像素黑色 Hello World 文字水印並輸齣 output.mp4 文檔 | 使用 drawtext 濾鏡 |
ffmpeg -i input.mp4 -vf "drawtext=fontsize=100:fontfile=FreeSerif.ttf:text='Hello World':fontcolor=green:x=20:y=20" output.mp4 | 在 input.mp4 左上角添加 100 像素綠色 Hello World 文字水印並輸齣 output.mp4 文檔 | ||
ffmpeg -i input.mp4 -vf "drawtext=fontsize=100:fontfile=FreeSerif.ttf:text='Hello World':fontcolor=green:box=1:boxcolor=yellow:x=20:y=20" output.mp4 | 在 input.mp4 左上角添加 100 像素綠色 Hello World 文字黃色邊框水印並輸齣 output.mp4 文檔 | ||
ffmpeg -re -i input.mp4 -vf "drawtext=fontsize=100:fontfile=FreeSerif.ttf:text='%{localtime\:%Y\-%m\-%d %H-%N-%S}':fontcolor=green:box=1:boxcolor=yellow:x=20:y=20" output.mp4 | 在 input.mp4 左上角添加 100 像素綠色年月日 時分秒時間文字黃色邊框水印並輸齣 output.mp4 文檔 | ||
ffmpeg -re -i input.mp4 -vf "drawtext=fontsize=100:fontfile=FreeSerif.ttf:text='test':fontcolor=green:box=1:boxcolor=yellow:enable=lt(mod(t\,3)\,1):x=20:y=20" output.mp4 | 在 input.mp4 左上角添加 100 像素綠色 test 文字黃色邊框水印 (每隔 3 秒齣現一次) 並輸齣 output.mp4 文檔 | ||
ffmpeg -re -i input.mp4 -vf "drawtext=fontsize=100:fontfile=/Library/Fonts/Songti.ttc:text='文字水印測試':fontcolor=green:box=1:boxcolor=yellow:x=20:y=20" output.mp4 | 在 input.mp4 左上角添加 100 像素綠色中文文字黃色邊框水印並輸齣 output.mp4 文檔 | ||
水印圖片 | ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v]scale=176:144[logo];[0:v][logo]overlay=x=0:y=0" output.mp4 | 在 input.mp4 視頻流 [0:v] 左上角添加 176x144 像素 logo.png 圖像水印並輸齣 output.mp4 文檔 |
功能 | 命令 | 文字解釋 | 備注 |
---|---|---|---|
AAC | ffmpeg -i input.mp4 -c:a aac -b:a 160k output.aac | 把 input.mp4 按默認 aac 編碼 160KBit/s 碼率轉換成 output.aac 文檔 | |
M4A | ffmpeg -i input.wav -c:a aac -q:a 2 output.m4a | 把 input.wav 按默認 aac 編碼 qscale 2 轉換成 output.m4a 文檔 | |
ffmpeg -i input.wav -c:a libfdk_aac -b:a 128k output.m4a | 把 input.wav 按第三方 libfdk_aac 編碼 128KBit/s 碼率轉換成 output.m4a 文檔 | ||
ffmpeg -i input.wav -c:a libfdk_aac -vbr 3 output.m4a | 把 input.wav 按第三方 libfdk_aac 編碼 vbr 動態碼率 3 轉換成 output.m4a 文檔 | ||
ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he -b:a 64k output.m4a | 把 input.wav 按第三方 libfdk_aac aac_he 編碼 cbr 恒定碼率 64KBit/s 轉換成 output.m4a 文檔 | ||
ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he_v2 -b:a 32k output.m4a | 把 input.wav 按第三方 libfdk_aac aac_he_v2 編碼 cbr 恒定碼率 32KBit/s 轉換成 output.m4a 文檔 | ||
MP3 | ffmpeg -h encoder=libmp3lame | 查看 libmp3lame 編碼器參數 | |
ffmpeg -i INPUT -acodec libmp3lame output.mp3 | 把 INPUT 轉換成 output.mp3 文檔 | ||
ffmpeg -i input.mp3 -acodec libmp3lame -q:a 8 output.mp3 | 把 input.mp3 按 VBR 動態 70-105KBit/s 碼率轉換成 output.mp3 文檔 | ||
ffmpeg -i input.mp3 -acodec libmp3lame -b:a 64k output.mp3 | 把 input.mp3 按 CBR 恒定 64KBit/s 碼率轉換成 output.mp3 文檔 | ||
ffmpeg -i input.mp3 -acodec libmp3lame -b:a 64k -abr 1 output.mp3 | 把 input.mp3 按 ABR 方式 64KBit/s 碼率轉換成 output.mp3 文檔 |
功能 | 命令 | 文字解釋 | 備注 |
---|---|---|---|
Nvidia | ffmpeg -h encoder=h264_nvenc | 查看 Nvidia 顯卡 GPU H.264 硬編碼參數 | |
ffmpeg -h decoder=h264_cuvid | 查看 Nvidia 顯卡 GPU H.264 硬解碼參數 | ||
ffmpeg -hwaccel cuvid -vcodec h264_cuvid -i input.mp4 -vf scale_npp=1920:1080 -vcodec h264_nvenc -acodec copy -f mp4 -y output.mp4 | 把 input.mp4 按 cuvid 硬解碼 nvenc 硬編碼方式 1920x1080 分辨率轉換成 output.mp4 文檔 | 2MBit/s 碼率 | |
Intel | ffmpeg -hide_banner -codecs | grep h264 | 編譯 FFmpeg 時采用 --enable-libmfx 命令開啓 Intel QSV 硬編解碼 GPU 支持 | |
ffmpeg -h encoder=h264_qsv | 查看 Intel Media SDK QSV H.264 硬編碼參數 | ||
ffmpeg -h decoder=h264_qsv | 查看 Intel Media SDK QSV H.264 硬解碼參數 | ||
ffmpeg -i input.mp4 -pix_fmt nv12 -vcodec h264_qsv -an -y output.mp4 | 把 input.mp4 按 h264_qsv 硬編解碼方式 1920x1080 分辨率轉換成 output.mp4 文檔 | 2MBit/s 碼率 | |
ffmpeg -hide_banner -y -hwaccel qsv -i input.mp4 -an -c:v hevc_qsv -load_plugin hevc_hw -b:v 5M -maxrate 5M output.mp4 | 把 input.mp4 按 hevc_hw H.265 硬編解碼方式 1920x1080 分辨率轉換成 output.mp4 文檔 | 2MBit/s 碼率 | |
Raspberry Pi | ffmpeg -h encoder=h264_omx | 編譯 FFmpeg 時采用 --enable-omx-rpi 命令開啓樹莓派 OpenMAX 硬編解碼支持 | 需要樹莓派硬件 |
ffmpeg -h decoder=h264_omx | 查看樹莓派 OpenMAX 硬解碼參數 | ||
ffmpeg -i input.mp4 -vcodec h264_omx -b:v 500k -acodec copy -y output.mp4 | 把 input.mp4 按 omx 編解碼方式轉換成 output.mp4 文檔 | 500KBit/s 碼率 | |
OS X | ffmpeg -h encoder=h264_videotoolbox | 查看 OS X 平颱 H.264 硬編碼參數 | |
ffmpeg -h decoder=h264_vda | 查看 OS X 平颱 H.264 硬解碼參數 | ||
ffmpeg -vcodec h264_vda -i input.mp4 -vcodec h264_videotoolbox -b:v 2000k output.mp4 | 把 input.mp4 按 vda 解碼 videotoolbox 編碼方式轉換成 output.mp4 文檔 | 2MBit/s 碼率 |
功能 | 命令 |
---|---|
聲音 |
ffmpeg -f dshow -i audio="virtual-audio-capturer" d:/test.aac ffmpeg -f dshow -i audio="麥剋風 (Realtek High Definition Au" -acodec aac d:/test.aac |
攝像頭 |
ffmpeg -f dshow -i video="HD WebCam" d:/test.mkv ffmpeg -f dshow -i video="HD WebCam" -vcodec libx264 -video_size 1280x720 -framerate 30 d:/test.mkv |
屏幕 |
dshow 錄製完整屏幕 ffmpeg -f dshow -i video="screen-capture-recorder" d:/test.mkv ffmpeg -f dshow -i video="screen-capture-recorder" -vcodec libx264 -video_size 1280x720 -framerate 30 d:/test.mkv |
dshow 錄製完整屏幕 聲音 ffmpeg -f dshow -i video="screen-capture-recorder" -f dshow -i audio="virtual-audio-capturer" -vcodec libx264 -acodec libmp3lame -s 1280x720 -r 30 d:/test.mkv ffmpeg -f dshow -i video="screen-capture-recorder":audio="virtual-audio-capturer" -vcodec libx264 -acodec libmp3lame -video_size 1280x720 -framerate 30 -preset:v ultrafast -tune:v zerolatency d:/test.mkv |
|
gdigrab 錄製屏幕區域, dshow 錄製聲音 ffmpeg -f gdigrab -framerate 30 -offset_x 100 -offset_y 100 -video_size 1280x720 -i desktop -f dshow -i audio="virtual-audio-capturer" -vcodec libx264 -acodec libmp3lame -preset:v ultrafast -tune:v zerolatency d:/test.mkv |
另請參閱: ffmpeg 常用命令
查看 virtual-audio-capturer 音頻設備信息。
注意: screen-capture-recorder 和 virtual-audio-capturer 需安裝 Setup Screen Capturer Recorder v0.12.10.exe
X:\digital manage\bin>ffmpeg -f dshow -list_options true -i audio="virtual-audio-capturer" ffmpeg version N-94335-g9869e21776 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 9.1.1 (GCC) 20190716 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56. 30.100 / 56. 30.100 libavcodec 58. 53.101 / 58. 53.101 libavformat 58. 28.102 / 58. 28.102 libavdevice 58. 7.100 / 58. 7.100 libavfilter 7. 56.101 / 7. 56.101 libswscale 5. 4.101 / 5. 4.101 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 [dshow @ 0000000000520180] DirectShow audio only device options (from audio devices) [dshow @ 0000000000520180] Pin "Capture Virtual Audio Pin" (alternative pin name "1") [dshow @ 0000000000520180] min ch=2 bits=16 rate= 48000 max ch=2 bits=16 rate= 48000 audio=virtual-audio-capturer: Immediate exit requested X:\digital manage\bin>
查看 screen-capture-recorder 視頻設備信息。
X:\digital manage\bin>ffmpeg -f dshow -list_options true -i video="screen-capture-recorder" ffmpeg version N-94335-g9869e21776 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 9.1.1 (GCC) 20190716 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56. 30.100 / 56. 30.100 libavcodec 58. 53.101 / 58. 53.101 libavformat 58. 28.102 / 58. 28.102 libavdevice 58. 7.100 / 58. 7.100 libavfilter 7. 56.101 / 7. 56.101 libswscale 5. 4.101 / 5. 4.101 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 [dshow @ 00000000004e0180] DirectShow video device options (from video devices) [dshow @ 00000000004e0180] Pin "Capture" (alternative pin name "1") [dshow @ 00000000004e0180] pixel_format=bgr0 min s=1x1 fps=0.02 max s=1920x1080 fps=30 [dshow @ 00000000004e0180] pixel_format=bgr0 min s=1x1 fps=0.02 max s=1920x1080 fps=30 [dshow @ 00000000004e0180] pixel_format=bgr24 min s=1x1 fps=0.02 max s=1920x1080 fps=30 [dshow @ 00000000004e0180] pixel_format=rgb555le min s=1x1 fps=0.02 max s=1920x1080 fps=30 [dshow @ 00000000004e0180] pixel_format=rgb555le min s=1x1 fps=0.02 max s=1920x1080 fps=30 [dshow @ 00000000004e0180] pixel_format=rgb8 min s=1x1 fps=0.02 max s=1920x1080 fps=30 [dshow @ 00000000004e0180] pixel_format=yuv420p min s=1x1 fps=0.02 max s=1920x1080 fps=30 leaving aero onvideo=screen-capture-recorder: Immediate exit requested X:\digital manage\bin>
在 Windows 編譯采用 MinGW (而非 Visual Studio) 和 MSYS 環境,在 OS X 編譯采用 LLVM。
編譯時 ./configure --help 展幫助,./configure --list-encoders 展示編碼器,./configure --list-decoders 展示解碼器,./configure --list-muxers 展示封裝,./configure --list-demuxers 展示解封裝,./configure --list-protocols 展示解封裝。
版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。