ffmpeg 工具使用基础

FFmpeg中常用的工具主要是ffmpeg、ffprobe、ffplay,分别用于多媒体的编解码,内容分析、播放。本文主要介绍这三个工具的常用命令

1.ffmpeg 常用命令

# 查看ffmpeg命令的基础信息
ffmpeg --help
# 查看ffmpeg命令高级参数部分
ffmpeg --help long
#查看ffmpeg命令全部参数
ffmpeg --help full
#查询指令具体信息
ffmpeg -h muxer=flv
ffmpeg -h encoder=h264
ffmpeg -h filter=colorkey

通过ffmpeg --help 可以看到ffmpeg常见的命令大概分为6个部分,具体如下:

  • ffmpeg信息查询部分
  • 公共操作参数部分
  • 文件主要操作参数
  • 视频操作参数
  • 音频操作参数
  • 字幕操作参数
参数介绍

ffmpeg信息查询参数

参数 释义
-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 # 构建选项,支持哪些功能模块, 比如libfdk-aac libx264 libvpx
-formats show available formats # 文件格式(协议标准) ,比如rtmp,hls,rtp
-muxers show available muxers # 封装格式 比如flv,mp3 mp4
-demuxers show available demuxers # 解封装格式 比如mp3 h264
-devices show available devices # 封装/解封装的设备 ,比如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 # 字节流过滤 比如aac_adtstoasc
-protocols show available protocols # 协议 比如rtmp,hls
-filters show available filters # 过滤器, 比如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 # 采集设备,比如摄像头
-sinks device list sinks of the output device # 水印
-hwaccels show available HW acceleration methods # HW加速

公共参数

参数 释义
-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 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)

主要参数

参数 释义
-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

视频参数

参数 释义
-vframes number set the number of video frames to output # 输出视频帧数, 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 # 视频过滤器
-ab bitrate audio bitrate (please use -b:a) # 音频码率
-b bitrate video bitrate (please use -b:v) # 视频码率
-dn disable data

音频参数

参数 释义
-aframes number set the number of audio frames to output # 设置要输出的音频帧数
-aq quality set audio quality (codec-specific) # 指定音频编码质量 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) # 设置起始声音
-af filter_graph set audio filters # 指定过滤器
-b:a bitrate audio bitrate (please use -b:a) # 音频码率 比如192kbps

字幕参数

参数 释义
-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 封装转换

ffmpeg转封装功能包含在AVFormat模块中,通过libavformat库进行Mux和Demux操作;多媒体文件的格式有很多种,这些格式的很多参数在Mux和Demux的操作参数中是公用的

参数 类型 释义
-avioflags 标记 format的缓冲设置,默认为0,就是有缓冲
direct 无缓冲状态
-probesize 整数 在进行媒体数据处理前获得文件内容的大小,可用在预读取文件头时提高速度,也可以设置设置足够大的值来读取到足够多的音视频数据信息
-formatprobesize 整数 文件格式的字节数 (0~ 2.14748e+09) (default 1048576)
-fflags 标记
flush_packets 立即将packets数据刷新写入文件中
ignidx 忽略index
genpts 输出时按照正常规则产生pts
nofillin 不填写可以精确计算缺失的值
igndts 忽略dts
discardcorrupt 丢失损坏的帧
sortdts 尝试以dts的顺序为准输出
fastseek 快速seek(定位)操作,但不够精确
nobuffer 直接读取或写出,不存入buffer,用于在直播采集时降低延迟
bitexact 不写入随机或不稳定的数据
-seek2any BOOL 支持时,允许在解复用器级别查找非关键帧 (default false)
-analyzeduration 整数 指定解析媒体所需要花销的时间,这里设置值越高,解析越准确,如果在直播中为了降低延迟,这个值可以设置得更低些(0 ~ I64_MAX) (default 0)
-output_ts_offset 整数 设置输出文件的起始时间
-codec_whitelist 列表 设置可以解析的codec的白名单
-format_whitelist 列表 设置可以解析的format的白名单

你可能感兴趣的:(ffmpeg 工具使用基础)