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