summaryrefslogtreecommitdiffstats
path: root/video/mp_image.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/mp_image.c')
-rw-r--r--video/mp_image.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/video/mp_image.c b/video/mp_image.c
index 57124eab11..72da838822 100644
--- a/video/mp_image.c
+++ b/video/mp_image.c
@@ -459,3 +459,31 @@ void mp_image_copy_fields_from_av_frame(struct mp_image *dst,
if (src->repeat_pict == 1)
dst->fields |= MP_IMGFIELD_REPEAT_FIRST;
}
+
+#if HAVE_AVUTIL_REFCOUNTING
+
+static void frame_free(void *p)
+{
+ AVFrame *frame = p;
+ av_frame_free(&frame);
+}
+
+static bool frame_is_unique(void *p)
+{
+ AVFrame *frame = p;
+ return av_frame_is_writable(frame);
+}
+
+// Create a new mp_image reference to av_frame.
+struct mp_image *mp_image_from_av_frame(struct AVFrame *av_frame)
+{
+ AVFrame *new_ref = av_frame_clone(av_frame);
+ if (!new_ref)
+ abort(); // OOM
+ struct mp_image t = {0};
+ mp_image_copy_fields_from_av_frame(&t, new_ref);
+ return mp_image_new_external_ref(&t, new_ref, NULL, NULL, frame_is_unique,
+ frame_free);
+}
+
+#endif /* HAVE_AVUTIL_REFCOUNTING */