-vsync
-vsync parameter
Video sync method.
For compatibility reasons old values can be specified as numbers.
Newly added values will have to be specified as strings always.0, passthrough
Each frame is passed with its timestamp from the demuxer to the muxer.1, cfr
Frames will be duplicated and dropped to achieve exactly the requested constant frame rate.2, vfr
Frames are passed through with their timestamp or dropped so as to prevent 2 frames from having the same timestamp.drop
As passthrough but destroys all timestamps, making the muxer generate fresh timestamps based on frame-rate.-1, auto
Chooses between 1 and 2 depending on muxer capabilities.
This is the default method.
0, passthrough: 时间戳不做任何改变,demuxer中是什么,直接传给muxer。
1, cfr: 为了达到固定的帧率,中间可能会丢弃一些帧。
最好使用字符串,如cfr来指定模式。
可以使用数字是为了兼容。
-vsync auto是默认的视频同步模式。根据muxer的处理能力选择0(passthrough)或1(cfr)。
-vsync auto
Note that the timestamps may be further modified by the muxer, after this.
For example, in the case that the format option avoid_negative_ts is enabled.
需要注意的是,在后续的处理过程中,时间戳还可能被修改。
比如启用了avoid_negative_ts参数时。
With -map you can select from which stream the timestamps should be taken.
You can leave either video or audio unchanged and sync the remaining stream(s) to the unchanged one.
利用-map,你可以选择采用哪路流的时间戳。
可以保持视频或音频不变,然后其它流同步到不变的那路流。
ffmpeg.h中的相关宏定义:
#define VSYNC_AUTO -1
#define VSYNC_PASSTHROUGH 0
#define VSYNC_CFR 1
#define VSYNC_VFR 2
#define VSYNC_VSCFR 0xfe
#define VSYNC_DROP 0xff
ffmpeg_opt.c中
const OptionDef options[] = {
/* main options */
CMDUTILS_COMMON_OPTIONS
{ "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
"force format", "fmt" },
...
{ "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
"video sync method", "" },
由 .func_arg = opt_vsync看出处理函数为opt_vsync:
static int opt_vsync(void *optctx, const char *opt, const char *arg)
{
if (!av_strcasecmp(arg, "cfr")) video_sync_method = VSYNC_CFR;
else if (!av_strcasecmp(arg, "vfr")) video_sync_method = VSYNC_VFR;
else if (!av_strcasecmp(arg, "passthrough")) video_sync_method = VSYNC_PASSTHROUGH;
else if (!av_strcasecmp(arg, "drop")) video_sync_method = VSYNC_DROP;
if (video_sync_method == VSYNC_AUTO)
video_sync_method = parse_number_or_die("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR);
return 0;
}
传入的参数值,被保存在video_sync_method中。
可以查询video_sync_method的默认值:
int video_sync_method = VSYNC_AUTO;
-async
-async samples_per_second
Audio sync method. "Stretches/squeezes" the audio stream to match the timestamps, the parameter is the maximum samples per second by which the audio is changed.
-async 1 is a special case where only the start of the audio stream is corrected without any later correction.Note that the timestamps may be further modified by the muxer, after this.
For example, in the case that the format option avoid_negative_ts is enabled.This option has been deprecated. Use the aresample audio filter instead.
这个参数已经废弃。请使用sresample audio filter。
aresample
aresample 是一个音频的filter。
Resample the input audio to the specified parameters, using the libswresample library.
If none are specified then the filter will automatically convert between its input and output.
该参数调用libswresample库,对输入的音频按照指定参数进行重采样。
This filter is also able to stretch/squeeze the audio data to make it match the timestamps or to inject silence / cut out audio to make it match the timestamps, do a combination of both or do neither.
The filter accepts the syntax
[sample_rate:]resampler_options
sample_rate表示采样率。
resampler_options 是key=value 对的list, 用 ":"来分割.
参数参见: https://ffmpeg.org/ffmpeg-resampler.html#Resampler-Options
Examples
- Resample the input audio to 44100Hz:
aresample=44100
- Stretch/squeeze samples to the given timestamps, with a maximum of 1000 samples per second compensation:
aresample=async=1000
avoid_negative_ts
avoid_negative_ts integer (output)
Possible values:‘make_non_negative’
Shift timestamps to make them non-negative. Also note that this affects only leading negative timestamps, and not non-monotonic negative timestamps.‘make_zero’
Shift timestamps so that the first timestamp is 0.‘auto (default)’
Enables shifting when required by the target format.‘disabled’
Disables shifting of timestamp.When shifting is enabled, all output timestamps are shifted by the same amount.
Audio, video, and subtitles desynching and relative timestamp differences are preserved compared to how they would have been without shifting.
References:
https://ffmpeg.org/ffmpeg-all.html