|
1 | | -# Timestamps - the stamps in time |
| 1 | +# Timestamps |
2 | 2 |
|
3 | 3 | In a nutshell, timestamps determine when a given event occurred in time. For |
4 | 4 | example when you take a photo with your phone, the exact time and date the photo |
@@ -61,36 +61,40 @@ another 200ms pass. |
61 | 61 | This element is useful if we have non-realtime input, and realtime output, for |
62 | 62 | example we want to stream the contents of a MP4 file with WebRTC. If we didn't |
63 | 63 | use Realtimer, then we would read contents of the file as fast as possible and |
64 | | -send them as fast as possible, which is not what we want, we want the receiver |
65 | | -to receive the stream in realtime, so that they can display it as it comes. |
| 64 | +send them over as fast as possible, which is not something we want. We want the receiver |
| 65 | +to get the stream in realtime, so that they can display it as it comes. |
66 | 66 |
|
67 | 67 | ## Decoding Time Stamps |
68 | 68 |
|
69 | | -The purpose of DTSs is to tell a decoder when a given media chunk should be |
| 69 | +The purpose of DTSs is to tell a decoder when a frame should be |
70 | 70 | decoded. In a lot of codecs the media can be decoded as it comes, but in some |
71 | 71 | cases, like in [H264](../membrane_tutorials/h264/1_Introduction.md), it's |
72 | 72 | not that simple. In a nutshell, in H264 some frames are encoded based on |
73 | 73 | information from other frames. There are three main types of frames: |
74 | 74 |
|
75 | 75 | * I-frame (Intra-coded picture) - A frame of this type is encoded without the |
76 | | - information from any other frames. |
| 76 | + information from any other frames. Sometimes referred to as a _keyframe_. |
77 | 77 | * P-frame (Predicted picture) - A frame of this type is encoded with the usage |
78 | | - of information of previous frames. If we have a static shot, then it takes |
| 78 | + of information from previous frames. If we have a static scene, then it takes |
79 | 79 | much less space to encode a frame by using the fact that it's almost the |
80 | | - same as the previous one. |
| 80 | + same as the previous one and encoding only the things that have changed. |
81 | 81 | * B-frame (Bidirectional predicted picture) - A frame of this type is similar |
82 | 82 | to a P-frame, as it uses information from other frames for it's encoding. |
83 | 83 | However, it not only depends on previous pictures, but also on future ones. |
84 | 84 | That's where the DTSs come in, because to decode a B-frame we also need to |
85 | | - decode all frames it's encoding is based on, including the future ones. |
86 | | - For example, let's assume that we have a slice of a stream consisting of |
87 | | - three frames where frame 2 is a B-frame that's encoded based on the |
88 | | - frames 1 and 3. If a decoder receives these frames with the following |
89 | | - timestamps: |
90 | | - |
91 | | - 1) pts: 0ms, dts: 0ms |
92 | | - 2) pts: 200ms, dts: 400ms |
93 | | - 3) pts: 400ms, dts: 200ms |
94 | | - |
95 | | - It will first decode the frames in order (1, 3, 2). If it hadn't decoded |
96 | | - frames 1 and 3 first, it couldn't decode frame 2. |
| 85 | + decode all frames it's based on, including the future ones. |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +For example, let's assume that we have a slice of a stream from the diagram, |
| 90 | +consisting of four frames. Frames 1 and 4 are I-frames, frame 2 is a P-frame |
| 91 | +depending on frame 1, and frame 3 is a B-frame depending of frames 2 and 4. |
| 92 | +If a decoder receives these frames with the following timestamps: |
| 93 | + |
| 94 | +1) pts: 0ms, dts: 0ms |
| 95 | +2) pts: 200ms, dts: 200ms |
| 96 | +3) pts: 400ms, dts: 600ms |
| 97 | +4) pts: 600ms, dts: 400ms |
| 98 | + |
| 99 | +It will first decode the frames in order (1, 2, 4, 3), according to their DTS. |
| 100 | +If it hadn't decoded frames 2 and 4 first, it couldn't have decoded frame 3. |
0 commit comments