aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/h264dec.c
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2021-08-17 21:25:31 +0200
committerJames Almer <jamrial@gmail.com>2021-08-24 09:58:52 -0300
commitcf37c3fb6c84d8eb61079520b4c57e3c969bc25d (patch)
treed449ba2158a00e4f606f1ce9faea50811ee32086 /libavcodec/h264dec.c
parent61b38f7aef8d2f34135eb6a1e1e637d4fef667d2 (diff)
downloadffmpeg-cf37c3fb6c84d8eb61079520b4c57e3c969bc25d.tar.gz
avcodec/h264_slice: compute and export film grain seed
From SMPTE RDD 5-2006, the grain seed is to be computed from the following definition of `pic_offset`: > When decoding H.264 | MPEG-4 AVC bitstreams, pic_offset is defined as > follows: > - pic_offset = PicOrderCnt(CurrPic) + (PicOrderCnt_offset << 5) > where: > - PicOrderCnt(CurrPic) is the picture order count of the current frame, > which shall be derived from [the video stream]. > > - PicOrderCnt_offset is set to idr_pic_id on IDR frames. idr_pic_id > shall be read from the slice header of [the video stream]. On non-IDR I > frames, PicOrderCnt_offset is set to 0. A frame shall be classified as I > frame when all its slices are I slices, which may be optionally > designated by setting primary_pic_type to 0 in the access delimiter NAL > unit. Otherwise, PicOrderCnt_offset it not changed. PicOrderCnt_offset is > updated in decoding order. Co-authored-by: James Almer <jamrial@gmail.com> Signed-off-by: Niklas Haas <git@haasn.dev> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/h264dec.c')
-rw-r--r--libavcodec/h264dec.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 07ff9110d2..f46d29baa6 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -485,6 +485,8 @@ static void h264_decode_flush(AVCodecContext *avctx)
static int get_last_needed_nal(H264Context *h)
{
int nals_needed = 0;
+ int slice_type = 0;
+ int picture_intra_only = 1;
int first_slice = 0;
int i, ret;
@@ -516,11 +518,23 @@ static int get_last_needed_nal(H264Context *h)
!first_slice ||
first_slice != nal->type)
nals_needed = i;
+ slice_type = get_ue_golomb_31(&gb);
+ if (slice_type > 9) {
+ if (h->avctx->err_recognition & AV_EF_EXPLODE)
+ return AVERROR_INVALIDDATA;
+ }
+ if (slice_type > 4)
+ slice_type -= 5;
+
+ slice_type = ff_h264_golomb_to_pict_type[slice_type];
+ picture_intra_only &= (slice_type & 3) == AV_PICTURE_TYPE_I;
if (!first_slice)
first_slice = nal->type;
}
}
+ h->picture_intra_only = picture_intra_only;
+
return nals_needed;
}