ffmpeg # 判断AVFrame是否为关键帧

typedef struct AVFrame {

...
    /**
     * width and height of the video frame
     */
    int width, height;

...

    /**
     * 1 -> keyframe, 0-> not
     */
    int key_frame;

    /**
     * Picture type of the frame.
     */
    enum AVPictureType pict_type;

...
}

通过key_frame判断是否为关键帧。或者 enum AVPictureType pict_type;也行。

AVPictureType的定义如下:

/**
 * @}
 * @}
 * @defgroup lavu_picture Image related
 *
 * AVPicture types, pixel formats and basic image planes manipulation.
 *
 * @{
 */

enum AVPictureType {
    AV_PICTURE_TYPE_NONE = 0, ///< Undefined
    AV_PICTURE_TYPE_I,     ///< Intra
    AV_PICTURE_TYPE_P,     ///< Predicted
    AV_PICTURE_TYPE_B,     ///< Bi-dir predicted
    AV_PICTURE_TYPE_S,     ///< S(GMC)-VOP MPEG-4
    AV_PICTURE_TYPE_SI,    ///< Switching Intra
    AV_PICTURE_TYPE_SP,    ///< Switching Predicted
    AV_PICTURE_TYPE_BI,    ///< BI type
};
AVFrame *decoded_frame;

int is_key_frame =       (decoded_frame->key_frame == 1)
                        || (decoded_frame->pict_type == AV_PICTURE_TYPE_I);

...

不过,感觉key_frame 好像不太准, AVPictureType pict_type感觉更准一些

你可能感兴趣的:(ffmpeg # 判断AVFrame是否为关键帧)