ffmpeg 命令行 详解 关键参数 字幕流相关

来源:互联网 发布:log4j打印sql输出级别 编辑:程序博客网 时间:2024/06/10 22:42


-i 用于选取输入文件


-c 用于指定流类型

后面加冒号和流类型

譬如 -c:v指的是视频流

等同于 -vcodec

同样的

-c:a = -acodec

-c:s = -scodec

如果只有-c则是针对源文件中所有流

后面加入copy参数用于复制源文件中的相关流

不指定copy的话ffmpeg会重新创建流

这样码率往往会下降

建议不舍弃的流都采用copy

譬如字幕流的引入就有两种方式

1.copy

使用copy方式字幕流只是复用(mux)到视频文件(container)中

此法只是需要将字幕流按照timestamps来split为frame 所以速度最快

2.burn

使用burn方式的特征是会调用-vf参数 即videofilter 调用libavfilter中的函数

这样字幕流就相当于覆盖在视频流中

变成原视频流中的像素点

最后output的文件是没有字幕流的

目前网上的美剧大部分是采用burn方式

可参照官网wiki:

https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo

但是我尚未查明普通播放器导入外部字幕如此迅速的原因

也许是他们有自己的流解析系统

希望了解这方面的童鞋能给我留言谢谢


-map可以指定映射

参数中冒号用于分割映射值

a代表audio

v代表video

s代表subtitles

冒号前是-i对应的输入文件的序号

第一个-i就是0 以此类推

冒号后如果是a,v,s则为指定对应的流类型

此时再加冒号,其后则为对应流类型在源文件中的序号

譬如 0:s:1就是第一个input file中的 第二个字幕流

如果不含a,v,s就等于直接按序索引对应的流

譬如0:2就是取第一个源文件中的第3个流

若在参数前加上减号“-”

意思是舍弃对应的流

譬如 -map 0 -map 0:s:1 舍弃第一个源文件中的第二个字幕流

注意 前面的-map 0 不可省略

即是 必须先有加再有减



以下为官网文档相关clip



-f fmt (input/output)

Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.

-i filename (input)

input file name

-y (global)

Overwrite output files without asking.

-n (global)

Do not overwrite output files, and exit immediately if a specified output file already exists.

-c[:stream_specifiercodec (input/output,per-stream)
-codec[:stream_specifiercodec (input/output,per-stream)

Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.

For example

ffmpeg -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT

encodes all video streams with libx264 and copies all audio streams.

For each stream, the last matching c option is applied, so

ffmpeg -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT

-vf filtergraph (output)

Create the filtergraph specified by filtergraph and use it to filter the stream.

-map [-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]] |[linklabel] (output)

Designate one or more input streams as a source for the output file. Each input stream is identified by the input file index input_file_id and the input stream index input_stream_id within the input file. Both indices start at 0. If specified, sync_file_id:stream_specifier sets which input stream is used as a presentation sync reference.

The first -map option on the command line specifies the source for output stream 0, the second -map option specifies the source for output stream 1, etc.

- character before the stream identifier creates a "negative" mapping. It disables matching streams from already created mappings.

An alternative [linklabel] form will map outputs from complex filter graphs (see the -filter_complexoption) to the output file. linklabel must correspond to a defined output link label in the graph.

For example, to map ALL streams from the first input file to output

ffmpeg -i INPUT -map 0 output

For example, if you have two audio streams in the first input file, these streams are identified by "0:0" and "0:1". You can use -map to select which streams to place in an output file. For example:

ffmpeg -i INPUT -map 0:1 out.wav

will map the input stream in INPUT identified by "0:1" to the (single) output stream in out.wav.

For example, to select the stream with index 2 from input file a.mov (specified by the identifier "0:2"), and stream with index 6 from input b.mov (specified by the identifier "1:6"), and copy them to the output file out.mov:

ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov

To select all video and the third audio stream from an input file:

ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT

To map all the streams except the second audio, use negative mappings

ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT

To pick the English audio stream:

ffmpeg -i INPUT -map 0:m:language:eng OUTPUT

Note that using this option disables the default mappings for this output file.


-f fmt (input/output)

Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.

-i filename (input)

input file name

-y (global)

Overwrite output files without asking.

-n (global)

Do not overwrite output files, and exit immediately if a specified output file already exists.

-c[:stream_specifiercodec (input/output,per-stream)
-codec[:stream_specifiercodec (input/output,per-stream)

Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.

For example

ffmpeg -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT

encodes all video streams with libx264 and copies all audio streams.

For each stream, the last matching c option is applied, so

ffmpeg -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT

-vf filtergraph (output)

Create the filtergraph specified by filtergraph and use it to filter the stream.

-map [-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]] |[linklabel] (output)

Designate one or more input streams as a source for the output file. Each input stream is identified by the input file index input_file_id and the input stream index input_stream_id within the input file. Both indices start at 0. If specified, sync_file_id:stream_specifier sets which input stream is used as a presentation sync reference.

The first -map option on the command line specifies the source for output stream 0, the second -map option specifies the source for output stream 1, etc.

- character before the stream identifier creates a "negative" mapping. It disables matching streams from already created mappings.

An alternative [linklabel] form will map outputs from complex filter graphs (see the -filter_complexoption) to the output file. linklabel must correspond to a defined output link label in the graph.

For example, to map ALL streams from the first input file to output

ffmpeg -i INPUT -map 0 output

For example, if you have two audio streams in the first input file, these streams are identified by "0:0" and "0:1". You can use -map to select which streams to place in an output file. For example:

ffmpeg -i INPUT -map 0:1 out.wav

will map the input stream in INPUT identified by "0:1" to the (single) output stream in out.wav.

For example, to select the stream with index 2 from input file a.mov (specified by the identifier "0:2"), and stream with index 6 from input b.mov (specified by the identifier "1:6"), and copy them to the output file out.mov:

ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov

To select all video and the third audio stream from an input file:

ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT

To map all the streams except the second audio, use negative mappings

ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT

To pick the English audio stream:

ffmpeg -i INPUT -map 0:m:language:eng OUTPUT

Note that using this option disables the default mappings for this output file.

0 0
原创粉丝点击