aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/video_hint.c
diff options
context:
space:
mode:
authorElias Carotti <eliascrt _at_ amazon _dot_ it>2023-07-10 14:34:53 +0200
committerStefano Sabatini <stefasab@gmail.com>2023-08-08 09:46:11 +0200
commit5012b4ab4ca65a1c71bbcc125ba39db074b94e70 (patch)
tree93e0c0507756486bb9830cd7a79110b06c59fde1 /libavutil/video_hint.c
parentc0709706ddda0d1f079d4020047bcdeb0bc4a7f1 (diff)
downloadffmpeg-5012b4ab4ca65a1c71bbcc125ba39db074b94e70.tar.gz
lavu: add video_hint API
Add side data type to provide hint to the video encoders about unchanged portions of each frame. Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavutil/video_hint.c')
-rw-r--r--libavutil/video_hint.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/libavutil/video_hint.c b/libavutil/video_hint.c
new file mode 100644
index 0000000000..431716ab67
--- /dev/null
+++ b/libavutil/video_hint.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <string.h>
+
+#include "avstring.h"
+#include "frame.h"
+#include "macros.h"
+#include "mem.h"
+#include "video_hint.h"
+
+AVVideoHint *av_video_hint_alloc(size_t nb_rects,
+ size_t *out_size)
+{
+ struct TestStruct {
+ AVVideoHint hint;
+ AVVideoRect rect;
+ };
+ const size_t rect_offset = offsetof(struct TestStruct, rect);
+ size_t size = rect_offset;
+ AVVideoHint *hint;
+
+ *out_size = 0;
+ if (nb_rects > (SIZE_MAX - size) / sizeof(AVVideoRect))
+ return NULL;
+ size += sizeof(AVVideoRect) * nb_rects;
+
+ hint = av_mallocz(size);
+ if (!hint)
+ return NULL;
+
+ hint->nb_rects = nb_rects;
+ hint->rect_offset = rect_offset;
+ hint->rect_size = sizeof(AVVideoRect);
+
+ *out_size = size;
+
+ return hint;
+}
+
+AVVideoHint *av_video_hint_create_side_data(AVFrame *frame,
+ size_t nb_rects)
+{
+ AVVideoHint *hint;
+ AVBufferRef *buf;
+ size_t size = 0;
+
+ hint = av_video_hint_alloc(nb_rects, &size);
+ if (!hint)
+ return NULL;
+
+ buf = av_buffer_create((uint8_t *)hint, size, NULL, NULL, 0);
+ if (!buf) {
+ av_freep(&hint);
+ return NULL;
+ }
+
+ if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_VIDEO_HINT, buf)) {
+ av_buffer_unref(&buf);
+ return NULL;
+ }
+
+ return hint;
+}