<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi there,</div><div><br></div><div>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:</div><div><br></div><div># I ran this command for the files in sequence, therefore the start pts from next is supposed to be the previous + duration * 90khz <br></div><div><br></div><div>$ ffprobe -loglevel panic -select_streams v -show_entries "stream=start_pts,start_time,duration" <file.ts><br><br># 197562612960.ts<br>start_pts=8584117906<br>start_time=95379.087844<br>duration=3.999333<br><br># 197562972960.ts<br>start_pts=8584477906 (it shows right! previous start_pts + 4 * 90000)<br>start_time=95383.087844<br>duration=3.999333<br><br># 197563332960.ts<br>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)<br>start_time=-56.629844<br>duration=3.999333<br><br></div><div>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. <br></div><div>(the line  return timestamp - (1ULL << st->pts_wrap_bits);)</div><div><br></div><div>Anyway, am I missing about the way PTS wraparound works? (for MPEG TS) or is it a bug on this function?<br></div><div><br></div><div>PS: From all the players I tried, they played the video as if it didn't have any error. <br></div><div><br></div><div>```/**<br> * Wrap a given time stamp, if there is an indication for an overflow<br> *<br> * @param st stream<br> * @param timestamp the time stamp to wrap<br> * @return resulting time stamp<br> */<br>static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp)<br>{<br>    if (st->pts_wrap_behavior != AV_PTS_WRAP_IGNORE &&<br>        st->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) {<br>        if (st->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET &&<br>            timestamp < st->pts_wrap_reference)<br>            return timestamp + (1ULL << st->pts_wrap_bits);<br>        else if (st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET &&<br>            timestamp >= st->pts_wrap_reference)<br>            return timestamp - (1ULL << st->pts_wrap_bits);<br>    }<br>    return timestamp;<br>}```<br><br>`utils.c` l:106<br></div></div></div></div>