FFmpeg 常用命令
Help
ffmpeg version 5.1.1 Copyright (c) 2000-2022 the FFmpeg developers
...
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Getting help:
-h -- print basic options
-h long -- print more options
-h full -- print all options (including all format and codec specific options, very long)
-h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol
See man ffmpeg for detailed description of the options.
Print help / information / capabilities:
-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
-demuxers show available demuxers
-devices show available devices
-codecs show available codecs
-decoders show available decoders
-encoders show available encoders
-bsfs show available bit stream filters
-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
-dispositions show available stream dispositions
-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
Global options (affect whole program instead of just one file):
-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
-max_error_rate maximum error rate ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.
-vol volume change audio volume (256=normal)
Per-file main options:
-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
-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
-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
-filter filter_graph set stream filtergraph
-filter_script filename read stream filtergraph description from a file
-reinit_filter reinit filtergraph on input parameter changes
-discard discard
-disposition disposition
Video options:
-vframes number set the number of video frames to output
-r rate set frame rate (Hz value, fraction or abbreviation)
-fpsmax rate set max frame rate (Hz value, fraction or abbreviation)
-s size set frame size (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-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
-ab bitrate audio bitrate (please use -b:a)
-b bitrate video bitrate (please use -b:v)
-dn disable data
Audio options:
-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)
-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)
-af filter_graph set audio filters
Subtitle options:
-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
Example
ffmpeg -version # show version
ffmpeg -buildconf # show build configuration
ffmpeg -formats # show available formats
ffmpeg -muxers # show available muxers
ffmpeg -demuxers # show available demuxers
ffmpeg -devices # show available devices
ffmpeg -codecs # show available codecs
ffmpeg -decoders # show available decoders
ffmpeg -encoders # show available encoders
ffmpeg -bsfs # show available bit stream filters
ffmpeg -protocols # show available protocols
ffmpeg -filters # show available filters
ffmpeg -pix_fmts # show available pixel formats
ffmpeg -layouts # show standard channel layouts
ffmpeg -sample_fmts # show available audio sample formats
ffmpeg -dispositions # show available stream dispositions
ffmpeg -colors # show available color names
ffmpeg -sources device # list sources of the input device
ffmpeg -sinks device # list sinks of the output device
ffmpeg -hwaccels # show available HW acceleration methods
# 格式转换 (如果不设置编码格式, 会根据后缀自动选择编码)
ffmpeg -i input.ape output.mp3
# 设置比特率
ffmpeg -i input.ape -ab 256k output.m4a
ffmpeg -i input.ape -ab 320k output.mp3
# 截取长度
# 从 00:02:00 开始, 到 00:03:00 结束, ss 开始时间, to 结束时间
ffmpeg -ss 00:02:00 -to 00:03:00 -i input.mp3 -c copy output.mp3
# 从 00:02:00 开始, 到 00:03:00 结束, ss 开始时间, t 时间长度
ffmpeg -ss 00:02:00 -t 00:01:00 -i input.mp3 -c copy output.mp3
# 音频淡入淡出
# 从 0s 开始淡入 3s
ffmpeg -i input.mp3 -af 'afade=t=in:ss=0:d=3' output.mp3
# 从 57s 开始淡出 3s
ffmpeg -i input.mp3 -af "afade=t=out:st=57:d=3" output.mp3
# 转换 WAV 到 MP3
# https://stackoverflow.com/questions/3255674/convert-audio-files-to-mp3-using-ffmpeg
ffmpeg -ss 00:28:42 -to 00:31:51 -i input.wav -vn -ar 44100 -ac 2 -b:a 320k output.mp3
# 连接多个音频文件 (https://superuser.com/a/587553)
ffmpeg -i input1.wav -i input2.wav -i input3.wav -i input4.wav \
-filter_complex '[0:0][1:0][2:0][3:0]concat=n=4:v=0:a=1[out]' \
-map '[out]' output.wav
# 剪切音频
ffmpeg -ss 00:01:00 -to 00:02:33 -i input.mp4 -c copy output.mp4
# 保留日期(macOS)
date="$(stat -f '%Sm' -t '%m/%d/%Y %H:%M:%S' input.mp4)"
SetFile -d date -m date output.mp4
# 将分辨率转换为 480x270 (16:9)
ffmpeg -i input.mp4 -vf scale=480:270 output.mp4
# 将分辨率转换为1080P, 并使用x265格式
ffmpeg -i input.mp4 -vf scale=1920:1080 -c:v libx265 -vtag hvc1 -an output.mp4
# 查看可用的编码格式
ffmpeg -encoders
# 将视频转化为 H264 编码格式
ffmpeg -i 07302019142737.mov -vcodec libx264 -an 07302019142737_H264.mov
# 将视频转化为 ProRes 编码格式
ffmpeg -i 07302019142737.mov -vcodec prores -an 07302019142737_ProRes.mov