Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start timestamp of pts_time in an MPEG-TS stream is not zero

Tags:

ffmpeg

I'm using ffmpeg to generate a MPEG-TS stream using the following command.

ffmpeg -i file1.mp4 -c:v libx265 -x265-params crf=25 -c:a copy output1.ts

When examining the output1.ts using,

ffplay -i output1.ts -vf showinfo

reveals that start timestamp under pts_time is not equal to zero. it shows 1.48.

A remuxing using

ffmpeg -i output1.ts -c:v copy -c:a copy -mpegts_copyts 1 output2.ts

caused the output2.ts to have a start timestamp of 0.08.

I would really appreciate if someone could explain me the reason for this behaviour and how I can set the start timestamp to zero.

like image 219
userDtrm Avatar asked Dec 17 '14 18:12

userDtrm


1 Answers

It is very common to add an arbitrary amount of time at the start of a transport stream. The reason for this is two fold.

First, transport streams were originally intended for very long broadcasts (days or weeks. Think television stations). TS uses 33 bits to store 90kHz ticks. This makes timesamp rollovers very common (about once a day). Because the timestamp rolls over so frequently, It is generally not a good idea to rely on the time stamps as anything other than an arbitrary tick on a ever moving clock with a start time at an unknown point in the past. Think of an analog clock, and remove all markings. Without the orientation, you can not use it to tell time. But you can still use it to measure time. In other words the timestamps only have meaning relative to other timestamps in the stream. They do not exist for human convenience. They exist so the decoder can do its job.

But as to why not start at 0 anyway. TS stores pts and dts as separate values, where as other containers use a dts+cts to determine pts. So, If you have a stream with out of order (B) frames, you will encounter frames that must be decoded before time 0, and displayed after. In other words, you will have negative (rolled over) dts values at the start of the stream. To simplify the decoders job, some value larger then the largest possible cts (pts-dts) is added to the pts/dts to bring them into the positive range at the start. This is common practice, and left up to the decoder/player to apply the logic as to what time is displayed to the user.

like image 60
szatmary Avatar answered Sep 24 '22 06:09

szatmary