forked from Kagami/SVT-AV1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EbEncSettings.c
2102 lines (1880 loc) · 83.9 KB
/
EbEncSettings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright(c) 2022 Intel Corporation
*
* This source code is subject to the terms of the BSD 3-Clause Clear License and
* the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at https://www.aomedia.org/license. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
*/
// SUMMARY
// Contains the encoder settings API functions
/**************************************
* Includes
**************************************/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "EbVersion.h"
#include "EbDefinitions.h"
#include "EbSvtAv1Enc.h"
#include "EbSvtAv1Metadata.h"
#include "EbEncSettings.h"
#include "EbLog.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <errno.h>
#include <pthread.h>
#include <unistd.h>
#endif
/******************************************
* Verify Settings
******************************************/
EbErrorType svt_av1_verify_settings(SequenceControlSet *scs) {
EbErrorType return_error = EB_ErrorNone;
EbSvtAv1EncConfiguration *config = &scs->static_config;
unsigned int channel_number = config->channel_id;
if (config->enc_mode > MAX_ENC_PRESET || config->enc_mode < -1) {
SVT_ERROR("Instance %u: EncoderMode must be in the range of [-1-%d]\n", channel_number + 1, MAX_ENC_PRESET);
return_error = EB_ErrorBadParameter;
}
if (config->enc_mode == MAX_ENC_PRESET) {
SVT_WARN(
"EncoderMode (preset): %d was developed for the sole purpose of debugging and or "
"running fast convex-hull encoding. This configuration should not be used for any "
"benchmarking or quality analysis\n",
MAX_ENC_PRESET);
}
if (scs->max_input_luma_width < 64) {
SVT_ERROR("Instance %u: Source Width must be at least 64\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->max_input_luma_height < 64) {
SVT_ERROR("Instance %u: Source Height must be at least 64\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->max_input_luma_width % 2) {
SVT_ERROR("Error Instance %u: Source Width must be even for YUV_420 colorspace\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->max_input_luma_height % 2) {
SVT_ERROR("Error Instance %u: Source Height must be even for YUV_420 colorspace\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->pred_structure > 2 || config->pred_structure < 1) {
SVT_ERROR("Instance %u: Pred Structure must be [1 or 2]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->pred_structure == 1 && config->pass > 0) {
SVT_ERROR("Instance %u: Multi-passes is not support with Low Delay mode \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->vbr_bias_pct != 100) {
SVT_WARN("Instance %u: The bias percentage is being ignored and will be deprecated in the up coming release \n",
channel_number + 1);
}
if (config->maximum_buffer_size_ms < 20 || config->maximum_buffer_size_ms > 10000) {
SVT_ERROR("Instance %u: The maximum buffer size must be between [20, 10000]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->starting_buffer_level_ms < 20 || config->starting_buffer_level_ms > 10000) {
SVT_ERROR("Instance %u: The initial buffer size must be between [20, 10000] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
} else if (config->starting_buffer_level_ms >= config->maximum_buffer_size_ms) {
SVT_WARN(
"The initial buffer size must be less than maximum buffer size. Defaulting optimal "
"buffer size to maximum buffer size - 1 (%u)\n",
config->maximum_buffer_size_ms - 1);
config->starting_buffer_level_ms = (config->maximum_buffer_size_ms - 1);
}
if (config->optimal_buffer_level_ms < 20 || config->optimal_buffer_level_ms > 10000) {
SVT_ERROR("Instance %u: The optimal buffer size must be between [20, 10000]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
} else if (config->optimal_buffer_level_ms >= config->maximum_buffer_size_ms) {
SVT_WARN(
"The optimal buffer size must be less than maximum buffer size. Defaulting optimal "
"buffer size to maximum buffer size - 1 (%u)\n",
config->maximum_buffer_size_ms - 1);
config->optimal_buffer_level_ms = (config->maximum_buffer_size_ms - 1);
}
if (config->over_shoot_pct > 100) {
SVT_ERROR("Instance %u: The overshoot percentage must be between [0, 100] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->mbr_over_shoot_pct > 100) {
SVT_ERROR("Instance %u: The max bitrate overshoot percentage must be between [0, 100] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->under_shoot_pct > 100) {
SVT_ERROR("Instance %u: The undershoot percentage must be between [0, 100] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->target_bit_rate > 100000000) {
SVT_ERROR("Instance %u: The target bit rate must be between [0, 100000] kbps \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->max_bit_rate > 100000000) {
SVT_ERROR("Instance %u: The maximum bit rate must be between [0, 100000] kbps \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->vbr_max_section_pct > 10000) {
SVT_ERROR("Instance %u: The max section percentage must be between [0, 10000] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->vbr_min_section_pct > 100) {
SVT_ERROR("Instance %u: The min section percentage must be between [0, 100] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->gop_constraint_rc &&
((config->rate_control_mode != SVT_AV1_RC_MODE_VBR) || config->intra_period_length < 119)) {
SVT_ERROR(
"Instance %u: Gop constraint rc is only supported with VBR mode when Gop size is "
"greater than 119 \n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->gop_constraint_rc > 1) {
SVT_ERROR("Instance %u: Invalid gop_constraint_rc. gop_constraint_rc must be [0 - 1]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->gop_constraint_rc)
SVT_WARN(
"Instance %u: The GoP constraint RC mode is a work-in-progress project, and is only "
"available for demos, experimentation, and further development uses and should not be "
"used for benchmarking until fully implemented.\n",
channel_number + 1);
if (config->force_key_frames &&
(config->rate_control_mode == SVT_AV1_RC_MODE_CBR || config->pred_structure != SVT_AV1_PRED_RANDOM_ACCESS)) {
SVT_WARN(
"Instance %u: Force key frames is now supported for lowdelay but the force_key_frames flag"
" does not need to be set be on. Please follow the app samples shown by the FTR_KF_ON_FLY_SAMPLE"
" macro on how to use it. force_key_frames will now be set to 0 \n",
channel_number + 1);
config->force_key_frames = 0;
}
if (config->force_key_frames && config->rate_control_mode == SVT_AV1_RC_MODE_VBR) {
SVT_ERROR("Instance %u: Force key frames is not supported for VBR mode \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->rate_control_mode != SVT_AV1_RC_MODE_CQP_OR_CRF && (config->max_bit_rate != 0)) {
SVT_ERROR("Instance %u: Max Bitrate only supported with CRF mode\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->rate_control_mode == SVT_AV1_RC_MODE_CBR && config->pred_structure == SVT_AV1_PRED_RANDOM_ACCESS) {
SVT_ERROR("CBR Rate control is currently not supported for SVT_AV1_PRED_RANDOM_ACCESS, use VBR mode\n");
return_error = EB_ErrorBadParameter;
}
if (config->rate_control_mode == SVT_AV1_RC_MODE_VBR && config->pred_structure == SVT_AV1_PRED_LOW_DELAY_B) {
SVT_ERROR("VBR Rate control is currently not supported for SVT_AV1_PRED_LOW_DELAY_B, use CBR mode\n");
return_error = EB_ErrorBadParameter;
}
if (scs->max_input_luma_width > 16384) {
SVT_ERROR("Instance %u: Source Width must be less than or equal to 16384\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->max_input_luma_height > 8704) {
SVT_ERROR("Instance %u: Source Height must be less than or equal to 8704)\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->seq_header.max_frame_width < 64) {
SVT_ERROR("Instance %u: Forced Max Width must be at least 64\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->seq_header.max_frame_height < 64) {
SVT_ERROR("Instance %u: Forced Max Height must be at least 64\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->seq_header.max_frame_width > 16384) {
SVT_ERROR("Instance %u: Forced Max Width must be less than or equal to 16384\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->seq_header.max_frame_height > 8704) {
SVT_ERROR("Instance %u: Forced Max Height must be less than or equal to 8704)\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if ((scs->max_input_luma_width > scs->seq_header.max_frame_width) ||
(scs->max_input_luma_height > scs->seq_header.max_frame_height)) {
SVT_ERROR(
"Error instance %u: Source Width/Height must be less than or equal to Forced Max "
"Width/Height\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->level != 0 && (config->level < 20 || config->level > 73)) {
SVT_ERROR("Instance %u: Level must be in the range of [2.0-7.3]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->qp > MAX_QP_VALUE) {
SVT_ERROR("Instance %u: %s must be [0 - %d]\n",
channel_number + 1,
config->enable_adaptive_quantization ? "CRF" : "QP",
MAX_QP_VALUE);
return_error = EB_ErrorBadParameter;
}
if (config->hierarchical_levels > 5) {
SVT_ERROR("Instance %u: Hierarchical Levels supported [0-5]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if ((config->intra_period_length < -2 || config->intra_period_length > 2 * ((1 << 30) - 1)) &&
config->rate_control_mode == SVT_AV1_RC_MODE_CQP_OR_CRF) {
SVT_ERROR("Instance %u: The intra period must be [-2, 2^31-2] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if ((config->intra_period_length < 0) && config->rate_control_mode == SVT_AV1_RC_MODE_VBR) {
SVT_ERROR("Instance %u: The intra period must be > 0 for RateControlMode %d \n",
channel_number + 1,
config->rate_control_mode);
return_error = EB_ErrorBadParameter;
}
if (config->intra_refresh_type > 2 || config->intra_refresh_type < 1) {
SVT_ERROR("Instance %u: Invalid intra Refresh Type [1-2]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->enable_dlf_flag > 1) {
SVT_ERROR("Instance %u: Invalid LoopFilterEnable. LoopFilterEnable must be [0 - 1]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->rate_control_mode > SVT_AV1_RC_MODE_CBR &&
(config->pass == ENC_FIRST_PASS || config->rc_stats_buffer.buf)) {
SVT_ERROR("Instance %u: Only rate control mode 0~2 are supported for 2-pass \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->profile > 2) {
SVT_ERROR("Instance %u: The maximum allowed profile value is 2 \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// Check if the current input video is conformant with the Level constraint
if (scs->frame_rate > (240 << 16)) {
SVT_ERROR("Instance %u: The maximum allowed frame rate is 240 fps\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// Check that the frame_rate is non-zero
if (!scs->frame_rate) {
SVT_ERROR("Instance %u: The frame rate should be greater than 0 fps \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->static_config.frame_rate_numerator == 0 || scs->static_config.frame_rate_denominator == 0) {
SVT_ERROR(
"Instance %u: The frame_rate_numerator and frame_rate_denominator must be greater than "
"0\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->recode_loop > 4) {
SVT_ERROR("Instance %u: The recode_loop must be [0 - 4] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->rate_control_mode > SVT_AV1_RC_MODE_CBR) {
SVT_ERROR("Instance %u: The rate control mode must be [0 - 2] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->look_ahead_distance > MAX_LAD && config->look_ahead_distance != (uint32_t)~0) {
SVT_ERROR("Instance %u: The lookahead distance must be [0 - %d] \n", channel_number + 1, MAX_LAD);
return_error = EB_ErrorBadParameter;
}
if ((unsigned)config->tile_rows > 6 || (unsigned)config->tile_columns > 6) {
SVT_ERROR("Instance %u: Log2Tile rows/cols must be [0 - 6] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if ((1u << config->tile_rows) * (1u << config->tile_columns) > 128 || config->tile_columns > 4) {
SVT_ERROR("Instance %u: MaxTiles is 128 and MaxTileCols is 16 (Annex A.3) \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->restricted_motion_vector > 1) {
SVT_ERROR("Instance %u : Invalid Restricted Motion Vector flag [0 - 1]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->max_qp_allowed > MAX_QP_VALUE) {
SVT_ERROR("Instance %u: MaxQpAllowed must be [1 - %d]\n", channel_number + 1, MAX_QP_VALUE);
return_error = EB_ErrorBadParameter;
} else if (config->min_qp_allowed >= MAX_QP_VALUE) {
SVT_ERROR("Instance %u: MinQpAllowed must be [1 - %d]\n", channel_number + 1, MAX_QP_VALUE - 1);
return_error = EB_ErrorBadParameter;
} else if ((config->min_qp_allowed) > (config->max_qp_allowed)) {
SVT_ERROR("Instance %u: MinQpAllowed must be smaller than MaxQpAllowed\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
} else if ((config->min_qp_allowed) == 0) {
SVT_ERROR("Instance %u: MinQpAllowed must be [1 - %d]. Lossless coding not supported\n",
channel_number + 1,
MAX_QP_VALUE - 1);
return_error = EB_ErrorBadParameter;
}
if (config->use_qp_file > 1) {
SVT_ERROR("Instance %u : Invalid use_qp_file. use_qp_file must be [0 - 1]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->use_fixed_qindex_offsets > 2) {
SVT_ERROR("Instance %u: The use_fixed_qindex_offsets must be [0 - 2] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->key_frame_qindex_offset < -64 || config->key_frame_qindex_offset > 63) {
SVT_ERROR(
"Instance %u : Invalid key_frame_qindex_offset. key_frame_qindex_offset must be [-64 - "
"63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
for (uint8_t i = 0; i < config->hierarchical_levels + 1; ++i) {
if (config->qindex_offsets[i] < -64 || config->qindex_offsets[i] > 63) {
SVT_ERROR("Instance %u : Invalid qindex_offsets. qindex_offsets must be [-64 - 63]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
}
if (config->key_frame_chroma_qindex_offset < -64 || config->key_frame_chroma_qindex_offset > 63) {
SVT_ERROR(
"Instance %u : Invalid key_frame_chroma_qindex_offset. key_frame_chroma_qindex_offset "
"must be [-64 - 63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->luma_y_dc_qindex_offset < -64 || config->luma_y_dc_qindex_offset > 63) {
SVT_ERROR(
"Instance %u : Invalid luma_y_dc_qindex_offset. luma_y_dc_qindex_offset "
"must be [-64 - 63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->chroma_u_dc_qindex_offset < -64 || config->chroma_u_dc_qindex_offset > 63) {
SVT_ERROR(
"Instance %u : Invalid chroma_u_dc_qindex_offset. chroma_u_dc_qindex_offset "
"must be [-64 - 63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->chroma_u_ac_qindex_offset < -64 || config->chroma_u_ac_qindex_offset > 63) {
SVT_ERROR(
"Instance %u : Invalid chroma_u_ac_qindex_offset. chroma_u_ac_qindex_offset "
"must be [-64 - 63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->chroma_v_dc_qindex_offset < -64 || config->chroma_v_dc_qindex_offset > 63) {
SVT_ERROR(
"Instance %u : Invalid chroma_v_dc_qindex_offset. chroma_v_dc_qindex_offset "
"must be [-64 - 63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->chroma_v_ac_qindex_offset < -64 || config->chroma_v_ac_qindex_offset > 63) {
SVT_ERROR(
"Instance %u : Invalid chroma_v_ac_qindex_offset. chroma_v_ac_qindex_offset "
"must be [-64 - 63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
for (uint8_t i = 0; i < config->hierarchical_levels + 1; ++i) {
if (config->chroma_qindex_offsets[i] < -64 || config->chroma_qindex_offsets[i] > 63) {
SVT_ERROR(
"Instance %u : Invalid chroma_qindex_offsets. chroma_qindex_offsets must be [-64 - "
"63]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
}
if (config->stat_report == 1) {
SVT_WARN("Instances %u: Enabling StatReport can decrease encoding speed\n", channel_number + 1);
}
if (config->stat_report > 1) {
SVT_ERROR("Instance %u : Invalid StatReport. StatReport must be [0 - 1]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->high_dynamic_range_input > 1) {
SVT_ERROR("Instance %u : Invalid HighDynamicRangeInput. HighDynamicRangeInput must be [0 - 1]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->screen_content_mode > 2) {
SVT_ERROR("Instance %u : Invalid screen_content_mode. screen_content_mode must be [0 - 2]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// IntraBC
if (scs->intrabc_mode > 3 || scs->intrabc_mode < -1) {
SVT_ERROR("Instance %u: Invalid intraBC mode [0-3, -1 for default], your input: %i\n",
channel_number + 1,
scs->intrabc_mode);
return_error = EB_ErrorBadParameter;
}
if (scs->intrabc_mode > 0 && config->screen_content_mode != 1) {
SVT_ERROR(
"Instance %u: The intra BC feature is only available when screen_content_mode is set "
"to 1\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (scs->static_config.enable_adaptive_quantization > 2) {
SVT_ERROR(
"Instance %u : Invalid enable_adaptive_quantization. enable_adaptive_quantization must "
"be [0-2]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if ((config->encoder_bit_depth != 8) && (config->encoder_bit_depth != 10)) {
SVT_ERROR("Instance %u: Encoder Bit Depth shall be only 8 or 10 \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// Check if the EncoderBitDepth is conformant with the Profile constraint
if ((config->profile == 0 || config->profile == 1) && config->encoder_bit_depth > 10) {
SVT_ERROR("Instance %u: The encoder bit depth shall be equal to 8 or 10 for Main/High Profile\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->encoder_color_format != EB_YUV420) {
SVT_ERROR("Instance %u: Only support 420 now \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->profile == 0 && config->encoder_color_format > EB_YUV420) {
SVT_ERROR("Instance %u: Non 420 color format requires profile 1 or 2\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->profile == 1 && config->encoder_color_format != EB_YUV444) {
SVT_ERROR("Instance %u: Profile 1 requires 4:4:4 color format\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->profile == 2 && config->encoder_bit_depth <= 10 && config->encoder_color_format != EB_YUV422) {
SVT_ERROR("Instance %u: Profile 2 bit-depth < 10 requires 4:2:2 color format\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->use_cpu_flags & EB_CPU_FLAGS_INVALID) {
SVT_ERROR(
"Instance %u: param '--asm' have invalid value.\n"
"Value should be [0 - 11] or [c, mmx, sse, sse2, sse3, ssse3, sse4_1, sse4_2, avx, "
"avx2, avx512, max]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->target_socket != -1 && config->target_socket != 0 && config->target_socket != 1) {
SVT_ERROR("Instance %u: Invalid target_socket. target_socket must be [-1 - 1] \n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// HBD mode decision
if (scs->enable_hbd_mode_decision < (int8_t)(-1) || scs->enable_hbd_mode_decision > 2) {
SVT_ERROR("Instance %u: Invalid HBD mode decision flag [-1 - 2], your input: %d\n",
channel_number + 1,
scs->enable_hbd_mode_decision);
return_error = EB_ErrorBadParameter;
}
// CDEF
if (config->cdef_level > 4 || config->cdef_level < -1) {
SVT_ERROR("Instance %u: Invalid CDEF level [0 - 4, -1 for auto], your input: %d\n",
channel_number + 1,
config->cdef_level);
return_error = EB_ErrorBadParameter;
}
// Restoration Filtering
if (config->enable_restoration_filtering != 0 && config->enable_restoration_filtering != 1 &&
config->enable_restoration_filtering != -1) {
SVT_ERROR("Instance %u: Invalid restoration flag [0 - 1, -1 for auto], your input: %d\n",
channel_number + 1,
config->enable_restoration_filtering);
return_error = EB_ErrorBadParameter;
}
if (config->enable_mfmv != 0 && config->enable_mfmv != 1 && config->enable_mfmv != -1) {
SVT_ERROR(
"Instance %u: Invalid motion field motion vector flag [0/1 or -1 for auto], your "
"input: %d\n",
channel_number + 1,
config->enable_mfmv);
return_error = EB_ErrorBadParameter;
}
if (config->enable_dg > 1) {
SVT_ERROR(
"Instance %u: Invalid dynamic GoP flag [0 - 1], your "
"input: %d\n",
channel_number + 1,
config->enable_dg);
return_error = EB_ErrorBadParameter;
}
if (config->fast_decode > 1) {
SVT_ERROR(
"Instance %u: Invalid fast decode flag [0 - 1, 0 for no decoder optimization], your "
"input: %d\n",
channel_number + 1,
config->fast_decode);
return_error = EB_ErrorBadParameter;
}
if (config->tune > 2) {
SVT_ERROR(
"Instance %u: Invalid tune flag [0 - 2, 0 for VQ, 1 for PSNR and 2 for SSIM], your "
"input: %d\n",
channel_number + 1,
config->tune);
return_error = EB_ErrorBadParameter;
}
if (config->tune == 2) {
if (config->rate_control_mode != 0 || config->pred_structure != SVT_AV1_PRED_RANDOM_ACCESS) {
SVT_ERROR("Instance %u: tune SSIM only supports CRF rate control mode currently\n",
channel_number + 1,
config->tune);
return_error = EB_ErrorBadParameter;
} else {
SVT_WARN(
"Instance %u: tune ssim (2) is supported for testing and debugging purposes."
"This configuration should not be used for any benchmarking analysis at this stage\n",
channel_number + 1);
}
}
if (config->superres_mode > SUPERRES_AUTO) {
SVT_ERROR("Instance %u: invalid superres-mode %d, should be in the range [%d - %d]\n",
channel_number + 1,
config->superres_mode,
SUPERRES_NONE,
SUPERRES_AUTO);
return_error = EB_ErrorBadParameter;
}
if (config->superres_mode > 0 && ((config->rc_stats_buffer.sz || config->pass == ENC_FIRST_PASS))) {
SVT_ERROR("Instance %u: superres is not supported for 2-pass\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->superres_qthres > MAX_QP_VALUE) {
SVT_ERROR("Instance %u: invalid superres-qthres %d, should be in the range [%d - %d] \n",
channel_number + 1,
config->superres_qthres,
MIN_QP_VALUE,
MAX_QP_VALUE);
return_error = EB_ErrorBadParameter;
}
if (config->superres_kf_qthres > MAX_QP_VALUE) {
SVT_ERROR("Instance %u: invalid superres-kf-qthres %d, should be in the range [%d - %d] \n",
channel_number + 1,
config->superres_kf_qthres,
MIN_QP_VALUE,
MAX_QP_VALUE);
return_error = EB_ErrorBadParameter;
}
if (config->superres_kf_denom < MIN_SUPERRES_DENOM || config->superres_kf_denom > MAX_SUPERRES_DENOM) {
SVT_ERROR("Instance %u: invalid superres-kf-denom %d, should be in the range [%d - %d] \n",
channel_number + 1,
config->superres_kf_denom,
MIN_SUPERRES_DENOM,
MAX_SUPERRES_DENOM);
return_error = EB_ErrorBadParameter;
}
if (config->superres_denom < MIN_SUPERRES_DENOM || config->superres_denom > MAX_SUPERRES_DENOM) {
SVT_ERROR("Instance %u: invalid superres-denom %d, should be in the range [%d - %d] \n",
channel_number + 1,
config->superres_denom,
MIN_SUPERRES_DENOM,
MAX_SUPERRES_DENOM);
return_error = EB_ErrorBadParameter;
}
if (config->resize_mode > RESIZE_RANDOM_ACCESS) {
SVT_LOG("Error instance %u: invalid resize-mode %d, should be in the range [%d - %d]\n",
channel_number + 1,
config->resize_mode,
RESIZE_NONE,
RESIZE_RANDOM_ACCESS);
return_error = EB_ErrorBadParameter;
}
if (config->resize_kf_denom < MIN_RESIZE_DENOM || config->resize_kf_denom > MAX_RESIZE_DENOM) {
SVT_LOG("Error instance %u: invalid resize-kf-denom %d, should be in the range [%d - %d] \n",
channel_number + 1,
config->resize_kf_denom,
MIN_RESIZE_DENOM,
MAX_RESIZE_DENOM);
return_error = EB_ErrorBadParameter;
}
if (config->resize_denom < MIN_RESIZE_DENOM || config->resize_denom > MAX_RESIZE_DENOM) {
SVT_LOG("Error instance %u: invalid resize-denom %d, should be in the range [%d - %d] \n",
channel_number + 1,
config->resize_denom,
MIN_RESIZE_DENOM,
MAX_RESIZE_DENOM);
return_error = EB_ErrorBadParameter;
}
if (config->matrix_coefficients == 0 && config->encoder_color_format != EB_YUV444) {
SVT_ERROR(
"Instance %u: Identity matrix (matrix_coefficient = 0) may be used only with 4:4:4 "
"color format.\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->hierarchical_levels < 2 || config->hierarchical_levels > 5) {
SVT_ERROR("Instance %u: Only hierarchical levels 2-5 is currently supported.\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->rate_control_mode == SVT_AV1_RC_MODE_VBR && config->intra_period_length == -1) {
SVT_ERROR(
"Instance %u: keyint = -1 is not supported for modes other than CRF rate control "
"encoding modes.\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// Limit 8K & 16K configurations ( due to memory constraints)
if ((uint64_t)(scs->max_input_luma_width * scs->max_input_luma_height) > INPUT_SIZE_4K_TH &&
config->enc_mode <= ENC_M7) {
SVT_ERROR("Instance %u: 8k+ resolution support is limited to M8 and faster presets.\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->pass > 0 && scs->static_config.enable_overlays) {
SVT_ERROR(
"Instance %u: The overlay frames feature is currently not supported with multi-pass "
"encoding\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
int pass = config->pass;
if (pass != 3 && pass != 2 && pass != 1 && pass != 0) {
SVT_ERROR(
"Instance %u: %d pass encode is not supported. --pass has a range of [0-3]\n", channel_number + 1, pass);
return_error = EB_ErrorBadParameter;
}
if (config->intra_refresh_type != 2 && pass > 0) {
SVT_ERROR("Instance %u: Multi-pass encode only supports closed-gop configurations.\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (pass == 3 && config->rate_control_mode == SVT_AV1_RC_MODE_CQP_OR_CRF) {
SVT_ERROR("Instance %u: CRF does not support 3-pass\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->enable_adaptive_quantization == 0 && config->rate_control_mode) {
SVT_ERROR("Instance %u: Adaptive quantization can not be turned OFF when RC ON\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->sframe_dist < 0) {
SVT_ERROR("Error instance %u: switch frame interval must be >= 0\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->sframe_dist > 0 && config->pred_structure != SVT_AV1_PRED_LOW_DELAY_P &&
config->pred_structure != SVT_AV1_PRED_LOW_DELAY_B) {
SVT_ERROR(
"Error instance %u: switch frame feature only supports low delay prediction "
"structure\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->sframe_dist > 0 && config->hierarchical_levels == 0) {
SVT_ERROR("Error instance %u: switch frame feature does not support flat IPPP\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->sframe_dist > 0 && config->sframe_mode != SFRAME_STRICT_BASE &&
config->sframe_mode != SFRAME_NEAREST_BASE) {
SVT_ERROR("Error instance %u: invalid switch frame mode %d, should be in the range [%d - %d]\n",
channel_number + 1,
config->sframe_mode,
SFRAME_STRICT_BASE,
SFRAME_NEAREST_BASE);
return_error = EB_ErrorBadParameter;
}
/* Warnings about the use of features that are incomplete */
if (config->enable_adaptive_quantization == 1) {
SVT_WARN(
"Instance %u: The adaptive quantization mode using segmentation is at a support level "
"only to be available for demos, experimentation, and further development uses and "
"should not be used for benchmarking until fully implemented.\n",
channel_number + 1);
}
if (config->pass > 1 && config->rate_control_mode == SVT_AV1_RC_MODE_CQP_OR_CRF) {
SVT_ERROR("Instance %u: CRF does not support Multi-pass. Use single pass\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// color description
if (config->color_primaries == 0 || config->color_primaries == 3 ||
(config->color_primaries >= 13 && config->color_primaries <= 21) || config->color_primaries > 22) {
SVT_WARN(
"Instance %u: value %u for color_primaries is reserved and not recommended for "
"usage.\n",
channel_number + 1,
config->color_primaries);
}
if (config->transfer_characteristics == 0 || config->transfer_characteristics == 3 ||
config->transfer_characteristics > 18) {
SVT_WARN(
"Instance %u: value %u for transfer_characteristics is reserved and not recommended "
"for usage.\n",
channel_number + 1,
config->transfer_characteristics);
}
if (config->matrix_coefficients == 3 || config->matrix_coefficients > 14) {
SVT_WARN(
"Instance %u: value %u for matrix_coefficients is reserved and not recommended for "
"usage.\n",
channel_number + 1,
config->matrix_coefficients);
}
if (config->chroma_sample_position < EB_CSP_UNKNOWN || config->chroma_sample_position > EB_CSP_COLOCATED) {
if (config->chroma_sample_position != EB_CSP_RESERVED) {
SVT_ERROR("Instance %u: chroma sample position %d is unknown.\n",
channel_number + 1,
config->chroma_sample_position);
return_error = EB_ErrorBadParameter;
} else {
SVT_WARN(
"Instance %u: value %d for chroma_sample_position is reserved "
"and not recommended for usage.\n",
channel_number + 1,
config->chroma_sample_position);
}
}
if (config->film_grain_denoise_strength > 0 && config->enc_mode > 6) {
SVT_WARN(
"Instance %u: It is recommended to not use Film Grain for presets greater than 6 as it "
"produces a significant compute overhead. This combination should only be used for "
"debug purposes.\n",
channel_number + 1);
}
if (config->film_grain_denoise_strength > 50) {
SVT_ERROR(
"Instance %u: Film grain denoise strength is only supported for values between "
"[0,50]\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->film_grain_denoise_apply != 0 && config->film_grain_denoise_apply != 1) {
SVT_ERROR("Instance %u: The film grain denoise apply signal can only have a value of 0 or 1\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
// Limit 8K & 16K support
if ((uint64_t)(scs->max_input_luma_width * scs->max_input_luma_height) > INPUT_SIZE_4K_TH) {
SVT_WARN(
"Instance %u: 8K and higher resolution support is currently a work-in-progress "
"project, and is only available for demos, experimentation, and further development "
"uses and should not be used for benchmarking until fully implemented.\n",
channel_number + 1);
}
if (config->pred_structure == 1) {
if (config->tune == 0) {
SVT_WARN("Instance %u: Tune 0 is not applicable for low-delay, tune will be forced to 1.\n",
channel_number + 1);
config->tune = 1;
}
if (config->superres_mode != 0) {
SVT_ERROR("Instance %u: Superres is not supported for low-delay.\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->enable_overlays) {
SVT_ERROR("Instance %u: Overlay is not supported for low-delay.\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
}
if (scs->static_config.scene_change_detection) {
scs->static_config.scene_change_detection = 0;
SVT_WARN(
"SVT-AV1 has an integrated mode decision mechanism to handle scene changes and will "
"not insert a key frame at scene changes\n");
}
if ((config->tile_columns > 0 || config->tile_rows > 0)) {
SVT_WARN(
"If you are using tiles with the intent of increasing the decoder speed, please also "
"consider using --fast-decode 1, especially if the intended decoder is running with "
"limited multi-threading capabilities.\n");
}
if (config->tune == 0 && config->fast_decode > 0) {
SVT_WARN(
"--fast - decode has been developed and optimized with --tune 1. "
"Please use it with caution when encoding with --tune 0. You can also consider using "
"--tile-columns 1 if you are targeting a high quality encode and a multi-core "
"high-performance decoder HW\n");
}
if (config->enable_qm && config->min_qm_level > config->max_qm_level) {
SVT_ERROR("Instance %u: Min quant matrix level must not greater than max quant matrix level\n",
channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->startup_mg_size != 0 && config->startup_mg_size != 2 && config->startup_mg_size != 3 &&
config->startup_mg_size != 4) {
SVT_ERROR("Instance %u: Startup MG size supported [0, 2, 3, 4]\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->startup_mg_size >= config->hierarchical_levels) {
SVT_ERROR("Instance %u: Startup MG size must less than Hierarchical Levels\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->startup_mg_size != 0 && config->rate_control_mode != 0) {
SVT_ERROR("Instance %u: Startup MG size feature only supports CRF/CQP rate control mode\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->variance_boost_strength > 5) {
SVT_ERROR("Instance %u: Variance boost strength must be between 0 and 5\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
if (config->new_variance_octile > 8) {
SVT_ERROR("Instance %u: New (8x8) variance octile must be between 0 and 8\n", channel_number + 1);
return_error = EB_ErrorBadParameter;
}
return return_error;
}
/**********************************
Set Default Library Params
**********************************/
EbErrorType svt_av1_set_default_params(EbSvtAv1EncConfiguration *config_ptr) {
EbErrorType return_error = EB_ErrorNone;
if (!config_ptr) {
SVT_ERROR("The EbSvtAv1EncConfiguration structure is empty!\n");
return EB_ErrorBadParameter;
}
config_ptr->frame_rate_numerator = 60000;
config_ptr->frame_rate_denominator = 1000;
config_ptr->encoder_bit_depth = 8;
config_ptr->source_width = 0;
config_ptr->source_height = 0;
config_ptr->forced_max_frame_width = 0;
config_ptr->forced_max_frame_height = 0;
config_ptr->stat_report = 0;
config_ptr->tile_rows = DEFAULT;
config_ptr->tile_columns = DEFAULT;
config_ptr->qp = DEFAULT_QP;
config_ptr->use_qp_file = FALSE;
config_ptr->use_fixed_qindex_offsets = 0;
memset(config_ptr->qindex_offsets, 0, sizeof(config_ptr->qindex_offsets));
config_ptr->key_frame_chroma_qindex_offset = 0;
config_ptr->key_frame_qindex_offset = 0;
memset(config_ptr->chroma_qindex_offsets, 0, sizeof(config_ptr->chroma_qindex_offsets));
config_ptr->luma_y_dc_qindex_offset = 0;
config_ptr->chroma_u_dc_qindex_offset = 0;
config_ptr->chroma_u_ac_qindex_offset = 0;
config_ptr->chroma_v_dc_qindex_offset = 0;
config_ptr->chroma_v_ac_qindex_offset = 0;
for (int i = 0; i < SVT_AV1_FRAME_UPDATE_TYPES; i++) config_ptr->lambda_scale_factors[i] = 128;
config_ptr->scene_change_detection = 0;
config_ptr->rate_control_mode = SVT_AV1_RC_MODE_CQP_OR_CRF;
config_ptr->look_ahead_distance = (uint32_t)~0;
config_ptr->enable_tpl_la = 1;
config_ptr->target_bit_rate = 2000000;
config_ptr->max_bit_rate = 0;
config_ptr->max_qp_allowed = 63;
config_ptr->min_qp_allowed = 1;
config_ptr->enable_adaptive_quantization = 2;
config_ptr->enc_mode = 10;
config_ptr->intra_period_length = -2;
config_ptr->multiply_keyint = FALSE;
config_ptr->intra_refresh_type = 2;
config_ptr->hierarchical_levels = 0;
config_ptr->pred_structure = SVT_AV1_PRED_RANDOM_ACCESS;
config_ptr->enable_dlf_flag = TRUE;
config_ptr->cdef_level = DEFAULT;
config_ptr->enable_restoration_filtering = DEFAULT;
config_ptr->enable_mfmv = DEFAULT;
config_ptr->enable_dg = 1;
config_ptr->fast_decode = 0;
config_ptr->encoder_color_format = EB_YUV420;
// Rate control options
// Set the default value toward more flexible rate allocation
#if !SVT_AV1_CHECK_VERSION(2, 0, 0)
config_ptr->vbr_bias_pct = 100;
#endif
config_ptr->vbr_min_section_pct = 0;
config_ptr->vbr_max_section_pct = 2000;
config_ptr->under_shoot_pct = (uint32_t)DEFAULT;
config_ptr->over_shoot_pct = (uint32_t)DEFAULT;
config_ptr->mbr_over_shoot_pct = 50;
config_ptr->gop_constraint_rc = 0;
config_ptr->maximum_buffer_size_ms = 1000; // default settings for CBR
config_ptr->starting_buffer_level_ms = 600; // default settings for CBR
config_ptr->optimal_buffer_level_ms = 600; // default settings for CBR
config_ptr->recode_loop = ALLOW_RECODE_DEFAULT;
config_ptr->restricted_motion_vector = FALSE;
config_ptr->high_dynamic_range_input = 0;
config_ptr->screen_content_mode = 2;
// Annex A parameters
config_ptr->profile = 0;
config_ptr->tier = 0;
config_ptr->level = 0;
// Latency
config_ptr->film_grain_denoise_strength = 0;
config_ptr->film_grain_denoise_apply = 1;
// CPU Flags
config_ptr->use_cpu_flags = EB_CPU_FLAGS_ALL;
// Channel info
config_ptr->logical_processors = 0;
config_ptr->pin_threads = 0;
config_ptr->target_socket = -1;
config_ptr->channel_id = 0;
config_ptr->active_channel_count = 1;
// Debug info
config_ptr->recon_enabled = 0;
// Alt-Ref default values
config_ptr->enable_tf = TRUE;
config_ptr->enable_overlays = FALSE;
config_ptr->tune = 1;
// Super-resolution default values
config_ptr->superres_mode = SUPERRES_NONE;
config_ptr->superres_denom = SCALE_NUMERATOR;
config_ptr->superres_kf_denom = SCALE_NUMERATOR;
config_ptr->superres_qthres = 43; // random threshold, change
config_ptr->superres_kf_qthres = 43; // random threshold, change
// Reference Scaling default values
config_ptr->resize_mode = RESIZE_NONE;
config_ptr->resize_denom = SCALE_NUMERATOR;
config_ptr->resize_kf_denom = SCALE_NUMERATOR;
// Color description default values
config_ptr->color_description_present_flag = FALSE;
config_ptr->color_primaries = 2;