ffmpeg # 視頻同步參數(shù) -vsync & -aresample

-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.

References:

https://ffmpeg.org/ffmpeg-all.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • 超高速音視頻編碼器用法: ffmpeg [options] [[infile options] -i infile...
    吉兇以情遷閱讀 4,827評論 0 4
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,671評論 5 6
  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,932評論 0 13
  • 昨天和兒子不太愉快,我感覺可能是自己沒把握好如何說話,而且還有點想操縱兒子吧。 昨晚得知有個充滿青春氣息的大學同學...
    燕子重生scy閱讀 317評論 0 1
  • 同理心。其實之前聽過一句話,很少有人可以真正做到換位思考,因為大多數(shù)人都是自以為站在了對方角度思考,替對方安排做決...
    晨曦iuiu閱讀 132評論 0 0

友情鏈接更多精彩內容