Skip to content

Commit

Permalink
libavcodec/h264_parser.c: treat an I frame as rap if SPS&PPS proceeds it
Browse files Browse the repository at this point in the history
Hopefully, this should fix AkarinVS/L-SMASH-Works#24.

Signed-off-by: akarin <i@akarin.info>
  • Loading branch information
AkarinVS committed Apr 14, 2022
1 parent 3b8d7ff commit 9b1350c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libavcodec/h264_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ static inline int parse_nal_units(AVCodecParserContext *s,
int field_poc[2];
int ret;

int has_sps = 0, has_pps = 0;

/* set some sane default values */
s->pict_type = AV_PICTURE_TYPE_I;
s->key_frame = 0;
Expand Down Expand Up @@ -325,9 +327,11 @@ static inline int parse_nal_units(AVCodecParserContext *s,

switch (nal.type) {
case H264_NAL_SPS:
has_sps = 1;
ff_h264_decode_seq_parameter_set(&nal.gb, avctx, &p->ps, 0);
break;
case H264_NAL_PPS:
has_pps = 1;
ff_h264_decode_picture_parameter_set(&nal.gb, avctx, &p->ps,
nal.size_bits);
break;
Expand All @@ -349,7 +353,11 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if (p->sei.recovery_point.recovery_frame_cnt >= 0) {
/* key frame, since recovery_frame_cnt is set */
/* Some incorrectly encoded m2ts contains SEI recovery point labeled non-IDR I-slices */
if (s->key_frame) s->key_frame = 2;
if (s->key_frame ||
/* Unfortunately, not all streams use H264_NAL_IDR_SLICE, so instead we also see
if SPS&PPS are present before the I slice. */
(s->pict_type == AV_PICTURE_TYPE_I && has_sps && has_pps))
s->key_frame = 2;
}
pps_id = get_ue_golomb(&nal.gb);
if (pps_id >= MAX_PPS_COUNT) {
Expand Down

0 comments on commit 9b1350c

Please sign in to comment.