前言
致敬师哥雷神,但师哥的FFMPEG参数的这篇文章,里面一些参数在FFMPEG的最新版已经都去掉了 文章链接https://blog.csdn.net/leixiaohua1020/article/details/12751349 同为广院的工科研究生,我写了这篇文章进行补充,针对于FFMEPG 4.2.1 以上版本
FFMPEG的命令行格式
在FFMPEG的官网http://ffmpeg.org/ffmpeg.html给出的命令行格式是这样的
ffmpeg
[global_options] {[input_file_options] -i input_url
} ... {[output_file_options] output_url
} ...
ffmpeg
[全局指令,可选
] {[对输入媒体文件的操作
,可选
] -i 输入文件的路径
} ...{[对输出文件的操作,可选
] 输出文件的路径
}
实例1 转码
将input.avi转码成output.ts,并设置视频的码率为64 kbps(64 kbit/s)
#实例
1
ffmpeg
-i input
.avi
-b
:v
64k
-bufsize
64k output
.ts
ffmpeg
-y
-i input
.avi
-b
:v
64k
-bufsize
64k output
.ts
ffmpeg
-n
-i input
.avi
-b
:v
64k
-bufsize
64k output
.ts
#扩展
1
可以同时编码为多种格式,并定义从输入流到输出流的映射:
在
64 kbits 时将 a
.wav 转换为 a
.mp2,在
128 kbits 时转换为 b
.mp2。
"-map: 索引"指定每个输出流使用哪个输入流,按输出流定义的顺序排列。
ffmpeg
-i
/tmp
/a
.wav
-map
0:a
-b
:a
64k
/tmp
/a
.mp2
-map
0:a
-b
:a
128k
/tmp
/b
.mp2
参数详解
参数参数含义备注
-y强制覆盖输出文件,即如果 output.ts 文件已经存在的话,不经用户确认就覆盖掉-y为全局指令-n不覆盖输出文件,即如果 output.ts 文件已经存在的话,直接退出-n为全局指令-i输入文件的路径-b:v 64k -bufsize 64k设置输出文件的视频比特率(码率),-bufsize设置码率控制缓冲器大小-b:v设置的码率和-bufsize缓冲器大小可不一致-b:a设置输出文件的音频码率见上面扩展1命令
实例2 改变视频帧率
强制修改输入文件的帧率为1 fps(仅对原始格式数据有效,如m2v视频数据,yuv原始视频文件,jpeg图片等格式),并把输出文件帧率调整到24fps
#实例
2
ffmpeg
-r
1 -i input
.m2v
-r
24 output
.avi
#ffmpeg
{对输入文件的操作
} {对输出文件的操作
}
ffmpeg
-s
1920x1080
-pix_fmt yuv422p
-i src01_1920x1080_422
.yuv
-s
1280x720
-pix_fmt yuv420p src01_1280x720
.yuv
ffmpeg
-f image2
-framerate
12 -i foo
-%03d
.jpeg
-s WxH foo
.avi
参数详解
参数参数含义
-s设置视频的分辨率-r视频帧率(fps)-fs设置文件格式-pix_fmt设置像素的格式
实例3
示例
3-1:
截取一张
352x240尺寸大小的,格式为jpg的图片:
ffmpeg
-i test
.asf
-y
-f image2
-t
0.001 -s
352x240 a
.jpg
示例
3-2:
把视频的前
30帧转换成一个Animated Gif :
ffmpeg
-i test
.asf
-vframes
30 -y
-f gif a
.gif
示例
3-3:
在视频的第
8.01秒处截取
352*240 的缩略图
ffmpeg
-i test2
.asf
-y
-f image2
-ss
08.010 -t
0.001 -s
352x240 b
.jpg
参数详解
参数参数含义备注
-t设置持续时间-ssposition 设置起始时间,时间格式为[-][HH:]MM:SS[.m...]或[-]S+[.m...][s|ms|us]时间实例可以是23.189,55,0.2,200ms,200000us,12:03:45-b:v bitrate设置视频码率-b:a bitrate设置音频码率-r fps设置帧率-s wxh设置帧大小,格式为WxH-c:v codec设置视频编码器(作用于输出文件)或者设置视频解码器(作用于输入文件) 等同于-codec:v 和 -vcodec codec-c:a codec设置音频编/解码器 ,等同-codec:a和acodec codec-c:s codec设置字幕编/解码器 等同-codec:s和-scodec codec-ar freq设置音频采样率
FFMPEG参数大全
查询指令
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
-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 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
)
文件操作
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
例子ffmpeg
-sseof
-10 -i input
.mp4 output
.mp4 #
-10是指负值,负
10秒
该获得一段不知道长度的视频的最后
10秒,
请注意
,在stream
copy模式下(通过使用
-c copy或等效模式
),剪切将出现在最近的关键帧上
,因此它可能会缩短您确切的所需时间
.如果需要更高的准确性
,则必须重新编码而不是流复制
.
-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
)
-s size
set frame
size (WxH or abbreviation
)
-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
音频相关
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
高级选项
-map
更多参数请查看 FFMPEG官方文档(英文) http://ffmpeg.org/ffmpeg.html FFMPEG官方文档(中文) https://www.jianshu.com/p/da47b00c42ce
参考链接
https://blog.csdn.net/hemingwang0902/article/details/4382205 https://blog.csdn.net/xiaomucgwlmx/article/details/82852987 https://blog.csdn.net/leixiaohua1020/article/details/12751349 https://www.jianshu.com/p/049d03705a81 https://www.jianshu.com/p/124aee284a61