FFmpeg
video_hint.h
Go to the documentation of this file.
1 /**
2  * Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVUTIL_VIDEO_HINT_H
22 #define AVUTIL_VIDEO_HINT_H
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 #include "libavutil/avassert.h"
27 #include "libavutil/frame.h"
28 
29 typedef struct AVVideoRect {
30  uint32_t x, y;
31  uint32_t width, height;
32 } AVVideoRect;
33 
34 typedef enum AVVideoHintType {
35  /* rectangled delimit the constant areas (unchanged), default is changed */
37 
38  /* rectangled delimit the constant areas (changed), default is not changed */
41 
42 typedef struct AVVideoHint {
43  /**
44  * Number of AVVideoRect present.
45  *
46  * May be 0, in which case no per-rectangle information is present. In this
47  * case the values of rect_offset / rect_size are unspecified and should
48  * not be accessed.
49  */
50  size_t nb_rects;
51 
52  /**
53  * Offset in bytes from the beginning of this structure at which the array
54  * of AVVideoRect starts.
55  */
56  size_t rect_offset;
57 
58  /**
59  * Size in bytes of AVVideoRect.
60  */
61  size_t rect_size;
62 
64 } AVVideoHint;
65 
68  return (AVVideoRect *)((uint8_t *)hints + hints->rect_offset);
69 }
70 
72 av_video_hint_get_rect(const AVVideoHint *hints, size_t idx) {
73  return (AVVideoRect *)((uint8_t *)hints + hints->rect_offset + idx * hints->rect_size);
74 }
75 
76 /**
77  * Allocate memory for the AVVideoHint struct along with an nb_rects-sized
78  * arrays of AVVideoRect.
79  *
80  * The side data contains a list of rectangles for the portions of the frame
81  * which changed from the last encoded one (and the remainder are assumed to be
82  * changed), or, alternately (depending on the type parameter) the unchanged
83  * ones (and the remanining ones are those which changed).
84  * Macroblocks will thus be hinted either to be P_SKIP-ped or go through the
85  * regular encoding procedure.
86  *
87  * It's responsibility of the caller to fill the AVRects accordingly, and to set
88  * the proper AVVideoHintType field.
89  *
90  * @param out_size if non-NULL, the size in bytes of the resulting data array is
91  * written here
92  *
93  * @return newly allocated AVVideoHint struct (must be freed by the caller using
94  * av_free()) on success, NULL on memory allocation failure
95  */
96 AVVideoHint *av_video_hint_alloc(size_t nb_rects,
97  size_t *out_size);
98 
99 /**
100  * Same as av_video_hint_alloc(), except newly-allocated AVVideoHint is attached
101  * as side data of type AV_FRAME_DATA_VIDEO_HINT_INFO to frame.
102  */
104  size_t nb_rects);
105 
106 
107 #endif /* AVUTIL_VIDEO_HINT_H */
out_size
int out_size
Definition: movenc.c:55
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVVideoRect
Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
Definition: video_hint.h:29
AVVideoRect::width
uint32_t width
Definition: video_hint.h:31
AVVideoHint::nb_rects
size_t nb_rects
Number of AVVideoRect present.
Definition: video_hint.h:50
AV_VIDEO_HINT_TYPE_CHANGED
@ AV_VIDEO_HINT_TYPE_CHANGED
Definition: video_hint.h:39
AVVideoRect::x
uint32_t x
Definition: video_hint.h:30
AVVideoHint
Definition: video_hint.h:42
AV_VIDEO_HINT_TYPE_CONSTANT
@ AV_VIDEO_HINT_TYPE_CONSTANT
Definition: video_hint.h:36
av_video_hint_rects
static av_always_inline AVVideoRect * av_video_hint_rects(const AVVideoHint *hints)
Definition: video_hint.h:67
AVVideoHintType
AVVideoHintType
Definition: video_hint.h:34
avassert.h
AVVideoRect::height
uint32_t height
Definition: video_hint.h:31
frame
static AVFrame * frame
Definition: demux_decode.c:54
AVVideoRect::y
uint32_t y
Definition: video_hint.h:30
AVVideoHint::rect_offset
size_t rect_offset
Offset in bytes from the beginning of this structure at which the array of AVVideoRect starts.
Definition: video_hint.h:56
AVVideoHint::rect_size
size_t rect_size
Size in bytes of AVVideoRect.
Definition: video_hint.h:61
frame.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
AVVideoHint::type
AVVideoHintType type
Definition: video_hint.h:63
av_video_hint_get_rect
static av_always_inline AVVideoRect * av_video_hint_get_rect(const AVVideoHint *hints, size_t idx)
Definition: video_hint.h:72
av_video_hint_alloc
AVVideoHint * av_video_hint_alloc(size_t nb_rects, size_t *out_size)
Allocate memory for the AVVideoHint struct along with an nb_rects-sized arrays of AVVideoRect.
Definition: video_hint.c:29
av_video_hint_create_side_data
AVVideoHint * av_video_hint_create_side_data(AVFrame *frame, size_t nb_rects)
Same as av_video_hint_alloc(), except newly-allocated AVVideoHint is attached as side data of type AV...
Definition: video_hint.c:58