PTS,DTS,CTS和I,P,B帧的关系

来源:互联网 发布:淘宝详情分割线 编辑:程序博客网 时间:2024/05/22 10:36

今天终于弄懂以上几个关系。

I frame 的解码不依赖于任何的其它的帧.

p frame的解码则依赖于其前面的I frame或者P frame.

B frame的解码则依赖于其前的最近的一个I frame或者P frame 及其后的最近的一个P frame.

解码顺序:

I P B B B P B B B ...
显示顺序
I B B B P B B B P ... 

DTS和PTS的不同:

DTS主要用于视频的解码,在解码阶段使用.

PTS主要用于视频的同步和输出.在display的时候使用.

在没有B frame的情况下.DTS和PTS的输出顺序是一样的.(这点很重要)

compositionTime = (PTS - DTS) / 90.0 

AVCVIDEOPACKET

CompositionTime SI24 if AVCPacketType == 1
Composition time offset   

    else

0

由于我做的是直播流,为了减少延时,没有使用B帧。故CompositionTime为00 00 00.

特此记录

而x264.h里面
x264_picture_t两个成员

    int64_t i_pts;
    /* Out: frame dts. When the pts of the first frame is close to zero,
     *      initial frames may have a negative dts which must be dealt with by any muxer */
    int64_t i_dts;
    /* In: custom encoding parameters to be set from this frame forwards
           (in coded order, not display order). If NULL, continue using
           parameters from the previous frame.  Some parameters, such as
           aspect ratio, can only be changed per-GOP due to the limitations
           of H.264 itself; in this case, the caller must force an IDR frame
           if it needs the changed parameter to apply immediately. */

解码顺序:

I P B B B P B B B ...
显示顺序
I B B B P B B B P ... 

0 0