-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來指定模式。
可以使用數(shù)字是為了兼容。
-vsync auto是默認的視頻同步模式。根據(jù)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.
需要注意的是,在后續(xù)的處理過程中,時間戳還可能被修改。
比如啟用了avoid_negative_ts參數(shù)時。
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看出處理函數(shù)為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;
}
傳入的參數(shù)值,被保存在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.
這個參數(shù)已經(jīng)廢棄。請使用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.
該參數(shù)調用libswresample庫,對輸入的音頻按照指定參數(shù)進行重采樣。
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, 用 ":"來分割.
參數(shù)參見: 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.‘a(chǎn)uto (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.