FFmpeg 笔记(Version: 4.3)
常用命令
-
格式转换
ffmpeg -i out.ogv -vcodec h264 out.mp4 ffmpeg -i out.ogv -vcodec mpeg4 out.mp4 ffmpeg -i out.ogv -vcodec libxvid out.mp4 ffmpeg -i out.mp4 -vcodec wmv1 out.wmv ffmpeg -i out.mp4 -vcodec wmv2 out.wmv
说明:
-i <input_file_name>
输入文件名;-vcodec <video_codec>
格式编码(h264 最佳) -
视频剪切
ffmpeg -i input.wmv -ss 00:00:30.0 -c copy -t 00:00:10.0 output.wmv ffmpeg -i input.wmv -ss 30 -c copy -t 10 output.wmv ffmpeg -i input.wmv -ss 30 -c copy -to 40 output.wmv
说明: 用
-ss
和-t
从input.wmv
第30
秒开始向后截取10
秒的视频,并保存为output.wmv
-
视频合并
$ cat mylist.txt file '/path/to/file1' file '/path/to/file2' file '/path/to/file3' $ ffmpeg -f concat -i mylist.txt -c copy output
说明: 从
mylist.txt
获取配置信息,通过concat
简单拼接视频。需要注意输入文件的多样性,需要转成中间格式再合成。
参数说明
$ ffmpeg -h
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
使用方法: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
帮助命令:
-h 显示基本选项
-h long 显示更多选项
-h full 显示所有选项(包括所有格式、编解码器的具体选项,内容非常多)
-h type=name 显示指定的 decoder/encoder/demuxer/muxer/filter/bsf/protocol 选项
打印帮助/信息/功能:
-L 显示许可
-h topic 显示指定主题的帮助信息
-? topic 显示指定主题的帮助信息
-help topic 显示指定主题的帮助信息
--help topic 显示指定主题的帮助信息
-version 显示版本信息
-buildconf 显示构建配置
-formats 显示可用 formats
-muxers 显示可用 muxers
-demuxers 显示可用 demuxers
-devices 显示可用 devices
-codecs 显示可用 codecs
-decoders 显示可用 decoders
-encoders 显示可用 encoders
-bsfs 显示可用 bit stream filters
-protocols 显示可用 protocols
-filters 显示可用 filters
-pix_fmts 显示可用 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
全局选项(FFmpeg 设置):
-loglevel loglevel 设置日志级别
-v loglevel 设置日志级别
-report 生成报告
-max_alloc bytes 设置单个已分配块的最大值
-y 覆盖输出文件
-n 永不覆盖输出文件
-ignore_unknown 忽略未知流类型
-filter_threads number of non-complex filter threads
-filter_complex_threads number of threads for -filter_complex
-stats 编码期间输出进度信息
-max_error_rate 最大错误率(0.0 - 无错误率,1.0 - 100%错误率) 超过此值将返回错误。
-bits_per_raw_sample number 设置每个原始样本的比特数
-vol volume 更改音频音量(正常值:256)
单文件主要选项:
-f fmt 强制使用格式
-c codec 编解码器名称
-codec codec 编解码器名称
-pre preset 预设名称
-map_metadata outfile[,metadata]:infile[,metadata] 从输入文件获取并设置为输出文件的元数据
-t duration 设置记录或转码音视频时长
-to time_stop 设置记录或转码停止时间
-fs limit_size 设置文件大小限制(单位:bytes)
-ss time_off 设置开始时间偏移量
-sseof time_off 设置开始时间相对与结束的偏移量(反向偏移)
-seek_timestamp enable/disable seeking by timestamp with -ss
-timestamp time 设置录制时间戳('now'设为当前时间)
-metadata string=string 添加元数据
-program title=string:st=number... add program with specified streams
-target type 指定目标文件类型 ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")
-apad audio pad
-frames number 设置输出帧数
-filter filter_graph 设置流滤镜
-filter_script filename 从文件中获取流滤镜描述
-reinit_filter 设置修改输入参数后重置滤镜
-discard discard
-disposition disposition
视频选项:
-vframes number 设置输出视频帧数
-r rate 设置帧率(Hz value, fraction or abbreviation)
-s size 设置帧大小(WxH or abbreviation)
-aspect aspect 设置长宽比(4:3, 16:9 or 1.3333, 1.7777)
-bits_per_raw_sample number 设置每个原始样本的比特数
-vn disable video
-vcodec 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 设置视频过滤器
-ab bitrate 设置音频比特率(使用 -b:a)
-b bitrate 设置视频比特率(使用 -b:v)
-dn disable data
音频选项:
-aframes number 设置输出音频帧数
-aq quality 设置音频质量(codec-specific)
-ar rate 设置音频采样率(in Hz)
-ac channels 设置音频通道数
-an disable audio
-acodec codec 设置音频编解码器('copy' to copy stream)
-vol volume 更改音频音量(正常值:256)
-af filter_graph 设置音频过滤器
字幕选项:
-s size 设置帧大小 (WxH or abbreviation)
-sn 禁用字幕
-scodec codec 设置字幕编解码器('copy' to copy stream)
-stag fourcc/tag force subtitle tag/fourcc
-fix_sub_duration 解决字幕时间
-canvas_size size 设置字幕画布大小(WxH or abbreviation)
-spre preset 将字幕选项设置为指定的预设值