[Libav-user] Help to understand PTS, DTS, timebase

Leandro Moreira leandro.ribeiro.moreira at gmail.com
Tue Nov 14 01:07:17 EET 2017


Hi there,

I'm trying to learn and also to write a tutorial
<https://github.com/leandromoreira/ffmpeg-libav-tutorial#learn-ffmpeg-libav-the-hard-way>
about
my adventure of learning FFmpeg libav (this amazing library, congrats lol).

The first part was only to decode some frames and save them into grayscale
images but I'm planning to write more about transcoding, remuxing and etc.

And one of the fundamental parts is how a player will play the video in
sync with audio no matter how CPU is loaded or if the system clock is
drifting. I can't understand it but I do accept links suggestion to read
=), anyway...

*What I think I know:*

Let's say we have a video with 25 fps and that we're decoding to play 4
frames of it.

PTS 0 1 2 3 (when it needs to be present, order)
DTS 0 3 1 1(when it needs to be decoded) (can be different due to B frames
and their need to know the future beforehand)

PTS_TIME FRAME_N x TIMEBASE (when it needs to be played, a value that we
can use in some sorta way into seconds)

First of all, I assume that this information about when you will play a
frame nth is in the container, not on the codec, right?

Now, we're going to stamp a timestamp on each frame, let's say we chose our
timebase
<https://stackoverflow.com/questions/43333542/what-is-video-timescale-timebase-or-timestamp-in-ffmpeg/43337235?noredirect=1#comment81441809_43337235>
to be 1/75 and our PTS to be increased 3 each frame, therefore we'd have
these pts_time about when I should play a given frame.

Timebase = 1/75; Timescale = 75
 Frame        pts           pts_time
   0          0          0 x 1/75 = 0.00
   1          3          3 x 1/75 = 0.04
   2          6          6 x 1/75 = 0.08
   3          9          9 x 1/75 = 0.12
   ...


*What I still don't know:*

Why did we choose to increase our PTS by 3 and not 5000? Why we pick 1/75
as timebase and not 1/25? what other values can we use?

Any help will be much appreciated with examples like this one, with only 4
frames building and be justifying why each value and how it's reliable.

Thanks a lot.

-----------

PS: I already read the "Doing a player with less than 1000 lines" part of
PTS and DTS but I could not understand it completely.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20171113/614f5b4c/attachment.html>


More information about the Libav-user mailing list