1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 module ffmpeg.libavutil.video_enc_params;
19 
20 import ffmpeg.libavutil;
21 
22 extern (C) @nogc nothrow:
23 
24 enum AVVideoEncParamsType
25 {
26     AV_VIDEO_ENC_PARAMS_NONE = -1,
27     /**
28      * VP9 stores:
29      * - per-frame base (luma AC) quantizer index, exported as AVVideoEncParams.qp
30      * - deltas for luma DC, chroma AC and chroma DC, exported in the
31      *   corresponding entries in AVVideoEncParams.delta_qp
32      * - per-segment delta, exported as for each block as AVVideoBlockParams.delta_qp
33      *
34      * To compute the resulting quantizer index for a block:
35      * - for luma AC, add the base qp and the per-block delta_qp, saturating to
36      *   unsigned 8-bit.
37      * - for luma DC and chroma AC/DC, add the corresponding
38      *   AVVideoBlockParams.delta_qp to the luma AC index, again saturating to
39      *   unsigned 8-bit.
40      */
41     AV_VIDEO_ENC_PARAMS_VP9 = 0,
42 
43     /**
44      * H.264 stores:
45      * - in PPS (per-picture):
46      *   * initial QP_Y (luma) value, exported as AVVideoEncParams.qp
47      *   * delta(s) for chroma QP values (same for both, or each separately),
48      *     exported as in the corresponding entries in AVVideoEncParams.delta_qp
49      * - per-slice QP delta, not exported directly, added to the per-MB value
50      * - per-MB delta; not exported directly; the final per-MB quantizer
51      *   parameter - QP_Y - minus the value in AVVideoEncParams.qp is exported
52      *   as AVVideoBlockParams.qp_delta.
53      */
54     AV_VIDEO_ENC_PARAMS_H264 = 1,
55 
56     /*
57      * MPEG-2-compatible quantizer.
58      *
59      * Summing the frame-level qp with the per-block delta_qp gives the
60      * resulting quantizer for the block.
61      */
62     AV_VIDEO_ENC_PARAMS_MPEG2 = 2
63 }
64 
65 /**
66  * Video encoding parameters for a given frame. This struct is allocated along
67  * with an optional array of per-block AVVideoBlockParams descriptors.
68  * Must be allocated with av_video_enc_params_alloc().
69  */
70 struct AVVideoEncParams
71 {
72     /**
73      * Number of blocks in the array.
74      *
75      * May be 0, in which case no per-block information is present. In this case
76      * the values of blocks_offset / block_size are unspecified and should not
77      * be accessed.
78      */
79     uint nb_blocks;
80     /**
81      * Offset in bytes from the beginning of this structure at which the array
82      * of blocks starts.
83      */
84     size_t blocks_offset;
85     /*
86      * Size of each block in bytes. May not match sizeof(AVVideoBlockParams).
87      */
88     size_t block_size;
89 
90     /**
91      * Type of the parameters (the codec they are used with).
92      */
93     AVVideoEncParamsType type;
94 
95     /**
96      * Base quantisation parameter for the frame. The final quantiser for a
97      * given block in a given plane is obtained from this value, possibly
98      * combined with {@code delta_qp} and the per-block delta in a manner
99      * documented for each type.
100      */
101     int qp;
102 
103     /**
104      * Quantisation parameter offset from the base (per-frame) qp for a given
105      * plane (first index) and AC/DC coefficients (second index).
106      */
107     int[2][4] delta_qp;
108 }
109 
110 /**
111  * Data structure for storing block-level encoding information.
112  * It is allocated as a part of AVVideoEncParams and should be retrieved with
113  * av_video_enc_params_block().
114  *
115  * sizeof(AVVideoBlockParams) is not a part of the ABI and new fields may be
116  * added to it.
117  */
118 struct AVVideoBlockParams
119 {
120     /**
121      * Distance in luma pixels from the top-left corner of the visible frame
122      * to the top-left corner of the block.
123      * Can be negative if top/right padding is present on the coded frame.
124      */
125     int src_x;
126     int src_y;
127     /**
128      * Width and height of the block in luma pixels.
129      */
130     int w;
131     int h;
132 
133     /**
134      * Difference between this block's final quantization parameter and the
135      * corresponding per-frame value.
136      */
137     int delta_qp;
138 }
139 
140 /*
141  * Get the block at the specified {@code idx}. Must be between 0 and nb_blocks.
142  */
143 AVVideoBlockParams* av_video_enc_params_block (AVVideoEncParams* par, uint idx);
144 
145 /**
146  * Allocates memory for AVVideoEncParams of the given type, plus an array of
147  * {@code nb_blocks} AVVideoBlockParams and initializes the variables. Can be
148  * freed with a normal av_free() call.
149  *
150  * @param out_size if non-NULL, the size in bytes of the resulting data array is
151  * written here.
152  */
153 AVVideoEncParams* av_video_enc_params_alloc (
154     AVVideoEncParamsType type,
155     uint nb_blocks,
156     size_t* out_size);
157 
158 /**
159  * Allocates memory for AVEncodeInfoFrame plus an array of
160  * {@code nb_blocks} AVEncodeInfoBlock in the given AVFrame {@code frame}
161  * as AVFrameSideData of type AV_FRAME_DATA_VIDEO_ENC_PARAMS
162  * and initializes the variables.
163  */
164 AVVideoEncParams* av_video_enc_params_create_side_data (
165     AVFrame* frame,
166     AVVideoEncParamsType type,
167     uint nb_blocks);
168 
169 /* AVUTIL_VIDEO_ENC_PARAMS_H */