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 Dec 14, 2022
1 parent 587bde3 commit 96da5fb
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 @@ -255,6 +255,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 @@ -322,9 +324,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 @@ -346,7 +350,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 96da5fb

Please sign in to comment.