I am trying to modify an HLS segment transport stream, and preserve its start time with ffmpeg. However the output does not preserve the input file\'s start_time value, even if
I decided to dig a little in the source to understand what's happening.
The overall start_time of the program is calculated by the using the presentation time stamp(PTS) of each individual stream in the file.
ffmpeg sets a default Mux decode delay value of 0.7 seconds. This is set in the ffmpeg_opt.c
This delay value is added to the PTS value of each packet, if the "copyts" flag is not set(in libavformat/mpegtsenc.c):
if (ts->copyts < 1) {
if (pts != AV_NOPTS_VALUE)
pts += delay;
if (dts != AV_NOPTS_VALUE)
dts += delay;
}
In this case, the encoder doubles the delay value :
const uint64_t delay =
av_rescale(s->max_delay, 90000, AV_TIME_BASE)*2;
Therefore, an extra 1.4 seconds get added to each packet's PTS. If "copyts" is provided, this is added to the timestamp value from the input stream.
It is possible to override this delay using the "muxdelay" flag; in that case the delay gets set to zero.
Now, why 0.7? why twice in the case of mpeg ts ?I wish I know the answers, presumably it's there in the spec somewhere. But for now, this would have to do.