[FFmpeg-cvslog] lavc/vvc/refs: export keyframe and picture type in output frames
Nuo Mi
git at videolan.org
Mon Jan 13 23:14:24 EET 2025
ffmpeg | branch: master | Nuo Mi <nuomi2021 at gmail.com> | Sun Jan 12 11:34:17 2025 +0800| [8eb1d76e146a0e557d596a4039efebac746b4d83] | committer: James Almer
lavc/vvc/refs: export keyframe and picture type in output frames
fixes https://trac.ffmpeg.org/ticket/11406
Co-authored-by: Ruben Gonzalez <rgonzalez at fluendo.com>
Signed-off-by: James Almer <jamrial at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8eb1d76e146a0e557d596a4039efebac746b4d83
---
libavcodec/vvc/refs.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/libavcodec/vvc/refs.c b/libavcodec/vvc/refs.c
index bc3b3d0d13..79b692ac48 100644
--- a/libavcodec/vvc/refs.c
+++ b/libavcodec/vvc/refs.c
@@ -21,6 +21,7 @@
*/
#include <stdatomic.h>
+#include <stdbool.h>
#include "libavutil/mem.h"
#include "libavutil/thread.h"
@@ -168,6 +169,36 @@ fail:
return NULL;
}
+static void set_pict_type(AVFrame *frame, const VVCContext *s, const VVCFrameContext *fc)
+{
+ bool has_b = false, has_inter = false;
+
+ if (IS_IRAP(s)) {
+ frame->pict_type = AV_PICTURE_TYPE_I;
+ frame->flags |= AV_FRAME_FLAG_KEY;
+ return;
+ }
+
+ if (fc->ps.ph.r->ph_inter_slice_allowed_flag) {
+ // At this point, fc->slices is not fully initialized; we need to inspect the CBS directly.
+ const CodedBitstreamFragment *current = &s->current_frame;
+ for (int i = 0; i < current->nb_units && !has_b; i++) {
+ const CodedBitstreamUnit *unit = current->units + i;
+ if (unit->type <= VVC_RSV_IRAP_11) {
+ const H266RawSliceHeader *rsh = unit->content_ref;
+ has_inter |= !IS_I(rsh);
+ has_b |= IS_B(rsh);
+ }
+ }
+ }
+ if (!has_inter)
+ frame->pict_type = AV_PICTURE_TYPE_I;
+ else if (has_b)
+ frame->pict_type = AV_PICTURE_TYPE_B;
+ else
+ frame->pict_type = AV_PICTURE_TYPE_P;
+}
+
int ff_vvc_set_new_ref(VVCContext *s, VVCFrameContext *fc, AVFrame **frame)
{
const VVCPH *ph= &fc->ps.ph;
@@ -189,6 +220,7 @@ int ff_vvc_set_new_ref(VVCContext *s, VVCFrameContext *fc, AVFrame **frame)
if (!ref)
return AVERROR(ENOMEM);
+ set_pict_type(ref->frame, s, fc);
*frame = ref->frame;
fc->ref = ref;
More information about the ffmpeg-cvslog
mailing list