ffmpeg # 為什么remux之后大多數(shù)ts文件的第一個(gè)時(shí)間戳是1.4s (1260000)

ffmpeg.h

    float mux_max_delay;

ffmpeg_opt.c

static void init_options(OptionsContext *o)
{
    memset(o, 0, sizeof(*o));

    ..
    o->mux_max_delay  = 0.7; // 重點(diǎn) 初始化是 0.7
    ...
}

static int open_output_file(OptionsContext *o, const char *filename)
{
    AVFormatContext *oc;
...
    oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
...
}
static int mpegts_init(AVFormatContext *s)
{
...
if (ts->copyts < 1)
            ts->first_pcr = av_rescale(s->max_delay, PCR_TIME_BASE, AV_TIME_BASE);


static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
{
...
       const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) * 2; // 重點(diǎn) 乘以了2倍
...
    if (ts->copyts < 1) {
        if (pts != AV_NOPTS_VALUE)
            pts += delay;
        if (dts != AV_NOPTS_VALUE)
            dts += delay;
    }
...
}

計(jì)算如下:
ts文件的time base是 90000

1.4 * 90000 =  1260000

即:

    pts = 126000
    pts_time = 1.4000

其它說(shuō)明:

the splitting and transcoding process, generates a delay(0.7 seconds) on the frame's Play Time Seconds.
Surprisingly, when we are dealing with .ts files,this delay is doubled, which means the first frame will have a 1.4 seconds delay to play.

The solution to this problem is also using another property (muxdelay), that sets the maximum demux-decode delay. If we set this property to 0, the 0.7 seconds delay no longer exists.


控制delay的參數(shù)

另外的參數(shù)mark:

muxdelay

-muxdelay seconds (output)
Set the maximum demux-decode delay.

max_delay

max_delay integer (input/output)
Set maximum muxing or demuxing delay in microseconds.

muxdelay sets the delay in seconds while max_delay sets it in microseconds.
The end result is the same. You can see the code that sets the underlying value in ffmpeg_opt.c

output_ts_offset offset (output)
Set the output time offset.

offset must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.

The offset is added by the muxer to the output timestamps.

Specifying a positive offset means that the corresponding streams are delayed bt the time duration specified in offset. Default value is 0 (meaning that no offset is applied).

MPEG-TS流中的pts_time的開(kāi)始時(shí)間戳不為零默穴?

但至于為什么不從0開(kāi)始呢般此。
TS將pts和dts存儲(chǔ)為單獨(dú)的值蝙茶,而其他容器使用dts + cts來(lái)確定pts哈街。
因此园骆,如果您的流有亂序(B)幀敞曹,您將遇到必須在時(shí)間0之前解碼并在之后顯示的幀世吨。
換句話(huà)說(shuō)士鸥,您將在流的開(kāi)頭具有負(fù)(滾動(dòng))dts值饮戳。
為了簡(jiǎn)化解碼器工作豪治,一些值大于最大可能的cts(pts-dts)被添加到pts / dts以使它們?cè)陂_(kāi)始時(shí)進(jìn)入正范圍。
這是常見(jiàn)的做法扯罐,并由解碼器/播放器將邏輯應(yīng)用于向用戶(hù)顯示的時(shí)間负拟。

MPEG-TS is a streaming format and ffmpeg will offset timestamps to accommodate possible video encoding delay. Setting muxpreload and muxdelay to 0 can avoid that.

FFmpeg is simply telling you the starting timestamp as parsed from the input.
MPEG-TS is a transport stream format, used to convey television broadcasts..etc, having no global header, and can be sliced at ~arbitrary points.
There are timestamp packets (PCR) at regular intervals, and ffmpeg is showing you the timestamp of the earliest packet.

References:

https://lists.ffmpeg.org/pipermail/libav-user/2012-May/002034.html
https://www.w3.org/2013/12/byte-stream-format-registry/mp2t-byte-stream-format.html
https://tsduck.io/
https://lists.ffmpeg.org/pipermail/ffmpeg-user/2013-February/013778.html
https://ffmpeg.org/ffmpeg-formats.html
https://cloud.tencent.com/developer/ask/137010
https://www.thinbug.com/q/27532571
https://superuser.com/questions/1109852/ffmpeg-transcode-each-segment-individually
https://stackoverflow.com/questions/29527882/ffmpeg-copyts-to-preserve-timestamp?answertab=active#tab-top
https://stackoverflow.com/questions/44565968/while-transcoding-to-mpegts-ffmpeg-creates-the-first-frame-after-1-48-seconds-de
https://superuser.com/questions/1462997/ffmpeg-spliting-video-but-keeping-the-timestamp/1463051
https://video.stackexchange.com/questions/26364/how-to-change-start-time-using-ffmpeg
https://www.thinbug.com/q/44565968

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市歹河,隨后出現(xiàn)的幾起案子掩浙,更是在濱河造成了極大的恐慌,老刑警劉巖秸歧,帶你破解...
    沈念sama閱讀 219,539評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件厨姚,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡键菱,警方通過(guò)查閱死者的電腦和手機(jī)谬墙,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評(píng)論 3 396
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)经备,“玉大人拭抬,你說(shuō)我怎么就攤上這事∏置桑” “怎么了造虎?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,871評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀(guān)的道長(zhǎng)纷闺。 經(jīng)常有香客問(wèn)我算凿,道長(zhǎng)份蝴,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,963評(píng)論 1 295
  • 正文 為了忘掉前任澎媒,我火速辦了婚禮搞乏,結(jié)果婚禮上波桩,老公的妹妹穿的比我還像新娘戒努。我一直安慰自己,他們只是感情好镐躲,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,984評(píng)論 6 393
  • 文/花漫 我一把揭開(kāi)白布储玫。 她就那樣靜靜地躺著,像睡著了一般萤皂。 火紅的嫁衣襯著肌膚如雪撒穷。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,763評(píng)論 1 307
  • 那天裆熙,我揣著相機(jī)與錄音端礼,去河邊找鬼。 笑死入录,一個(gè)胖子當(dāng)著我的面吹牛蛤奥,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播僚稿,決...
    沈念sama閱讀 40,468評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼凡桥,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了蚀同?” 一聲冷哼從身側(cè)響起缅刽,我...
    開(kāi)封第一講書(shū)人閱讀 39,357評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蠢络,沒(méi)想到半個(gè)月后衰猛,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,850評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡刹孔,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,002評(píng)論 3 338
  • 正文 我和宋清朗相戀三年啡省,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片芦疏。...
    茶點(diǎn)故事閱讀 40,144評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡冕杠,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出酸茴,到底是詐尸還是另有隱情分预,我是刑警寧澤,帶...
    沈念sama閱讀 35,823評(píng)論 5 346
  • 正文 年R本政府宣布薪捍,位于F島的核電站笼痹,受9級(jí)特大地震影響配喳,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜凳干,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,483評(píng)論 3 331
  • 文/蒙蒙 一晴裹、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧救赐,春花似錦涧团、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,026評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至预厌,卻和暖如春阿迈,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背轧叽。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,150評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工苗沧, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人炭晒。 一個(gè)月前我還...
    沈念sama閱讀 48,415評(píng)論 3 373
  • 正文 我出身青樓待逞,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親腰埂。 傳聞我的和親對(duì)象是個(gè)殘疾皇子飒焦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,092評(píng)論 2 355