[Libav-user] Negative PTS when it is closer to wrap around at MPEG TS
Leandro Moreira
leandro.ribeiro.moreira at gmail.com
Mon Mar 18 21:28:34 EET 2019
Hi there,
I'm using libav and I noticed that suddenly my video files (.ts) became to
show negative (start) PTS. I thought it was something wrong in my code but
then I tried to use ffprobe to see its contents:
# I ran this command for the files in sequence, therefore the start pts
from next is supposed to be the previous + duration * 90khz
$ ffprobe -loglevel panic -select_streams v -show_entries
"stream=start_pts,start_time,duration" <file.ts>
# 197562612960.ts
start_pts=8584117906
start_time=95379.087844
duration=3.999333
# 197562972960.ts
start_pts=8584477906 (it shows right! previous start_pts + 4 * 90000)
start_time=95383.087844
duration=3.999333
# 197563332960.ts
start_pts=-5096686 (it shows wrong! previous start_pts + 4 * 90000 =
8584837906 which is not bigger than 2^33-1 and even if it were it should
wrap around)
start_time=-56.629844
duration=3.999333
While I was trying to find what causes it, I found a function called
wrap_timestamp located at utils.c line 106, it seems that the value
-5096686 is obtained when you do the following calculation: previous pts -
2^33.
(the line return timestamp - (1ULL << st->pts_wrap_bits);)
Anyway, am I missing about the way PTS wraparound works? (for MPEG TS) or
is it a bug on this function?
PS: From all the players I tried, they played the video as if it didn't
have any error.
```/**
* Wrap a given time stamp, if there is an indication for an overflow
*
* @param st stream
* @param timestamp the time stamp to wrap
* @return resulting time stamp
*/
static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp)
{
if (st->pts_wrap_behavior != AV_PTS_WRAP_IGNORE &&
st->pts_wrap_reference != AV_NOPTS_VALUE && timestamp !=
AV_NOPTS_VALUE) {
if (st->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET &&
timestamp < st->pts_wrap_reference)
return timestamp + (1ULL << st->pts_wrap_bits);
else if (st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET &&
timestamp >= st->pts_wrap_reference)
return timestamp - (1ULL << st->pts_wrap_bits);
}
return timestamp;
}```
`utils.c` l:106
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190318/8388d556/attachment.html>
More information about the Libav-user
mailing list