@revizly/sharp-libvips-dev 1.0.34 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1137 @@
1
+ /*
2
+ * Copyright(c) 2019 Intel Corporation
3
+ *
4
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and
5
+ * the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License
6
+ * was not distributed with this source code in the LICENSE file, you can
7
+ * obtain it at https://www.aomedia.org/license. If the Alliance for Open
8
+ * Media Patent License 1.0 was not distributed with this source code in the
9
+ * PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
10
+ */
11
+
12
+ #ifndef EbSvtAv1Enc_h
13
+ #define EbSvtAv1Enc_h
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif // __cplusplus
18
+
19
+ #include <stdint.h>
20
+ #include "EbSvtAv1.h"
21
+ #include <stdlib.h>
22
+ #include <stdarg.h>
23
+ #include <stdio.h>
24
+ #include <stdbool.h>
25
+ /**
26
+ * @brief SVT-AV1 encoder ABI version
27
+ *
28
+ * Should be increased by 1 everytime a public struct in the encoder
29
+ * has been modified, and reset anytime the major API version has
30
+ * been changed. Used to keep track if a field has been added or not.
31
+ */
32
+ #define SVT_AV1_ENC_ABI_VERSION 0
33
+ #define HIERARCHICAL_LEVELS_AUTO ((uint32_t)(~0))
34
+ #define MAX_HIERARCHICAL_LEVEL 6
35
+ #define REF_LIST_MAX_DEPTH 4
36
+ /*!\brief Decorator indicating that given struct/union/enum is packed */
37
+ #ifndef ATTRIBUTE_PACKED
38
+ #if defined(__GNUC__) && __GNUC__
39
+ #define ATTRIBUTE_PACKED __attribute__((packed))
40
+ #else
41
+ #define ATTRIBUTE_PACKED
42
+ #endif
43
+ #endif /* ATTRIBUTE_PACKED */
44
+ typedef enum ATTRIBUTE_PACKED {
45
+ ENC_MR = -1, //Research mode with higher quality than M0
46
+ ENC_M0 = 0,
47
+ ENC_M1 = 1,
48
+ ENC_M2 = 2,
49
+ ENC_M3 = 3,
50
+ ENC_M4 = 4,
51
+ ENC_M5 = 5,
52
+ ENC_M6 = 6,
53
+ ENC_M7 = 7,
54
+ ENC_M8 = 8,
55
+ ENC_M9 = 9,
56
+ ENC_M10 = 10,
57
+ ENC_M11 = 11,
58
+ ENC_M12 = 12,
59
+ ENC_M13 = 13,
60
+ MAX_ENC_PRESET = ENC_M13
61
+ } EncMode;
62
+
63
+ #define DEFAULT -1
64
+
65
+ #define EB_BUFFERFLAG_EOS 0x00000001 // signals the last packet of the stream
66
+ #define EB_BUFFERFLAG_SHOW_EXT 0x00000002 // signals that the packet contains a show existing frame at the end
67
+ #define EB_BUFFERFLAG_HAS_TD 0x00000004 // signals that the packet contains a TD
68
+ #define EB_BUFFERFLAG_IS_ALT_REF 0x00000008 // signals that the packet contains an ALT_REF frame
69
+ #define EB_BUFFERFLAG_ERROR_MASK \
70
+ 0xFFFFFFF0 // mask for signalling error assuming top flags fit in 4 bits. To be changed, if more flags are added.
71
+
72
+ /*
73
+ * Struct for storing content light level information
74
+ * Values are stored in BE format
75
+ * Refer to the AV1 specification 6.7.3 for more details
76
+ */
77
+ struct EbContentLightLevel {
78
+ uint16_t max_cll;
79
+ uint16_t max_fall;
80
+ };
81
+
82
+ /*
83
+ * Struct for storing x and y chroma points, values are stored in BE format
84
+ */
85
+ struct EbSvtAv1ChromaPoints {
86
+ uint16_t x;
87
+ uint16_t y;
88
+ };
89
+
90
+ /*
91
+ * Struct for storing mastering-display information
92
+ * values are stored in BE format
93
+ * Refer to the AV1 specification 6.7.4 for more details
94
+ */
95
+ struct EbSvtAv1MasteringDisplayInfo {
96
+ struct EbSvtAv1ChromaPoints r;
97
+ struct EbSvtAv1ChromaPoints g;
98
+ struct EbSvtAv1ChromaPoints b;
99
+ struct EbSvtAv1ChromaPoints white_point;
100
+ uint32_t max_luma;
101
+ uint32_t min_luma;
102
+ };
103
+
104
+ // super-res modes
105
+ typedef enum {
106
+ SUPERRES_NONE, // No frame superres allowed.
107
+ SUPERRES_FIXED, // All frames are coded at the specified scale, and super-resolved.
108
+ SUPERRES_RANDOM, // All frames are coded at a random scale, and super-resolved.
109
+ SUPERRES_QTHRESH, // Superres scale for a frame is determined based on q_index.
110
+ SUPERRES_AUTO, // Automatically select superres for appropriate frames.
111
+ SUPERRES_MODES
112
+ } SUPERRES_MODE;
113
+
114
+ // super-res auto search type
115
+ typedef enum {
116
+ SUPERRES_AUTO_ALL, // Tries all possible superres ratios
117
+ SUPERRES_AUTO_DUAL, // Tries no superres and q-based superres ratios
118
+ SUPERRES_AUTO_SOLO, // Only apply the q-based superres ratio
119
+ SUPERRES_AUTO_SEARCH_TYPES
120
+ } SUPERRES_AUTO_SEARCH_TYPE;
121
+
122
+ // reference scaling modes
123
+ typedef enum {
124
+ RESIZE_NONE, // No frame resize allowed.
125
+ RESIZE_FIXED, // All frames are coded at the specified scale.
126
+ RESIZE_RANDOM, // All frames are coded at a random scale.
127
+ RESIZE_DYNAMIC, // Resize scale for a frame in dynamic.
128
+ RESIZE_RANDOM_ACCESS, // Resize scale frame by event in random access
129
+ RESIZE_MODES
130
+ } RESIZE_MODE;
131
+
132
+ /* Indicates what prediction structure to use
133
+ */
134
+ typedef enum PredStructure { ALL_INTRA, LOW_DELAY, RANDOM_ACCESS, PRED_TOTAL_COUNT, PRED_INVALID = 0xFF } PredStructure;
135
+
136
+ /** The SvtAv1IntraRefreshType is used to describe the intra refresh type.
137
+ */
138
+ typedef enum SvtAv1IntraRefreshType {
139
+ SVT_AV1_FWDKF_REFRESH = 1,
140
+ SVT_AV1_KF_REFRESH = 2,
141
+ } SvtAv1IntraRefreshType;
142
+
143
+ typedef enum {
144
+ SVT_AV1_STREAM_INFO_START = 1,
145
+ SVT_AV1_STREAM_INFO_FIRST_PASS_STATS_OUT = SVT_AV1_STREAM_INFO_START,
146
+
147
+ SVT_AV1_STREAM_INFO_END,
148
+ } SVT_AV1_STREAM_INFO_ID;
149
+
150
+ /*!\brief Generic fixed size buffer structure
151
+ *
152
+ * This structure is able to hold a reference to any fixed size buffer.
153
+ */
154
+ typedef struct SvtAv1FixedBuf {
155
+ void* buf; /**< Pointer to the data. Does NOT own the data! */
156
+ uint64_t sz; /**< Length of the buffer, in chars */
157
+ } SvtAv1FixedBuf; /**< alias for struct aom_fixed_buf */
158
+
159
+ /** Indicates how an S-Frame should be inserted.
160
+ */
161
+ typedef enum EbSFrameMode {
162
+ SFRAME_STRICT_BASE =
163
+ 1, /**< The considered frame will be made into an S-Frame only if it is a base layer inter frame */
164
+ SFRAME_NEAREST_BASE =
165
+ 2, /**< If the considered frame is not an altref frame, the next base layer inter frame will be made into an S-Frame */
166
+ SFRAME_FLEXIBLE_BASE =
167
+ 3, /**< If the considered frame is not an altref frame, modify the miniGOP layers to make the considered frame as an altref frame, then it will be made into an S-Frame */
168
+ SFRAME_DEC_POSI_BASE =
169
+ 4, /**< If the considered frame in decode order is not an altref frame, modify the mini-GOP structure to promote its previous frame to an altref frame, and set the next altref to an S-Frame */
170
+ } EbSFrameMode;
171
+
172
+ /* Indicates what rate control mode is used.
173
+ * Currently, cqp is distinguised by setting aq_mode to 0
174
+ */
175
+ typedef enum SvtAv1RcMode {
176
+ SVT_AV1_RC_MODE_CQP_OR_CRF = 0, // constant quantization parameter/constant rate factor
177
+ SVT_AV1_RC_MODE_VBR = 1, // variable bit rate
178
+ SVT_AV1_RC_MODE_CBR = 2, // constant bit rate
179
+ } SvtAv1RcMode;
180
+
181
+ typedef enum SvtAv1FrameUpdateType {
182
+ SVT_AV1_KF_UPDATE,
183
+ SVT_AV1_LF_UPDATE,
184
+ SVT_AV1_GF_UPDATE,
185
+ SVT_AV1_ARF_UPDATE,
186
+ SVT_AV1_OVERLAY_UPDATE,
187
+ SVT_AV1_INTNL_OVERLAY_UPDATE, // Internal Overlay Frame
188
+ SVT_AV1_INTNL_ARF_UPDATE, // Internal Altref Frame
189
+ SVT_AV1_FRAME_UPDATE_TYPES
190
+ } SvtAv1FrameUpdateType;
191
+
192
+ typedef struct SvtAv1FrameScaleEvts {
193
+ uint32_t evt_num;
194
+ uint64_t* start_frame_nums;
195
+ uint32_t* resize_kf_denoms;
196
+ uint32_t* resize_denoms;
197
+ } SvtAv1FrameScaleEvts;
198
+
199
+ typedef struct SvtAv1SFramePositions {
200
+ uint32_t sframe_num;
201
+ uint64_t* sframe_posis;
202
+ uint32_t sframe_qp_num;
203
+ uint8_t* sframe_qps;
204
+ int8_t* sframe_qp_offsets;
205
+ } SvtAv1SFramePositions;
206
+
207
+ // Will contain the EbEncApi which will live in the EncHandle class
208
+ // Only modifiable during config-time.
209
+ typedef struct EbSvtAv1EncConfiguration {
210
+ /**
211
+ * @brief Encoder preset used.
212
+ * -2 and -1 are for debug purposes and should not be used.
213
+ * 0 is the highest quality mode but is the slowest,
214
+ * 13 is the fastest mode but is not as high quality.
215
+ *
216
+ * Min value is -2.
217
+ * Max value is 13.
218
+ * Default is 12.
219
+ */
220
+ int8_t enc_mode;
221
+
222
+ // GOP Structure
223
+
224
+ /* The intra period defines the interval of frames after which you insert an
225
+ * Intra refresh. It is strongly recommended to set the value to multiple of
226
+ * 2^(hierarchical_levels), subtracting one if using open GOP (intra_refresh_type == 1).
227
+ * For instance, to get a 5-second GOP (default being >=5 seconds)
228
+ * with hierarchical_levels = 3 and open GOP you could use 319, 279, 159
229
+ * for 60, 50, or 30 respectively.
230
+ *
231
+ * -1 = no intra update.
232
+ * -2 = auto.
233
+ *
234
+ * Default is -2. */
235
+ int32_t intra_period_length;
236
+
237
+ /* Random access.
238
+ *
239
+ * 1 = CRA, open GOP.
240
+ * 2 = IDR, closed GOP.
241
+ *
242
+ * Default is 1. */
243
+ SvtAv1IntraRefreshType intra_refresh_type;
244
+ /* Number of hierarchical layers used to construct GOP.
245
+ * Minigop size = 2^HierarchicalLevels.
246
+ *
247
+ * Default is auto */
248
+ uint32_t hierarchical_levels;
249
+ /* Prediction structure used to construct GOP. There are two main structures
250
+ * supported, which are: Low Delay and Random Access.
251
+ *
252
+ * In Low Delay structure, pictures within a mini GOP refer to the previously
253
+ * encoded pictures in display order. In other words, pictures with display
254
+ * order N can only be referenced by pictures with display order greater than
255
+ * N, and it can only refer pictures with picture order lower than N.
256
+ *
257
+ * In Random Access structure, the B/b pictures can refer to reference pictures
258
+ * from both directions (past and future).
259
+ *
260
+ * Refer to PredStructure enum for valid values.
261
+ *
262
+ * Default is RANDOM_ACCESS. */
263
+ PredStructure pred_structure;
264
+
265
+ // Input Info
266
+
267
+ /**
268
+ * @brief Frame width in pixels.
269
+ *
270
+ * Min is 64.
271
+ * Max is 16384.
272
+ * Default is 0.
273
+ */
274
+ uint32_t source_width;
275
+
276
+ /**
277
+ * @brief Frame height in pixels
278
+ *
279
+ * Min is 64.
280
+ * Max is 8704.
281
+ * Default is 0.
282
+ */
283
+ uint32_t source_height;
284
+
285
+ /* Specifies the maximum frame width/height for the frames represented by the sequence header
286
+ * (max_frame_width_minus_1 and max_frame_height_minus_1, spec 5.5.1).
287
+ * Actual frame height could be equal to or less than this value. E.g. Use this value to indicate
288
+ * the maximum height between renditions when switch frame feature is on.
289
+ */
290
+ uint32_t forced_max_frame_width;
291
+ uint32_t forced_max_frame_height;
292
+ /* Frame rate numerator. When zero, the encoder will use -fps if
293
+ * FrameRateDenominator is also zero, otherwise an error is returned.
294
+ *
295
+ * Default is 0. */
296
+ uint32_t frame_rate_numerator;
297
+ /* Frame rate denominator. When zero, the encoder will use -fps if
298
+ * FrameRateNumerator is also zero, otherwise an error is returned.
299
+ *
300
+ * Default is 0. */
301
+ uint32_t frame_rate_denominator;
302
+ /* Specifies the bit depth of input video.
303
+ *
304
+ * 8 = 8 bit.
305
+ * 10 = 10 bit.
306
+ *
307
+ * Default is 8. */
308
+ uint32_t encoder_bit_depth;
309
+
310
+ /**
311
+ * @brief Encoder color format.
312
+ * Only YUV420 is supported for now.
313
+ *
314
+ * Min is YUV400.
315
+ * Max is YUV444.
316
+ * Default is YUV420.
317
+ */
318
+ EbColorFormat encoder_color_format;
319
+ /**
320
+ * @brief Bitstream profile to use.
321
+ * 0: main, 1: high, 2: professional.
322
+ *
323
+ * Min is MAIN_PROFILE.
324
+ * Max is PROFESSIONAL_PROFILE.
325
+ * Default is MAIN_PROFILE.
326
+ */
327
+ EbAv1SeqProfile profile;
328
+ /* Constraints for bitstream in terms of max bitrate and max buffer size.
329
+ *
330
+ * 0 = Main, for most applications.
331
+ * 1 = High, for demanding applications.
332
+ *
333
+ * Default is 0. */
334
+ uint32_t tier;
335
+ /**
336
+ * @brief Bitstream level.
337
+ * 0: autodetect from bitstream, 20: level 2.0, 63: level 6.3, only levels 2.0-6.3 are properly defined.
338
+ * The levels are defined at https://aomediacodec.github.io/av1-spec/av1-spec.pdf
339
+ * under "A.3. Levels".
340
+ *
341
+ * Min is 0.
342
+ * Max is 73.
343
+ * Default is 0.
344
+ */
345
+ uint32_t level;
346
+ /* Color primaries
347
+ * values are from EbColorPrimaries
348
+ Default is 2 (CP_UNSPECIFIED). */
349
+ EbColorPrimaries color_primaries;
350
+ /* Transfer characteristics
351
+ * values are from EbTransferCharacteristics
352
+ Default is 2 (TC_UNSPECIFIED). */
353
+ EbTransferCharacteristics transfer_characteristics;
354
+ /* Matrix coefficients
355
+ * values are from EbMatrixCoefficients
356
+ Default is 2 (MC_UNSPECIFIED). */
357
+ EbMatrixCoefficients matrix_coefficients;
358
+ /* Color range
359
+ * values are from EbColorRange
360
+ * 0: studio swing.
361
+ * 1: full swing.
362
+ Default is 0. */
363
+ EbColorRange color_range;
364
+ /* Mastering display metadata
365
+ * values are from set using svt_aom_parse_mastering_display()
366
+ */
367
+ struct EbSvtAv1MasteringDisplayInfo mastering_display;
368
+ /* Content light level
369
+ * values are from set using svt_aom_parse_content_light_level()
370
+ */
371
+ struct EbContentLightLevel content_light_level;
372
+
373
+ /* Chroma sample position
374
+ * Values as per 6.4.2 of the specification:
375
+ * EB_CSP_UNKNOWN: default
376
+ * EB_CSP_VERTICAL: value 0 from H.273 AKA "left"
377
+ * EB_CSP_COLOCATED: value 2 from H.273 AKA "top left"
378
+ */
379
+ EbChromaSamplePosition chroma_sample_position;
380
+
381
+ // End input info
382
+
383
+ /* Rate control mode.
384
+ *
385
+ * Refer to the SvtAv1RcMode enum for valid values
386
+ * Default is 0. */
387
+ uint8_t rate_control_mode;
388
+ // Rate control tuning
389
+
390
+ // Quantization
391
+ /* Initial quantization parameter for the Intra pictures used under constant
392
+ * qp rate control mode.
393
+ *
394
+ * Default is 50. */
395
+ uint32_t qp;
396
+
397
+ /* force qp values for every picture that are passed in the header pointer
398
+ *
399
+ * Default is 0.*/
400
+ bool use_qp_file;
401
+ /* Target bitrate in bits/second, only applicable when rate control mode is
402
+ * set to 1 (VBR) or 2 (CBR).
403
+ *
404
+ * Default is 2000513. */
405
+ uint32_t target_bit_rate;
406
+ /* maximum bitrate in bits/second, only apllicable when rate control mode is
407
+ * set to 0.
408
+ *
409
+ * Default is 0. */
410
+ uint32_t max_bit_rate;
411
+ /* Maxium QP value
412
+ * Default is 63. */
413
+ uint32_t max_qp_allowed;
414
+ /* Minimum QP value
415
+ * Default is auto. */
416
+ uint32_t min_qp_allowed;
417
+ /**
418
+ * @brief Variable Bit Rate Minimum Section Percentage
419
+ *
420
+ * Indicates the minimum bitrate to be used for a single GOP as a percentage
421
+ * of the target bitrate.
422
+ *
423
+ * Min is 0.
424
+ * Max is 100.
425
+ * Default is 0.
426
+ */
427
+ uint32_t vbr_min_section_pct;
428
+
429
+ /**
430
+ * @brief Variable Bit Rate Maximum Section Percentage
431
+ *
432
+ * Indicates the maximum bitrate to be used for a single GOP as a percentage
433
+ * of the target bitrate.
434
+ *
435
+ * Min is 0.
436
+ * Max is 10000.
437
+ * Default is 2000.
438
+ */
439
+ uint32_t vbr_max_section_pct;
440
+
441
+ /**
442
+ * @brief UnderShoot Percentage
443
+ *
444
+ * Only applicable for VBR and CBR.
445
+ *
446
+ * Indicates the tolerance of the VBR algorithm to undershoot and is used
447
+ * as a trigger threshold for more agressive adaptation of Quantization.
448
+ *
449
+ * Min is 0.
450
+ * Max is 100.
451
+ * Default is 25 for CBR and 50 for VBR.
452
+ */
453
+ uint32_t under_shoot_pct;
454
+
455
+ /**
456
+ * @brief OverShoot Percentage
457
+ *
458
+ * Only applicable for VBR and CBR
459
+ *
460
+ * Indicates the tolerance of the VBR algorithm to overshoot and is used as
461
+ * a trigger threshold for more agressive adaptation of Quantization.
462
+ *
463
+ * Min is 0.
464
+ * Max is 100.
465
+ * Default is 25.
466
+ */
467
+ uint32_t over_shoot_pct;
468
+
469
+ /**
470
+ * @brief MaxBitRate OverShoot Percentage
471
+ *
472
+ * Only applicable for Capped CRF.
473
+ *
474
+ * Indicates the tolerance of the Capped CRF algorithm to overshoot
475
+ * and is used as a trigger threshold for more agressive adaptation of
476
+ * Quantization.
477
+ *
478
+ * Min is 0.
479
+ * Max is 100.
480
+ * Default is 50.
481
+ */
482
+ uint32_t mbr_over_shoot_pct;
483
+
484
+ /**
485
+ * @brief Starting Buffer Level in MilliSeconds
486
+ *
487
+ * Only applicable for CBR.
488
+ *
489
+ * Indicates the amount of data that will be buffered by the decoding
490
+ * application prior to beginning playback, and is expressed in units of
491
+ * time. Must be less than maximum_buffer_size_ms.
492
+ *
493
+ * Min is 20.
494
+ * Max is 10000.
495
+ * Default is 600.
496
+ */
497
+ int64_t starting_buffer_level_ms;
498
+
499
+ /**
500
+ * @brief Optimal Buffer Level in MilliSeconds
501
+ *
502
+ * Only applicable for CBR.
503
+ *
504
+ * indicates the amount of data that the encoder should try to maintain in the
505
+ * decoder's buffer, and is expressed in units of time. Must be less than
506
+ * maximum_buffer_size_ms.
507
+ *
508
+ * Min is 20.
509
+ * Max is 10000.
510
+ * Default is 600.
511
+ */
512
+ int64_t optimal_buffer_level_ms;
513
+
514
+ /**
515
+ * @brief Maximum Buffer Size in MilliSeconds
516
+ *
517
+ * Only applicable for CBR.
518
+ *
519
+ * indicates the maximum amount of data that may be buffered by the
520
+ * decoding application, and is expressed in units of time.
521
+ *
522
+ * Min is 20.
523
+ * Max is 10000.
524
+ * Default is 1000.
525
+ */
526
+ int64_t maximum_buffer_size_ms;
527
+
528
+ // input / output buffer to be used for multi-pass encoding
529
+ SvtAv1FixedBuf rc_stats_buffer;
530
+ int pass;
531
+
532
+ // End rate control tuning
533
+
534
+ // Individual tuning flags
535
+ /* use fixed qp offset for every picture based on temporal layer index
536
+ * 0: off (use the auto mode QP)
537
+ * 1: on (the offset is applied on top of the user QP)
538
+ * 2: on (the offset is applied on top of the auto mode QP)
539
+ *
540
+ * Default is 0.*/
541
+ uint8_t use_fixed_qindex_offsets;
542
+ int32_t qindex_offsets[EB_MAX_TEMPORAL_LAYERS];
543
+ int32_t key_frame_chroma_qindex_offset;
544
+ int32_t key_frame_qindex_offset;
545
+ int32_t chroma_qindex_offsets[EB_MAX_TEMPORAL_LAYERS];
546
+
547
+ int32_t luma_y_dc_qindex_offset;
548
+ int32_t chroma_u_dc_qindex_offset;
549
+ int32_t chroma_u_ac_qindex_offset;
550
+ int32_t chroma_v_dc_qindex_offset;
551
+ int32_t chroma_v_ac_qindex_offset;
552
+
553
+ /**
554
+ * @brief Deblocking loop filter control
555
+ *
556
+ * 0: disabled
557
+ * 1: enabled
558
+ * 2: more accurate (slower)
559
+ */
560
+ uint8_t enable_dlf_flag;
561
+
562
+ /* Film grain denoising the input picture
563
+ * Flag to enable the denoising
564
+ *
565
+ * Default is 0. */
566
+ uint32_t film_grain_denoise_strength;
567
+
568
+ /**
569
+ * @brief Determines how much denoising is used.
570
+ * Only applicable when film grain is ON.
571
+ *
572
+ * 0 is no denoising
573
+ * 1 is full denoising
574
+ *
575
+ * Default is 0. */
576
+ uint8_t film_grain_denoise_apply;
577
+
578
+ /* CDEF Level
579
+ *
580
+ * Default is -1. */
581
+ int cdef_level;
582
+
583
+ /* Restoration filtering
584
+ * enable/disable
585
+ * set Self-Guided (sg) mode
586
+ * set Wiener (wn) mode
587
+ *
588
+ * Default is -1. */
589
+ int enable_restoration_filtering;
590
+
591
+ /* motion field motion vector
592
+ *
593
+ * Default is -1. */
594
+ int enable_mfmv;
595
+
596
+ /* Flag to enable the scene change detection algorithm.
597
+ *
598
+ * Default is 1. */
599
+ uint32_t scene_change_detection;
600
+
601
+ /* Log 2 Tile Rows and columns . 0 means no tiling,1 means that we split the dimension
602
+ * into 2
603
+ * Default is 0. */
604
+ int32_t tile_columns;
605
+ int32_t tile_rows;
606
+
607
+ /* When RateControlMode is set to 1 it's best to set this parameter to be
608
+ * equal to the Intra period value (such is the default set by the encoder).
609
+ * When CQP is chosen, then a (2 * minigopsize +1) look ahead is recommended.
610
+ *
611
+ * Default depends on rate control mode.*/
612
+ uint32_t look_ahead_distance;
613
+
614
+ /* recode_loop indicates the recode levels,
615
+ * DISALLOW_RECODE = 0, No recode.
616
+ * ALLOW_RECODE_KFMAXBW = 1, Allow recode for KF and exceeding maximum frame bandwidth.
617
+ * ALLOW_RECODE_KFARFGF = 2, Allow recode only for KF/ARF/GF frames.
618
+ * ALLOW_RECODE = 3, Allow recode for all frames based on bitrate constraints.
619
+ * ALLOW_RECODE_DEFAULT = 4, Default setting, ALLOW_RECODE_KFARFGF for M0~5 and
620
+ * ALLOW_RECODE_KFMAXBW for M6~8.
621
+ * default is 4
622
+ */
623
+ uint32_t recode_loop;
624
+
625
+ /* Flag to signal the content being a screen sharing content type
626
+ *
627
+ * Default is 0. */
628
+ uint32_t screen_content_mode;
629
+
630
+ /* Adaptive quantization used within a frame.
631
+ *
632
+ * For rc_mode 0, setting this to:
633
+ * 0: use CQP mode
634
+ * 1: variance-based segmentation
635
+ * 2: CRF (per-frame QPs and per-SB delta-QPs derived using TPL) */
636
+ uint8_t aq_mode;
637
+
638
+ /**
639
+ * @brief Enable use of ALT-REF (temporally filtered) frames.
640
+ * 0 = off
641
+ * 1 = on
642
+ * 2 = adaptive
643
+ * Default is 1. */
644
+ uint8_t enable_tf;
645
+
646
+ bool enable_overlays;
647
+ /**
648
+ * @brief Tune for a particular metric; 0: VQ, 1: PSNR, 2: SSIM, 3: IQ (Image Quality), 4: MS-SSIM.
649
+ *
650
+ * Default is 1.
651
+ */
652
+ uint8_t tune;
653
+
654
+ // super-resolution parameters
655
+ uint8_t superres_mode;
656
+ uint8_t superres_denom;
657
+ uint8_t superres_kf_denom;
658
+ uint8_t superres_qthres;
659
+ uint8_t superres_kf_qthres;
660
+ uint8_t superres_auto_search_type;
661
+ /* Decoder-speed-targeted encoder optimization level (produce bitstreams that can be decoded faster).
662
+ * 0: No decoder-targeted speed optimization
663
+ * 1: Level 1 of decoder-targeted speed optimizations (faster decoder-speed than level 0)
664
+ * 2: Level 2 of decoder-targeted speed optimizations (faster decoder-speed than level 1)
665
+ */
666
+ uint8_t fast_decode;
667
+ /* S-Frame interval (frames)
668
+ * 0: S-Frame off
669
+ * >0: S-Frame on and indicates the number of frames after which a frame may be coded as an S-Frame
670
+ */
671
+ int32_t sframe_dist;
672
+ /* Indicates how an S-Frame should be inserted
673
+ * values are from EbSFrameMode
674
+ * SFRAME_STRICT_ARF: the considered frame will be made into an S-Frame only if it is an altref frame
675
+ * SFRAME_NEAREST_ARF: if the considered frame is not an altref frame, the next altref frame will be made into an S-Frame
676
+ * SFRAME_FLEXIBLE_ARF: if the considered frame is not an altref frame, modify the mini-GOP structure to promote it to an altref frame
677
+ * SFRAME_DEC_POSI: if the considered frame in decode order is not an altref frame, modify the mini-GOP structure to promote its previous frame to an altref frame, and set the next altref to an S-Frame
678
+ */
679
+ EbSFrameMode sframe_mode;
680
+
681
+ // End of individual tuning flags
682
+
683
+ // Threads management
684
+
685
+ /* The level of parallelism refers to how much parallelization the encoder will perform
686
+ * by setting the number of threads and pictures that can be handled simultaneously. If
687
+ * the value is 0, a deafult level will be chosen based on the number of cores on the
688
+ * machine. Levels 1-6 are supported. Beyond that, higher inputs
689
+ * will map to the highest level.
690
+ */
691
+ uint32_t level_of_parallelism;
692
+
693
+ /* CPU FLAGS to limit assembly instruction set used by encoder.
694
+ * Default is EB_CPU_FLAGS_ALL. */
695
+ EbCpuFlags use_cpu_flags;
696
+
697
+ // Debug tools
698
+ /* Instruct the library to calculate the recon to source for PSNR calculation
699
+ *
700
+ * Default is 0.*/
701
+ uint32_t stat_report;
702
+
703
+ /**
704
+ * @brief API Signal to output reconstructed yuv used for debug purposes.
705
+ * Using this will affect the speed of encoder.
706
+ *
707
+ * Default is false.
708
+ */
709
+ bool recon_enabled;
710
+ // 1.0.0: Any additional fields shall go after here
711
+
712
+ /**
713
+ * @brief Signal that force-key-frames is enabled.
714
+ *
715
+ */
716
+ bool force_key_frames;
717
+
718
+ /**
719
+ * @brief Signal to the library to treat intra_period_length as seconds and
720
+ * multiply by fps_num/fps_den.
721
+ */
722
+ bool multiply_keyint;
723
+ // reference scaling parameters
724
+ /**
725
+ * @brief Reference scaling mode
726
+ * the available modes are defined in RESIZE_MODE
727
+ */
728
+ uint8_t resize_mode;
729
+ /**
730
+ * @brief Resize denominator
731
+ * this value can be from 8 to 16, means downscaling to 8/8-8/16 of original
732
+ * resolution in both width and height
733
+ */
734
+ uint8_t resize_denom;
735
+ /**
736
+ * @brief Resize denominator of key frames
737
+ * this value can be from 8 to 16, means downscaling to 8/8-8/16 of original
738
+ * resolution in both width and height
739
+ */
740
+ uint8_t resize_kf_denom;
741
+ /**
742
+ * @brief Signal to the library to enable quantisation matrices
743
+ *
744
+ * Default is false.
745
+ */
746
+ bool enable_qm;
747
+
748
+ /**
749
+ * @brief Min quant matrix flatness. Applicable when enable_qm is true.
750
+ * Min value is 0.
751
+ * Max value is 15.
752
+ * Default is 8.
753
+ */
754
+ uint8_t min_qm_level;
755
+ /**
756
+ * @brief Max quant matrix flatness. Applicable when enable_qm is true.
757
+ * Min value is 0.
758
+ * Max value is 15.
759
+ * Default is 15.
760
+ */
761
+ uint8_t max_qm_level;
762
+
763
+ /**
764
+ * @brief gop_constraint_rc
765
+ *
766
+ * Currently, only applicable for VBR and when GoP size is greater than 119 frames.
767
+ *
768
+ * When enabled, the rate control matches the target rate for each GoP.
769
+ *
770
+ * 0: off
771
+ * 1: on
772
+ * Default is 0.
773
+ */
774
+ bool gop_constraint_rc;
775
+ /**
776
+ * @brief scale factors for lambda value for different frame update types
777
+ * factor >> 7 (/ 128) is the actual value in float
778
+ */
779
+ int32_t lambda_scale_factors[SVT_AV1_FRAME_UPDATE_TYPES];
780
+
781
+ /* Dynamic gop
782
+ *
783
+ * 0 = disable Dynamic GoP
784
+ * 1 = enable Dynamic GoP
785
+ * Default is 1. */
786
+ bool enable_dg;
787
+ /**
788
+ * @brief startup_mg_size
789
+ *
790
+ * When enabled, a MG with specified size will be inserted after the key frame.
791
+ * The MG size is determined by 2^startup_mg_size.
792
+ *
793
+ * 0: off
794
+ * 2: set hierarchical levels to 2 (MG size 4)
795
+ * 3: set hierarchical levels to 3 (MG size 8)
796
+ * 4: set hierarchical levels to 4 (MG size 16)
797
+ * Default is 0.
798
+ */
799
+ uint8_t startup_mg_size;
800
+
801
+ /**
802
+ * @brief startup_qp_offset
803
+ *
804
+ * When enabled, an offset will be added to the input-qp of the startup GOP prior to the picture-qp derivation
805
+ *
806
+ * Min value is -63.
807
+ * Max value is 63.
808
+ * Default is 0.
809
+ */
810
+ int8_t startup_qp_offset;
811
+ /* @brief reference scaling events for random access mode (resize-mode = 4)
812
+ *
813
+ * evt_num: total count of events
814
+ * start_frame_nums: array of scaling start frame numbers
815
+ * resize_kf_denoms: array of scaling denominators of key-frame
816
+ * resize_denoms: array of scaling denominators of non-key-frame
817
+ */
818
+ SvtAv1FrameScaleEvts frame_scale_evts;
819
+
820
+ /* ROI map
821
+ *
822
+ * 0 = disable ROI
823
+ * 1 = enable ROI
824
+ * Default is 0. */
825
+ bool enable_roi_map;
826
+
827
+ /* Manually adjust temporal filtering strength
828
+ * 10 + (4 - 0) = 14 (8x weaker)
829
+ * 10 + (4 - 1) = 13 (4x weaker, PSY default)
830
+ * 10 + (4 - 2) = 12 (2x weaker)
831
+ * 10 + (4 - 3) = 11 (mainline default)
832
+ * 10 + (4 - 4) = 10 (2x stronger) */
833
+ uint8_t tf_strength;
834
+
835
+ /* Stores the optional film grain synthesis info */
836
+ AomFilmGrain* fgs_table;
837
+
838
+ /* New parameters can go in under this line. Also deduct the size of the parameter */
839
+ /* from the padding array */
840
+
841
+ /* Variance Boost
842
+ * false = disable Variance Boost
843
+ * true = enable Variance Boost
844
+ * Default is false. */
845
+ bool enable_variance_boost;
846
+ /* @brief Selects the curve strength to boost low variance regions according to a fast-growing formula
847
+ * Default is 2 */
848
+ uint8_t variance_boost_strength;
849
+
850
+ /* @brief Picks a set of eight 8x8 variance values per superblock to determine boost
851
+ * Lower values enable detecting more blocks that need boosting, at the expense of more possible false positives (overall bitrate increase)
852
+ * 1: 1st octile
853
+ * 4: 4th octile
854
+ * 8: 8th octile
855
+ * Default is 5 */
856
+ uint8_t variance_octile;
857
+
858
+ /* @brief Bias towards decreased/increased sharpness in the deblocking loop filter & during rate distortion
859
+ * Minimum value is -7 (less sharp).
860
+ * Maximum value is 7 (more sharp).
861
+ * Default is 0 (medium sharpness). */
862
+ int8_t sharpness;
863
+
864
+ /* @brief Enable the user to configure which curve variance boost uses.
865
+ * Curve 1 emphasizes boosting low-medium contrast regions at a modest bitrate increase over the default curve
866
+ * 0: default curve
867
+ * 1: low-medium contrast boost curve
868
+ * 2: still picture curve, tuned for SSIMULACRA2 performance on the CID22 Validation Set
869
+ * Default is 0. */
870
+ uint8_t variance_boost_curve;
871
+
872
+ /* @brief Frame-level luminance-based QP bias to improve quality in low luma scenarios
873
+ * Works by adjusting frame-level QP based on average luminance across a frame
874
+ * 0: Disable luminance-based QP bias
875
+ * 1-100: Enable frame-level luminance-based QP bias. Higher values strengthen the bias
876
+ * Default is 0 (disabled). */
877
+ uint8_t luminance_qp_bias;
878
+
879
+ /* @brief Signal to the library to enable losless coding
880
+ *
881
+ * Default is false.
882
+ */
883
+ bool lossless;
884
+
885
+ /* @brief Signal to the library to enable still-picture coding
886
+ *
887
+ * Default is false.
888
+ */
889
+ bool avif;
890
+
891
+ /**
892
+ * @brief Min chroma quant matrix flatness. Applicable when enable_qm is true.
893
+ * Min value is 0.
894
+ * Max value is 15.
895
+ * Default is 8.
896
+ */
897
+ uint8_t min_chroma_qm_level;
898
+
899
+ /**
900
+ * @brief Max chroma quant matrix flatness. Applicable when enable_qm is true.
901
+ * Min value is 0.
902
+ * Max value is 15.
903
+ * Default is 15.
904
+ */
905
+ uint8_t max_chroma_qm_level;
906
+
907
+ /* @brief Signal to the library to enable real-time coding
908
+ *
909
+ * Default is false.
910
+ */
911
+ bool rtc;
912
+
913
+ /* @brief compresses the QP hierarchical layer scale to improve temporal video consistency
914
+ * 0: no compression, original SVT-AV1 scaling
915
+ * 1-3: enable compression, the higher the number the stronger the compression
916
+ * (different frame quality fluctuation/mean quality tradeoffs)
917
+ * Default is 1
918
+ */
919
+ uint8_t qp_scale_compress_strength;
920
+
921
+ /* @brief Indicates where to insert an S-Frame, only available when sframe_mode is SFRAME_FLEXIBLE_ARF */
922
+ SvtAv1SFramePositions sframe_posi;
923
+
924
+ /* @brief Indicates QP of S-Frame(s) */
925
+ uint8_t sframe_qp;
926
+ /* @brief Indicates QP offset of S-Frame(s) */
927
+ int8_t sframe_qp_offset;
928
+
929
+ /**
930
+ * @brief Toggle default film grain blocksize behavior
931
+ * 0: use default blocksize behavior (32x32)
932
+ * 1: use adaptive blocksize based on resolution
933
+ * - 8x8 for <4k
934
+ * - 16x16 for 4k
935
+ * Default is 1
936
+ */
937
+ bool adaptive_film_grain;
938
+
939
+ /* @brief Limit transform sizes to the specified size
940
+ * 32: use transform sizes up to 32x32 pixels
941
+ * 64: use transform sizes up to 64x64 pixels
942
+ * Default is 64
943
+ * Note: Setting the max transform size to 32 can be useful under some circumstances (e.g. still image coding),
944
+ * as it's the largest transform where all coefficients can be coded into the bitstream.
945
+ * In AV1, the transform size of 64 drops the highest 32 AC coefficients by design, effectively zeroing them upon
946
+ * decoding, which can cause certain visual features to look blurry.
947
+ * Forcing smaller tx sizes (i.e. 16, 8, 4) doesn't hold an inherent visual quality advantage over 32, so those
948
+ * aren't exposed as options.
949
+ */
950
+ uint8_t max_tx_size;
951
+
952
+ /* @brief qindex offset for extended CRF support
953
+ * Value is internally determined by CRF parameter value, each quarter-step increment to the CRF adds 1 to the
954
+ * offset, with a maximum of 3 (i.e. three quarter-step increments) for fractional CRFs below 63, and up to
955
+ * 28 for the extended CRF range (63.25 to 70)
956
+ * Default is 0 if CRF is an integer
957
+ */
958
+ uint8_t extended_crf_qindex_offset;
959
+
960
+ /**
961
+ * @brief Strength of the internal RD metric to bias toward high-frequency error (helps with texture preservation and film grain retention)
962
+ * 0.00: disable AC bias
963
+ * 1.00: enable AC bias with a strength of 1.00
964
+ * Default is 0.00.
965
+ */
966
+ double ac_bias;
967
+
968
+ // clang-format off
969
+ /* Add 128 Byte Padding to Struct to avoid changing the size of the public configuration struct */
970
+ uint8_t padding[128
971
+ - sizeof(PredStructure) + sizeof (uint8_t) // pred_strucutre type was changed from uint8_t to PredStructure
972
+ ];
973
+ // clang-format on
974
+ } EbSvtAv1EncConfiguration;
975
+
976
+ /**
977
+ * Returns a string containing "v$tag-$commit_count-g$hash${dirty:+-dirty}"
978
+ * @param[out] SVT_AV1_CVS_VERSION
979
+ */
980
+ EB_API const char* svt_av1_get_version(void);
981
+
982
+ /**
983
+ * Prints the version header and build information to the file
984
+ * specified by the SVT_LOG_FILE environment variable or stderr
985
+ */
986
+ EB_API void svt_av1_print_version(void);
987
+
988
+ /**
989
+ * @brief Log levels
990
+ *
991
+ * Defines the severity levels for logging messages.
992
+ */
993
+ typedef enum {
994
+ SVT_AV1_LOG_ALL = -1, /**< Log all messages */
995
+ SVT_AV1_LOG_FATAL = 0, /**< Fatal errors */
996
+ SVT_AV1_LOG_ERROR = 1, /**< Errors */
997
+ SVT_AV1_LOG_WARN = 2, /**< Warnings */
998
+ SVT_AV1_LOG_INFO = 3, /**< Informational messages */
999
+ SVT_AV1_LOG_DEBUG = 4, /**< Debug messages */
1000
+ } SvtAv1LogLevel;
1001
+
1002
+ /**
1003
+ * @brief Log callback function signature
1004
+ *
1005
+ * Applications can register a callback to intercept log messages from the encoder.
1006
+ *
1007
+ * @param[in] level Severity level of the log message
1008
+ * @param[in] context Opaque user-provided context pointer (may be NULL)
1009
+ * @param[in] tag Optional log tag (may be NULL)
1010
+ * @param[in] fmt printf-style format string
1011
+ * @param[in] args Variable argument list corresponding to the format string
1012
+ */
1013
+ typedef void (*SvtAv1LogCallback)(void* context, SvtAv1LogLevel level, const char* tag, const char* fmt, va_list args);
1014
+
1015
+ /**
1016
+ * Register a callback for intercepting log messages.
1017
+ *
1018
+ * Applications can use this function to redirect log output to custom handlers. When a callback is registered, all log
1019
+ * messages will be dispatched to the callback instead of the default stderr/file output. This will affect all
1020
+ * instances and is a global setting. This should be called before svt_av1_enc_init_handle() as any calls to
1021
+ * svt_av1_enc_init_handle() will finalize logging.
1022
+ *
1023
+ * @param[in] callback Callback function pointer. Has no effect if NULL.
1024
+ * @param[in] context Opaque context pointer passed back to the callback. Typically application state or logging context.
1025
+ * Ignored if callback is NULL.
1026
+ */
1027
+ EB_API void svt_av1_set_log_callback(SvtAv1LogCallback callback, void* context);
1028
+
1029
+ /* STEP 1: Call the library to construct a Component Handle.
1030
+ *
1031
+ * Parameter:
1032
+ * @ **p_handle Handle to be called in the future for manipulating the
1033
+ * component.
1034
+ * @ *p_app_data Callback data.
1035
+ * @ *config_ptr Pointer passed back to the client during callbacks, it will be
1036
+ * loaded with default params from the library. */
1037
+ EB_API EbErrorType svt_av1_enc_init_handle(
1038
+ EbComponentType** p_handle,
1039
+ EbSvtAv1EncConfiguration* config_ptr); // config_ptr will be loaded with default params from the library
1040
+
1041
+ /* STEP 2: Set all configuration parameters.
1042
+ *
1043
+ * Parameter:
1044
+ * @ *svt_enc_component Encoder handler.
1045
+ * @ *pComponentParameterStructure Encoder and buffer configurations will be copied to the library. */
1046
+ EB_API EbErrorType svt_av1_enc_set_parameter(
1047
+ EbComponentType* svt_enc_component,
1048
+ EbSvtAv1EncConfiguration*
1049
+ pComponentParameterStructure); // pComponentParameterStructure contents will be copied to the library
1050
+
1051
+ /* OPTIONAL: Set a single configuration parameter.
1052
+ *
1053
+ * Parameter:
1054
+ * @ *pComponentParameterStructure Encoder parameters structure.
1055
+ * @ *name Null terminated string containing the parameter name
1056
+ * @ *value Null terminated string containing the parameter value */
1057
+ EB_API EbErrorType svt_av1_enc_parse_parameter(EbSvtAv1EncConfiguration* pComponentParameterStructure, const char* name,
1058
+ const char* value);
1059
+
1060
+ /* STEP 3: Initialize encoder and allocates memory to necessary buffers.
1061
+ *
1062
+ * Parameter:
1063
+ * @ *svt_enc_component Encoder handler. */
1064
+ EB_API EbErrorType svt_av1_enc_init(EbComponentType* svt_enc_component);
1065
+
1066
+ /* OPTIONAL: Get stream headers at init time.
1067
+ *
1068
+ * Parameter:
1069
+ * @ *svt_enc_component Encoder handler.
1070
+ * @ **output_stream_ptr Output buffer. */
1071
+ EB_API EbErrorType svt_av1_enc_stream_header(EbComponentType* svt_enc_component,
1072
+ EbBufferHeaderType** output_stream_ptr);
1073
+
1074
+ /* OPTIONAL: Release stream headers at init time.
1075
+ *
1076
+ * Parameter:
1077
+ * @ *stream_header_ptr stream header buffer. */
1078
+ EB_API EbErrorType svt_av1_enc_stream_header_release(EbBufferHeaderType* stream_header_ptr);
1079
+
1080
+ /* STEP 4: Send the picture.
1081
+ *
1082
+ * Parameter:
1083
+ * @ *svt_enc_component Encoder handler.
1084
+ * @ *p_buffer Header pointer, picture buffer. */
1085
+ EB_API EbErrorType svt_av1_enc_send_picture(EbComponentType* svt_enc_component, EbBufferHeaderType* p_buffer);
1086
+
1087
+ /**
1088
+ * @brief Step 5: Receive packet.
1089
+ * This function will become blocking if either pic_send_done is set to 1 or if we are in low-delay (pred-struct=1).
1090
+ * Otherwise, this function is non-blocking and will return EB_NoErrorEmptyQueue if there are no packets available.
1091
+ *
1092
+ * @param svt_enc_component The encoder handler
1093
+ * @param p_buffer Header pointer to return packet with
1094
+ * @param pic_send_done Flag to signal that all input pictures have been sent. Should be either 0 or 1.
1095
+ * @return EB_API Either EB_ErrorMax for an encode error or EB_NoErrorEmptyQueue if there are no available packets.
1096
+ */
1097
+ EB_API EbErrorType svt_av1_enc_get_packet(EbComponentType* svt_enc_component, EbBufferHeaderType** p_buffer,
1098
+ uint8_t pic_send_done);
1099
+
1100
+ /* STEP 5-1: Release output buffer back into the pool.
1101
+ *
1102
+ * Parameter:
1103
+ * @ **p_buffer Header pointer that contains the output packet to be released. */
1104
+ EB_API void svt_av1_enc_release_out_buffer(EbBufferHeaderType** p_buffer);
1105
+
1106
+ /* OPTIONAL: Fill buffer with reconstructed picture.
1107
+ *
1108
+ * Parameter:
1109
+ * @ *svt_enc_component Encoder handler.
1110
+ * @ *p_buffer Output buffer. */
1111
+ EB_API EbErrorType svt_av1_get_recon(EbComponentType* svt_enc_component, EbBufferHeaderType* p_buffer);
1112
+
1113
+ /* OPTIONAL: get stream information
1114
+ *
1115
+ * Parameter:
1116
+ * @ *svt_enc_component Encoder handler.
1117
+ * @ *stream_info_id SVT_AV1_STREAM_INFO_ID.
1118
+ * @ *info output, the type depends on id */
1119
+ EB_API EbErrorType svt_av1_enc_get_stream_info(EbComponentType* svt_enc_component, uint32_t stream_info_id, void* info);
1120
+
1121
+ /* STEP 6: Deinitialize encoder library.
1122
+ *
1123
+ * Parameter:
1124
+ * @ *svt_enc_component Encoder handler. */
1125
+ EB_API EbErrorType svt_av1_enc_deinit(EbComponentType* svt_enc_component);
1126
+
1127
+ /* STEP 7: Deconstruct encoder handler.
1128
+ *
1129
+ * Parameter:
1130
+ * @ *svt_enc_component Encoder handler. */
1131
+ EB_API EbErrorType svt_av1_enc_deinit_handle(EbComponentType* svt_enc_component);
1132
+
1133
+ #ifdef __cplusplus
1134
+ }
1135
+ #endif // __cplusplus
1136
+
1137
+ #endif // EbSvtAv1Enc_h