Skip to content

Commit 8eb1d76

Browse files
nuomi2021rgonzalezfluendo
authored andcommitted
lavc/vvc/refs: export keyframe and picture type in output frames
fixes https://trac.ffmpeg.org/ticket/11406 Co-authored-by: Ruben Gonzalez <[email protected]> Signed-off-by: James Almer <[email protected]>
1 parent d5873be commit 8eb1d76

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

libavcodec/vvc/refs.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#include <stdatomic.h>
24+
#include <stdbool.h>
2425

2526
#include "libavutil/mem.h"
2627
#include "libavutil/thread.h"
@@ -168,6 +169,36 @@ static VVCFrame *alloc_frame(VVCContext *s, VVCFrameContext *fc)
168169
return NULL;
169170
}
170171

172+
static void set_pict_type(AVFrame *frame, const VVCContext *s, const VVCFrameContext *fc)
173+
{
174+
bool has_b = false, has_inter = false;
175+
176+
if (IS_IRAP(s)) {
177+
frame->pict_type = AV_PICTURE_TYPE_I;
178+
frame->flags |= AV_FRAME_FLAG_KEY;
179+
return;
180+
}
181+
182+
if (fc->ps.ph.r->ph_inter_slice_allowed_flag) {
183+
// At this point, fc->slices is not fully initialized; we need to inspect the CBS directly.
184+
const CodedBitstreamFragment *current = &s->current_frame;
185+
for (int i = 0; i < current->nb_units && !has_b; i++) {
186+
const CodedBitstreamUnit *unit = current->units + i;
187+
if (unit->type <= VVC_RSV_IRAP_11) {
188+
const H266RawSliceHeader *rsh = unit->content_ref;
189+
has_inter |= !IS_I(rsh);
190+
has_b |= IS_B(rsh);
191+
}
192+
}
193+
}
194+
if (!has_inter)
195+
frame->pict_type = AV_PICTURE_TYPE_I;
196+
else if (has_b)
197+
frame->pict_type = AV_PICTURE_TYPE_B;
198+
else
199+
frame->pict_type = AV_PICTURE_TYPE_P;
200+
}
201+
171202
int ff_vvc_set_new_ref(VVCContext *s, VVCFrameContext *fc, AVFrame **frame)
172203
{
173204
const VVCPH *ph= &fc->ps.ph;
@@ -189,6 +220,7 @@ int ff_vvc_set_new_ref(VVCContext *s, VVCFrameContext *fc, AVFrame **frame)
189220
if (!ref)
190221
return AVERROR(ENOMEM);
191222

223+
set_pict_type(ref->frame, s, fc);
192224
*frame = ref->frame;
193225
fc->ref = ref;
194226

0 commit comments

Comments
 (0)