Suppose there is a MPEG picture sequence and you know the decoding order. How do you get the output order (=presentation order)?
Assuming every picture is a frame structure, we can use the following method.
Imagine a ditch. Only I or P picture drops into it. If a picture drops when the ditch already has another picture, it’s pushed out. For example, suppose we have a picture sequence in decoding order: I, B, P, I.
B picture passes over the ditch and outputs (presented).
P picture drops into the ditch…
And it pushes out the I picture. The I picture outputs.
Then, the last I picture comes. It drops into the ditch …
and pushes out the P picture.
Therefore, the output order is B, I, P. The last I picture stays in the ditch until another reference picture or a sequence_end_code.
The method also indicates several interesting observations.
- PTS of a reference picture (I/P) is greater than DTS. DTS is a timestamp when the picture comes from the left. PTS is a timestamp when the picture is pushed out from the ditch.
- PTS of a non-Reference picture (B) is same as DTS.
- The last output picture is always a reference picture.
When a frame is coded as two field pictures, group each pair to one symbol as shown below.
- II -> I
- IP -> I
- PP -> P
- BB -> B
Then apply the method. Once you get the output order, convert the symbol back to the original picture types.
This method does not apply for H.264. To get output order of H.264 picture sequence, we need to parse POC (Picture Order Count) information coded in the bit stream.