1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <assert.h>
15#include <math.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
24#include "common/args.h"
25#include "common/tools_common.h"
26#include "common/video_writer.h"
27#include "examples/encoder_util.h"
28#include "aom_ports/aom_timer.h"
29
30#define OPTION_BUFFER_SIZE 1024
31
32typedef struct {
33 const char *output_filename;
34 char options[OPTION_BUFFER_SIZE];
35 struct AvxInputContext input_ctx;
36 int speed;
37 int aq_mode;
38 int layering_mode;
39 int output_obu;
40} AppInput;
41
42typedef enum {
43 QUANTIZER = 0,
44 BITRATE,
45 SCALE_FACTOR,
46 AUTO_ALT_REF,
47 ALL_OPTION_TYPES
48} LAYER_OPTION_TYPE;
49
50static const arg_def_t outputfile =
51 ARG_DEF("o", "output", 1, "Output filename");
52static const arg_def_t frames_arg =
53 ARG_DEF("f", "frames", 1, "Number of frames to encode");
54static const arg_def_t threads_arg =
55 ARG_DEF("th", "threads", 1, "Number of threads to use");
56static const arg_def_t width_arg = ARG_DEF("w", "width", 1, "Source width");
57static const arg_def_t height_arg = ARG_DEF("h", "height", 1, "Source height");
58static const arg_def_t timebase_arg =
59 ARG_DEF("t", "timebase", 1, "Timebase (num/den)");
60static const arg_def_t bitrate_arg = ARG_DEF(
61 "b", "target-bitrate", 1, "Encoding bitrate, in kilobits per second");
62static const arg_def_t spatial_layers_arg =
63 ARG_DEF("sl", "spatial-layers", 1, "Number of spatial SVC layers");
64static const arg_def_t temporal_layers_arg =
65 ARG_DEF("tl", "temporal-layers", 1, "Number of temporal SVC layers");
66static const arg_def_t layering_mode_arg =
67 ARG_DEF("lm", "layering-mode", 1, "Temporal layering scheme.");
68static const arg_def_t kf_dist_arg =
69 ARG_DEF("k", "kf-dist", 1, "Number of frames between keyframes");
70static const arg_def_t scale_factors_arg =
71 ARG_DEF("r", "scale-factors", 1, "Scale factors (lowest to highest layer)");
72static const arg_def_t min_q_arg =
73 ARG_DEF(NULL, "min-q", 1, "Minimum quantizer");
74static const arg_def_t max_q_arg =
75 ARG_DEF(NULL, "max-q", 1, "Maximum quantizer");
76static const arg_def_t speed_arg =
77 ARG_DEF("sp", "speed", 1, "Speed configuration");
78static const arg_def_t aqmode_arg =
79 ARG_DEF("aq", "aqmode", 1, "AQ mode off/on");
80static const arg_def_t bitrates_arg =
81 ARG_DEF("bl", "bitrates", 1,
82 "Bitrates[spatial_layer * num_temporal_layer + temporal_layer]");
83static const arg_def_t dropframe_thresh_arg =
84 ARG_DEF(NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)");
85static const arg_def_t error_resilient_arg =
86 ARG_DEF(NULL, "error-resilient", 1, "Error resilient flag");
87static const arg_def_t output_obu_arg =
88 ARG_DEF(NULL, "output-obu", 1,
89 "Write OBUs when set to 1. Otherwise write IVF files.");
90
91#if CONFIG_AV1_HIGHBITDEPTH
92static const struct arg_enum_list bitdepth_enum[] = {
94};
95
96static const arg_def_t bitdepth_arg = ARG_DEF_ENUM(
97 "d", "bit-depth", 1, "Bit depth for codec 8, 10 or 12. ", bitdepth_enum);
98#endif
99
100static const arg_def_t *svc_args[] = {
101 &frames_arg, &outputfile, &width_arg,
102 &height_arg, &timebase_arg, &bitrate_arg,
103 &spatial_layers_arg, &kf_dist_arg, &scale_factors_arg,
104 &min_q_arg, &max_q_arg, &temporal_layers_arg,
105 &layering_mode_arg, &threads_arg, &aqmode_arg,
106#if CONFIG_AV1_HIGHBITDEPTH
107 &bitdepth_arg,
108#endif
109 &speed_arg, &bitrates_arg, &dropframe_thresh_arg,
110 &error_resilient_arg, &output_obu_arg, NULL
111};
112
113#define zero(Dest) memset(&(Dest), 0, sizeof(Dest));
114
115static const char *exec_name;
116
117void usage_exit(void) {
118 fprintf(stderr, "Usage: %s <options> input_filename -o output_filename\n",
119 exec_name);
120 fprintf(stderr, "Options:\n");
121 arg_show_usage(stderr, svc_args);
122 exit(EXIT_FAILURE);
123}
124
125static int file_is_y4m(const char detect[4]) {
126 return memcmp(detect, "YUV4", 4) == 0;
127}
128
129static int fourcc_is_ivf(const char detect[4]) {
130 if (memcmp(detect, "DKIF", 4) == 0) {
131 return 1;
132 }
133 return 0;
134}
135
136static const int option_max_values[ALL_OPTION_TYPES] = { 63, INT_MAX, INT_MAX,
137 1 };
138
139static const int option_min_values[ALL_OPTION_TYPES] = { 0, 0, 1, 0 };
140
141static void open_input_file(struct AvxInputContext *input,
143
144 input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb")
145 : set_binary_mode(stdin);
146
147 if (!input->file) fatal("Failed to open input file");
148
149 if (!fseeko(input->file, 0, SEEK_END)) {
150
151
152
153 input->length = ftello(input->file);
154 rewind(input->file);
155 }
156
157
158 input->pixel_aspect_ratio.numerator = 1;
159 input->pixel_aspect_ratio.denominator = 1;
160
161
162
163
164 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
165 input->detect.position = 0;
166
167 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
168 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
169 input->only_i420) >= 0) {
170 input->file_type = FILE_TYPE_Y4M;
171 input->width = input->y4m.pic_w;
172 input->height = input->y4m.pic_h;
173 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
174 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
175 input->framerate.numerator = input->y4m.fps_n;
176 input->framerate.denominator = input->y4m.fps_d;
177 input->fmt = input->y4m.aom_fmt;
178 input->bit_depth = input->y4m.bit_depth;
179 } else {
180 fatal("Unsupported Y4M stream.");
181 }
182 } else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
183 fatal("IVF is not supported as input.");
184 } else {
185 input->file_type = FILE_TYPE_RAW;
186 }
187}
188
189static aom_codec_err_t extract_option(LAYER_OPTION_TYPE type,
char *input,
190 int *value0, int *value1) {
191 if (type == SCALE_FACTOR) {
192 *value0 = (int)strtol(input, &input, 10);
194 *value1 = (int)strtol(input, &input, 10);
195
196 if (*value0 < option_min_values[SCALE_FACTOR] ||
197 *value1 < option_min_values[SCALE_FACTOR] ||
198 *value0 > option_max_values[SCALE_FACTOR] ||
199 *value1 > option_max_values[SCALE_FACTOR] ||
200 *value0 > *value1)
202 } else {
203 *value0 = atoi(input);
204 if (*value0 < option_min_values[type] || *value0 > option_max_values[type])
206 }
208}
209
212 int *option0, int *option1) {
214 char *input_string;
215 char *token;
216 const char *delim = ",";
218 int i = 0;
219
220 if (type == BITRATE)
221 num_layers =
223
224 if (input == NULL || option0 == NULL ||
225 (option1 == NULL && type == SCALE_FACTOR))
227
228 input_string = malloc(strlen(input));
229 memcpy(input_string, input, strlen(input));
231 token = strtok(input_string, delim);
232 for (i = 0; i < num_layers; ++i) {
233 if (token != NULL) {
234 res = extract_option(type, token, option0 + i, option1 + i);
236 token = strtok(NULL, delim);
237 } else {
238 break;
239 }
240 }
243 }
244 free(input_string);
245 return res;
246}
247
248static void parse_command_line(int argc, const char **argv_,
249 AppInput *app_input,
252 struct arg arg;
253 char **argv = NULL;
254 char **argi = NULL;
255 char **argj = NULL;
256 char string_options[1024] = { 0 };
257
258
261 app_input->layering_mode = 0;
262 app_input->output_obu = 0;
265
266
267 argv = argv_dup(argc - 1, argv_ + 1);
268 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
269 arg.argv_step = 1;
270
271 if (arg_match(&arg, &outputfile, argi)) {
272 app_input->output_filename = arg.val;
273 } else if (arg_match(&arg, &width_arg, argi)) {
274 enc_cfg->
g_w = arg_parse_uint(&arg);
275 } else if (arg_match(&arg, &height_arg, argi)) {
276 enc_cfg->
g_h = arg_parse_uint(&arg);
277 } else if (arg_match(&arg, &timebase_arg, argi)) {
278 enc_cfg->
g_timebase = arg_parse_rational(&arg);
279 } else if (arg_match(&arg, &bitrate_arg, argi)) {
281 } else if (arg_match(&arg, &spatial_layers_arg, argi)) {
283 } else if (arg_match(&arg, &temporal_layers_arg, argi)) {
285 } else if (arg_match(&arg, &speed_arg, argi)) {
286 app_input->speed = arg_parse_uint(&arg);
287 if (app_input->speed > 9) {
288 warn("Mapping speed %d to speed 9.\n", app_input->speed);
289 }
290 } else if (arg_match(&arg, &aqmode_arg, argi)) {
291 app_input->aq_mode = arg_parse_uint(&arg);
292 } else if (arg_match(&arg, &threads_arg, argi)) {
293 enc_cfg->
g_threads = arg_parse_uint(&arg);
294 } else if (arg_match(&arg, &layering_mode_arg, argi)) {
295 app_input->layering_mode = arg_parse_int(&arg);
296 } else if (arg_match(&arg, &kf_dist_arg, argi)) {
299 } else if (arg_match(&arg, &scale_factors_arg, argi)) {
300 parse_layer_options_from_string(svc_params, SCALE_FACTOR, arg.val,
303 } else if (arg_match(&arg, &min_q_arg, argi)) {
305 } else if (arg_match(&arg, &max_q_arg, argi)) {
307#if CONFIG_AV1_HIGHBITDEPTH
308 } else if (arg_match(&arg, &bitdepth_arg, argi)) {
309 enc_cfg->
g_bit_depth = arg_parse_enum_or_int(&arg);
314 break;
318 break;
322 break;
323 default:
324 die(
"Error: Invalid bit depth selected (%d)\n", enc_cfg->
g_bit_depth);
325 break;
326 }
327#endif
328 } else if (arg_match(&arg, &dropframe_thresh_arg, argi)) {
330 } else if (arg_match(&arg, &error_resilient_arg, argi)) {
333 die("Invalid value for error resilient (0, 1): %d.",
335 } else if (arg_match(&arg, &output_obu_arg, argi)) {
336 app_input->output_obu = arg_parse_uint(&arg);
337 if (app_input->output_obu != 0 && app_input->output_obu != 1)
338 die("Invalid value for obu output flag (0, 1): %d.",
339 app_input->output_obu);
340 } else {
341 ++argj;
342 }
343 }
344
345
346 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
347 arg.argv_step = 1;
348 if (arg_match(&arg, &bitrates_arg, argi)) {
349 parse_layer_options_from_string(svc_params, BITRATE, arg.val,
351 } else {
352 ++argj;
353 }
354 }
355
356
357 if (strlen(string_options) > 0)
358 strncpy(app_input->options, string_options, OPTION_BUFFER_SIZE);
359
360
361 for (argi = argv; *argi; ++argi)
362 if (argi[0][0] == '-' && strlen(argi[0]) > 1)
363 die("Error: Unrecognized option %s\n", *argi);
364
365 if (argv[0] == NULL) {
366 usage_exit();
367 }
368
369 app_input->input_ctx.filename = argv[0];
370 free(argv);
371
372 open_input_file(&app_input->input_ctx, 0);
373 if (app_input->input_ctx.file_type == FILE_TYPE_Y4M) {
374 enc_cfg->
g_w = app_input->input_ctx.width;
375 enc_cfg->
g_h = app_input->input_ctx.height;
376 }
377
378 if (enc_cfg->
g_w < 16 || enc_cfg->
g_w % 2 || enc_cfg->
g_h < 16 ||
380 die(
"Invalid resolution: %d x %d\n", enc_cfg->
g_w, enc_cfg->
g_h);
381
382 printf(
383 "Codec %s\n"
384 "layers: %d\n"
385 "width %u, height: %u\n"
386 "num: %d, den: %d, bitrate: %u\n"
387 "gop size: %u\n",
392}
393
394static unsigned int mode_to_num_temporal_layers[11] = { 1, 2, 3, 3, 2, 1,
395 1, 3, 3, 3, 3 };
396static unsigned int mode_to_num_spatial_layers[11] = { 1, 1, 1, 1, 1, 2,
397 3, 2, 3, 3, 3 };
398
399
400struct RateControlMetrics {
401
403
405
407
409
411
413
415
416
417 double avg_st_encoding_bitrate;
418
419 double variance_st_encoding_bitrate;
420
421 int window_size;
422
423 int window_count;
425};
426
427
428enum {
429 SVC_LAST_FRAME = 0,
430 SVC_LAST2_FRAME,
431 SVC_LAST3_FRAME,
432 SVC_GOLDEN_FRAME,
433 SVC_BWDREF_FRAME,
434 SVC_ALTREF2_FRAME,
435 SVC_ALTREF_FRAME
436};
437
438static int read_frame(
struct AvxInputContext *input_ctx,
aom_image_t *img) {
439 FILE *f = input_ctx->file;
440 y4m_input *y4m = &input_ctx->y4m;
441 int shortread = 0;
442
443 if (input_ctx->file_type == FILE_TYPE_Y4M) {
444 if (y4m_input_fetch_frame(y4m, f, img) < 1) return 0;
445 } else {
446 shortread = read_yuv_frame(input_ctx, img);
447 }
448
449 return !shortread;
450}
451
452static void close_input_file(struct AvxInputContext *input) {
453 fclose(input->file);
454 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
455}
456
457
458
459
460
461
462
463static void set_rate_control_metrics(struct RateControlMetrics *rc,
464 double framerate,
465 unsigned int ss_number_layers,
466 unsigned int ts_number_layers) {
468 ts_rate_decimator[0] = 1;
469 if (ts_number_layers == 2) {
470 ts_rate_decimator[0] = 2;
471 ts_rate_decimator[1] = 1;
472 }
473 if (ts_number_layers == 3) {
474 ts_rate_decimator[0] = 4;
475 ts_rate_decimator[1] = 2;
476 ts_rate_decimator[2] = 1;
477 }
478
479
480 for (unsigned int sl = 0; sl < ss_number_layers; ++sl) {
481 unsigned int i = sl * ts_number_layers;
482 rc->layer_framerate[0] = framerate / ts_rate_decimator[0];
483 rc->layer_pfb[i] =
484 1000.0 * rc->layer_target_bitrate[i] / rc->layer_framerate[0];
485 for (unsigned int tl = 0; tl < ts_number_layers; ++tl) {
486 i = sl * ts_number_layers + tl;
487 if (tl > 0) {
488 rc->layer_framerate[tl] = framerate / ts_rate_decimator[tl];
489 rc->layer_pfb[i] =
490 1000.0 *
491 (rc->layer_target_bitrate[i] - rc->layer_target_bitrate[i - 1]) /
492 (rc->layer_framerate[tl] - rc->layer_framerate[tl - 1]);
493 }
494 rc->layer_input_frames[tl] = 0;
495 rc->layer_enc_frames[tl] = 0;
496 rc->layer_encoding_bitrate[i] = 0.0;
497 rc->layer_avg_frame_size[i] = 0.0;
498 rc->layer_avg_rate_mismatch[i] = 0.0;
499 }
500 }
501 rc->window_count = 0;
502 rc->window_size = 15;
503 rc->avg_st_encoding_bitrate = 0.0;
504 rc->variance_st_encoding_bitrate = 0.0;
505}
506
507static void printout_rate_control_summary(struct RateControlMetrics *rc,
508 int frame_cnt,
509 unsigned int ss_number_layers,
510 unsigned int ts_number_layers) {
511 int tot_num_frames = 0;
512 double perc_fluctuation = 0.0;
513 printf("Total number of processed frames: %d\n\n", frame_cnt - 1);
514 printf("Rate control layer stats for %u layer(s):\n\n", ts_number_layers);
515 for (unsigned int sl = 0; sl < ss_number_layers; ++sl) {
516 tot_num_frames = 0;
517 for (unsigned int tl = 0; tl < ts_number_layers; ++tl) {
518 unsigned int i = sl * ts_number_layers + tl;
519 const int num_dropped =
520 tl > 0 ? rc->layer_input_frames[tl] - rc->layer_enc_frames[tl]
521 : rc->layer_input_frames[tl] - rc->layer_enc_frames[tl] - 1;
522 tot_num_frames += rc->layer_input_frames[tl];
523 rc->layer_encoding_bitrate[i] = 0.001 * rc->layer_framerate[tl] *
524 rc->layer_encoding_bitrate[i] /
525 tot_num_frames;
526 rc->layer_avg_frame_size[i] =
527 rc->layer_avg_frame_size[i] / rc->layer_enc_frames[tl];
528 rc->layer_avg_rate_mismatch[i] =
529 100.0 * rc->layer_avg_rate_mismatch[i] / rc->layer_enc_frames[tl];
530 printf("For layer#: %u %u \n", sl, tl);
531 printf("Bitrate (target vs actual): %d %f\n", rc->layer_target_bitrate[i],
532 rc->layer_encoding_bitrate[i]);
533 printf("Average frame size (target vs actual): %f %f\n", rc->layer_pfb[i],
534 rc->layer_avg_frame_size[i]);
535 printf("Average rate_mismatch: %f\n", rc->layer_avg_rate_mismatch[i]);
536 printf(
537 "Number of input frames, encoded (non-key) frames, "
538 "and perc dropped frames: %d %d %f\n",
539 rc->layer_input_frames[tl], rc->layer_enc_frames[tl],
540 100.0 * num_dropped / rc->layer_input_frames[tl]);
541 printf("\n");
542 }
543 }
544 rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
545 rc->variance_st_encoding_bitrate =
546 rc->variance_st_encoding_bitrate / rc->window_count -
547 (rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
548 perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
549 rc->avg_st_encoding_bitrate;
550 printf("Short-time stats, for window of %d frames:\n", rc->window_size);
551 printf("Average, rms-variance, and percent-fluct: %f %f %f\n",
552 rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
553 perc_fluctuation);
554 if (frame_cnt - 1 != tot_num_frames)
555 die("Error: Number of input frames not equal to output!\n");
556}
557
558
559static void set_layer_pattern(int layering_mode, int superframe_cnt,
562 int *use_svc_control, int spatial_layer_id,
563 int is_key_frame, int ksvc_mode) {
564 int i;
565 int enable_longterm_temporal_ref = 1;
566 int shift = (layering_mode == 8) ? 2 : 0;
567 *use_svc_control = 1;
569 int lag_index = 0;
570 int base_count = superframe_cnt >> 2;
571
572
573
574 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->
ref_idx[i] = i;
575 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->
reference[i] = 0;
576 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->
refresh[i] = 0;
577
578 if (ksvc_mode) {
579
580 layering_mode = 9;
581 if (!is_key_frame)
582
583 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
584 }
585 switch (layering_mode) {
586 case 0:
587
589 ref_frame_config->
refresh[0] = 1;
590 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
591 break;
592 case 1:
593
594
595
596 if (superframe_cnt % 2 == 0) {
598
599 ref_frame_config->
refresh[0] = 1;
600 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
601 } else {
603
604 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
605 }
606 break;
607 case 2:
608
609
610
611
612 if (superframe_cnt % 4 == 0) {
613
615
616 ref_frame_config->
refresh[0] = 1;
617 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
618 } else if ((superframe_cnt - 1) % 4 == 0) {
620
621 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
622 } else if ((superframe_cnt - 2) % 4 == 0) {
624
625 ref_frame_config->
refresh[1] = 1;
626 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
627 } else if ((superframe_cnt - 3) % 4 == 0) {
629
630
631
632 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
633 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 0;
634 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
635 }
636 break;
637 case 3:
638
639
640
641
642
643
644
645 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
646
647 lag_index = 4 + (base_count % 4);
648
649 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = lag_index;
650 if (superframe_cnt % 4 == 0) {
651
653
654 ref_frame_config->
refresh[0] = 1;
655 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
656
657 if (base_count % 10 == 0) ref_frame_config->
refresh[3] = 1;
658
659 ref_frame_config->
refresh[lag_index] = 1;
660 } else if ((superframe_cnt - 1) % 4 == 0) {
662
663 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
664 } else if ((superframe_cnt - 2) % 4 == 0) {
666
667 ref_frame_config->
refresh[1] = 1;
668 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
669 } else if ((superframe_cnt - 3) % 4 == 0) {
671
672
673
674 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
675 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 0;
676 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
677 }
678
679 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
680 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
681 break;
682 case 4:
683
684
685
686
687
688 if (superframe_cnt % 4 == 0) {
689
691
692 ref_frame_config->
refresh[0] = 1;
693 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
694 } else if ((superframe_cnt - 1) % 4 == 0) {
696
697 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
698 } else if ((superframe_cnt - 2) % 4 == 0) {
700
701 ref_frame_config->
refresh[3] = 1;
702 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
703 } else if ((superframe_cnt - 3) % 4 == 0) {
705
706 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
707 }
708 break;
709 case 5:
710
713
714 ref_frame_config->
refresh[0] = 1;
715 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
717
718
719 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
720 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 0;
721 ref_frame_config->
refresh[1] = 1;
722 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
723 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
724 }
725 break;
726 case 6:
727
728
729
730
731
734
735 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
736 ref_frame_config->
ref_idx[i] = 0;
737 ref_frame_config->
refresh[0] = 1;
738 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
740
741
742
743 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
744 ref_frame_config->
ref_idx[i] = 0;
745 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
746 ref_frame_config->
refresh[1] = 1;
747 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
748 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
750
751
752
753 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
754 ref_frame_config->
ref_idx[i] = 1;
755 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
756 ref_frame_config->
refresh[2] = 1;
757 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
758 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
759
760
761 if (enable_longterm_temporal_ref) {
762 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = REF_FRAMES - 1;
763 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
764 if (base_count % 10 == 0)
765 ref_frame_config->
refresh[REF_FRAMES - 1] = 1;
766 }
767 }
768 break;
769 case 7:
770
771 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
772 if (superframe_cnt % 4 == 0) {
773
776
777
778 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
779 ref_frame_config->
ref_idx[i] = 0;
780 ref_frame_config->
refresh[0] = 1;
782
783 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
784 ref_frame_config->
ref_idx[i] = 0;
785 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
786 ref_frame_config->
refresh[1] = 1;
787 }
788 } else if ((superframe_cnt - 1) % 4 == 0) {
789
792 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
793 ref_frame_config->
ref_idx[i] = 0;
794 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
795 ref_frame_config->
refresh[3] = 1;
797
798
799
800 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
801 ref_frame_config->
ref_idx[i] = 3;
802 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
803 }
804 } else if ((superframe_cnt - 2) % 4 == 0) {
805
808
809
810
811 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
812 ref_frame_config->
ref_idx[i] = 0;
813 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5 - shift;
814 ref_frame_config->
refresh[5 - shift] = 1;
816
817
818
819 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
820 ref_frame_config->
ref_idx[i] = 5 - shift;
821 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
822 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 6 - shift;
823 ref_frame_config->
refresh[6 - shift] = 1;
824 }
825 } else if ((superframe_cnt - 3) % 4 == 0) {
826
829
830
831
832 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
833 ref_frame_config->
ref_idx[i] = 0;
834 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5 - shift;
835 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
836 ref_frame_config->
refresh[3] = 1;
838
839
840 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
841 ref_frame_config->
ref_idx[i] = 0;
842 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 6 - shift;
843 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
844 }
845 }
847
848 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
849 }
850 break;
851 case 8:
852
853
854
855
856
857
858 case 9:
859
860
861
862
863
864 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
865 if (superframe_cnt % 4 == 0) {
866
869
870
871 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
872 ref_frame_config->
ref_idx[i] = 0;
873 ref_frame_config->
refresh[0] = 1;
875
876
877
878 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
879 ref_frame_config->
ref_idx[i] = 0;
880 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
881 ref_frame_config->
refresh[1] = 1;
883
884
885
886 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
887 ref_frame_config->
ref_idx[i] = 1;
888 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
889 ref_frame_config->
refresh[2] = 1;
890 }
891 } else if ((superframe_cnt - 1) % 4 == 0) {
892
895
896
897
898 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
899 ref_frame_config->
ref_idx[i] = 0;
900 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
901 ref_frame_config->
refresh[3] = 1;
903
904
905
906 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
907 ref_frame_config->
ref_idx[i] = 3;
908 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
909 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 4;
910 ref_frame_config->
refresh[4] = 1;
912
913
914
915 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
916 ref_frame_config->
ref_idx[i] = 4;
917 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
918 }
919 } else if ((superframe_cnt - 2) % 4 == 0) {
920
923
924
925
926 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
927 ref_frame_config->
ref_idx[i] = 0;
928 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5 - shift;
929 ref_frame_config->
refresh[5 - shift] = 1;
931
932
933
934 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
935 ref_frame_config->
ref_idx[i] = 5 - shift;
936 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
937 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 6 - shift;
938 ref_frame_config->
refresh[6 - shift] = 1;
940
941
942
943 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
944 ref_frame_config->
ref_idx[i] = 6 - shift;
945 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
946 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 7 - shift;
947 ref_frame_config->
refresh[7 - shift] = 1;
948 }
949 } else if ((superframe_cnt - 3) % 4 == 0) {
950
953
954
955
956 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
957 ref_frame_config->
ref_idx[i] = 0;
958 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5 - shift;
959 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
960 ref_frame_config->
refresh[3] = 1;
962
963
964 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
965 ref_frame_config->
ref_idx[i] = 0;
966 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 6 - shift;
967 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
968 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 4;
969 ref_frame_config->
refresh[4] = 1;
971
972
973 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
974 ref_frame_config->
ref_idx[i] = 0;
975 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 7 - shift;
976 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 4;
977 }
978 }
980
981 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
982
983
984
985
987 layering_mode == 8) {
988 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = REF_FRAMES - 1;
989 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
991 ref_frame_config->
refresh[REF_FRAMES - 1] = 1;
992 }
993 break;
994 default: assert(0); die("Error: Unsupported temporal layering mode!\n");
995 }
996}
997
998#if CONFIG_AV1_DECODER
1000 const int frames_out, int *mismatch_seen) {
1002
1003 if (*mismatch_seen) return;
1004
1005
1008
1009#if CONFIG_AV1_HIGHBITDEPTH
1015 enc_img.
d_w, enc_img.
d_h, 16);
1016 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1017 enc_img = enc_hbd_img;
1018 }
1022 dec_img.
d_w, dec_img.
d_h, 16);
1023 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1024 dec_img = dec_hbd_img;
1025 }
1026 }
1027#endif
1028
1029 if (!aom_compare_img(&enc_img, &dec_img)) {
1030 int y[4], u[4], v[4];
1031#if CONFIG_AV1_HIGHBITDEPTH
1033 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1034 } else {
1035 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1036 }
1037#else
1038 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1039#endif
1041 printf(
1042 "Encode/decode mismatch on frame %d at"
1043 " Y[%d, %d] {%d/%d},"
1044 " U[%d, %d] {%d/%d},"
1045 " V[%d, %d] {%d/%d}",
1046 frames_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0], v[1],
1047 v[2], v[3]);
1048 *mismatch_seen = frames_out;
1049 }
1050
1053}
1054#endif
1055
1056int main(int argc, const char **argv) {
1057 AppInput app_input;
1060 AvxVideoWriter *total_layer_file = NULL;
1061 FILE *total_layer_obu_file = NULL;
1063 int frame_cnt = 0;
1065 int frame_avail;
1066 int got_data = 0;
1067 int flags = 0;
1068 unsigned i;
1069 int pts = 0;
1070 int frame_duration = 1;
1074
1075#if CONFIG_INTERNAL_STATS
1076 FILE *stats_file = fopen("opsnr.stt", "a");
1077 if (stats_file == NULL) {
1078 die("Cannot open opsnr.stt\n");
1079 }
1080#endif
1081#if CONFIG_AV1_DECODER
1082 int mismatch_seen = 0;
1084#endif
1085
1086 struct RateControlMetrics rc;
1087 int64_t cx_time = 0;
1088 int64_t cx_time_sl[3];
1089 double sum_bitrate = 0.0;
1090 double sum_bitrate2 = 0.0;
1091 double framerate = 30.0;
1092 int use_svc_control = 1;
1093 int set_err_resil_frame = 0;
1094 zero(rc.layer_target_bitrate);
1096 memset(&app_input, 0, sizeof(AppInput));
1097 memset(&svc_params, 0, sizeof(svc_params));
1098
1099
1100
1101 const int test_dynamic_scaling_single_layer = 0;
1102
1103
1104 app_input.input_ctx.framerate.numerator = 30;
1105 app_input.input_ctx.framerate.denominator = 1;
1106 app_input.input_ctx.only_i420 = 1;
1107 app_input.input_ctx.bit_depth = 0;
1108 exec_name = argv[0];
1109
1110
1113 if (res) {
1115 }
1116
1117
1119
1131
1132 parse_command_line(argc, argv, &app_input, &svc_params, &cfg);
1133
1136
1137 unsigned int width = cfg.
g_w;
1138 unsigned int height = cfg.
g_h;
1139
1140 if (app_input.layering_mode >= 0) {
1141 if (ts_number_layers !=
1142 mode_to_num_temporal_layers[app_input.layering_mode] ||
1143 ss_number_layers !=
1144 mode_to_num_spatial_layers[app_input.layering_mode]) {
1145 die("Number of layers doesn't match layering mode.");
1146 }
1147 }
1148
1149
1150 if (app_input.input_ctx.file_type != FILE_TYPE_Y4M) {
1152 die("Failed to allocate image", width, height);
1153 }
1154 }
1155
1157
1160
1161 unsigned int total_rate = 0;
1162 for (i = 0; i < ss_number_layers; i++) {
1163 total_rate +=
1164 svc_params
1166 }
1168 die("Incorrect total target bitrate");
1169 }
1170
1172 if (ts_number_layers == 2) {
1175 } else if (ts_number_layers == 3) {
1179 }
1180
1181 if (app_input.input_ctx.file_type == FILE_TYPE_Y4M) {
1182
1183 cfg.
g_w = app_input.input_ctx.width;
1184 cfg.
g_h = app_input.input_ctx.height;
1185
1186 cfg.
g_timebase.
num = app_input.input_ctx.framerate.denominator;
1187 cfg.
g_timebase.
den = app_input.input_ctx.framerate.numerator;
1188 }
1190 set_rate_control_metrics(&rc, framerate, ss_number_layers, ts_number_layers);
1191
1192 AvxVideoInfo info;
1193 info.codec_fourcc = get_fourcc_by_aom_encoder(encoder);
1194 info.frame_width = cfg.
g_w;
1195 info.frame_height = cfg.
g_h;
1198
1199 for (unsigned int sl = 0; sl < ss_number_layers; ++sl) {
1200 for (unsigned tl = 0; tl < ts_number_layers; ++tl) {
1201 i = sl * ts_number_layers + tl;
1202 char file_name[PATH_MAX];
1203 snprintf(file_name, sizeof(file_name), "%s_%u.av1",
1204 app_input.output_filename, i);
1205 if (app_input.output_obu) {
1206 obu_files[i] = fopen(file_name, "wb");
1207 if (!obu_files[i]) die("Failed to open %s for writing", file_name);
1208 } else {
1209 outfile[i] = aom_video_writer_open(file_name, kContainerIVF, &info);
1210 if (!outfile[i]) die("Failed to open %s for writing", file_name);
1211 }
1212 }
1213 }
1214 if (app_input.output_obu) {
1215 total_layer_obu_file = fopen(app_input.output_filename, "wb");
1216 if (!total_layer_obu_file)
1217 die("Failed to open %s for writing", app_input.output_filename);
1218 } else {
1219 total_layer_file =
1220 aom_video_writer_open(app_input.output_filename, kContainerIVF, &info);
1221 if (!total_layer_file)
1222 die("Failed to open %s for writing", app_input.output_filename);
1223 }
1224
1225
1228 die("Failed to initialize encoder");
1229
1230#if CONFIG_AV1_DECODER
1232 die("Failed to initialize decoder");
1233 }
1234#endif
1235
1250
1253 for (i = 0; i < ss_number_layers * ts_number_layers; ++i) {
1256 }
1257 for (i = 0; i < ss_number_layers; ++i) {
1260 }
1261 if (ss_number_layers == 2) {
1264 } else if (ss_number_layers == 3) {
1269 }
1271
1272
1273
1274
1275
1276 {
1277 const int max_intra_size_pct = 300;
1279 max_intra_size_pct);
1280 }
1281
1282 for (unsigned int slx = 0; slx < ss_number_layers; slx++) cx_time_sl[slx] = 0;
1283 frame_avail = 1;
1284 while (frame_avail || got_data) {
1285 struct aom_usec_timer timer;
1286 frame_avail = read_frame(&(app_input.input_ctx), &raw);
1287 int is_key_frame = (frame_cnt % cfg.
kf_max_dist) == 0;
1288
1289 for (unsigned int slx = 0; slx < ss_number_layers; slx++) {
1292 int layer = 0;
1293
1294
1295 if (app_input.layering_mode >= 0) {
1296
1297
1298 set_layer_pattern(app_input.layering_mode, frame_cnt, &layer_id,
1299 &ref_frame_config, &use_svc_control, slx,
1300 is_key_frame, (app_input.layering_mode == 10));
1302 if (use_svc_control)
1304 &ref_frame_config);
1305 } else {
1306
1307
1308
1311 if (ts_number_layers == 2) {
1313 } else if (ts_number_layers == 3) {
1314 if (frame_cnt % 2 != 0)
1316 else if ((frame_cnt > 1) && ((frame_cnt - 2) % 4 == 0))
1318 }
1320 }
1321
1322 if (set_err_resil_frame) {
1323
1324
1325 int err_resil_mode =
1328 err_resil_mode);
1329 }
1330
1332 if (frame_avail && slx == 0) ++rc.layer_input_frames[layer];
1333
1334 if (test_dynamic_scaling_single_layer) {
1335 if (frame_cnt >= 200 && frame_cnt <= 400) {
1336
1339 } else {
1340
1343 }
1344 }
1345
1346
1347 aom_usec_timer_start(&timer);
1349 die_codec(&codec, "Failed to encode frame");
1350 aom_usec_timer_mark(&timer);
1351 cx_time += aom_usec_timer_elapsed(&timer);
1352 cx_time_sl[slx] += aom_usec_timer_elapsed(&timer);
1353
1354 got_data = 0;
1356 got_data = 1;
1357 switch (pkt->
kind) {
1360 sl < ss_number_layers; ++sl) {
1362 tl < ts_number_layers; ++tl) {
1363 unsigned int j = sl * ts_number_layers + tl;
1364 if (app_input.output_obu) {
1366 obu_files[j]);
1367 } else {
1368 aom_video_writer_write_frame(outfile[j], pkt->
data.
frame.
buf,
1370 }
1372 rc.layer_encoding_bitrate[j] += 8.0 * pkt->
data.
frame.
sz;
1373 }
1374 }
1375
1376 if (app_input.output_obu) {
1378 total_layer_obu_file);
1379 } else {
1380 aom_video_writer_write_frame(total_layer_file,
1383 }
1384
1388 rc.layer_avg_frame_size[j] += 8.0 * pkt->
data.
frame.
sz;
1389 rc.layer_avg_rate_mismatch[j] +=
1390 fabs(8.0 * pkt->
data.
frame.
sz - rc.layer_pfb[j]) /
1391 rc.layer_pfb[j];
1393 }
1394
1395
1396
1397
1398
1399 if (frame_cnt > rc.window_size && slx == ss_number_layers - 1) {
1400 sum_bitrate += 0.001 * 8.0 * pkt->
data.
frame.
sz * framerate;
1401 rc.window_size = (rc.window_size <= 0) ? 1 : rc.window_size;
1402 if (frame_cnt % rc.window_size == 0) {
1403 rc.window_count += 1;
1404 rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
1405 rc.variance_st_encoding_bitrate +=
1406 (sum_bitrate / rc.window_size) *
1407 (sum_bitrate / rc.window_size);
1408 sum_bitrate = 0.0;
1409 }
1410 }
1411
1412 if (frame_cnt > rc.window_size + rc.window_size / 2 &&
1413 slx == ss_number_layers - 1) {
1414 sum_bitrate2 += 0.001 * 8.0 * pkt->
data.
frame.
sz * framerate;
1415 if (frame_cnt > 2 * rc.window_size &&
1416 frame_cnt % rc.window_size == 0) {
1417 rc.window_count += 1;
1418 rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
1419 rc.variance_st_encoding_bitrate +=
1420 (sum_bitrate2 / rc.window_size) *
1421 (sum_bitrate2 / rc.window_size);
1422 sum_bitrate2 = 0.0;
1423 }
1424 }
1425
1426#if CONFIG_AV1_DECODER
1429 die_codec(&decoder, "Failed to decode frame.");
1430#endif
1431
1432 break;
1433 default: break;
1434 }
1435 }
1436#if CONFIG_AV1_DECODER
1437
1438
1439 if ((ss_number_layers > 1 || ts_number_layers > 1) &&
1442 test_decode(&codec, &decoder, frame_cnt, &mismatch_seen);
1443 }
1444#endif
1445 }
1446 ++frame_cnt;
1447 pts += frame_duration;
1448 }
1449
1450 close_input_file(&(app_input.input_ctx));
1451 printout_rate_control_summary(&rc, frame_cnt, ss_number_layers,
1452 ts_number_layers);
1453 printf("\n");
1454 printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f\n",
1455 frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
1456 1000000 * (double)frame_cnt / (double)cx_time);
1457
1458 if (ss_number_layers > 1) {
1459 printf("Per spatial layer: \n");
1460 for (unsigned int slx = 0; slx < ss_number_layers; slx++)
1461 printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f\n",
1462 frame_cnt, (float)cx_time_sl[slx] / (double)(frame_cnt * 1000),
1463 1000000 * (double)frame_cnt / (double)cx_time_sl[slx]);
1464 }
1465
1467
1468#if CONFIG_INTERNAL_STATS
1469 if (mismatch_seen) {
1470 fprintf(stats_file, "First mismatch occurred in frame %d\n", mismatch_seen);
1471 } else {
1472 fprintf(stats_file, "No mismatch detected in recon buffers\n");
1473 }
1474 fclose(stats_file);
1475#endif
1476
1477
1478 for (i = 0; i < ss_number_layers * ts_number_layers; ++i)
1479 aom_video_writer_close(outfile[i]);
1480 aom_video_writer_close(total_layer_file);
1481
1482 if (app_input.input_ctx.file_type != FILE_TYPE_Y4M) {
1484 }
1485 return EXIT_SUCCESS;
1486}
Describes the encoder algorithm interface to applications.
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition aom_image.h:38
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
@ AOM_IMG_FMT_I420
Definition aom_image.h:45
struct aom_image aom_image_t
Image Descriptor.
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
Declares top-level encoder structures and functions.
#define AOM_MAX_LAYERS
Definition aomcx.h:1430
struct aom_svc_params aom_svc_params_t
#define AOM_MAX_TS_LAYERS
Definition aomcx.h:1432
aom_codec_iface_t * aom_codec_av1_cx(void)
The interface to the AV1 encoder.
struct aom_svc_layer_id aom_svc_layer_id_t
struct aom_svc_ref_frame_config aom_svc_ref_frame_config_t
@ AV1E_SET_ROW_MT
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition aomcx.h:350
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition aomcx.h:397
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition aomcx.h:457
@ AV1E_SET_SVC_LAYER_ID
Codec control function to set the layer id, aom_svc_layer_id_t* parameter.
Definition aomcx.h:1258
@ AV1E_SET_SVC_REF_FRAME_CONFIG
Codec control function to set reference frame config: the ref_idx and the refresh flags for each buff...
Definition aomcx.h:1269
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition aomcx.h:495
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition aomcx.h:1236
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition aomcx.h:1216
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition aomcx.h:654
@ AV1E_SET_SVC_PARAMS
Codec control function to set SVC paramaeters, aom_svc_params_t* parameter.
Definition aomcx.h:1263
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition aomcx.h:295
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition aomcx.h:431
@ AOME_SET_SCALEMODE
Codec control function to set encoder scaling mode, aom_scaling_mode_t* parameter.
Definition aomcx.h:195
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition aomcx.h:369
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition aomcx.h:849
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition aomcx.h:1113
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:213
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition aomcx.h:328
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition aomcx.h:1226
@ AV1_GET_NEW_FRAME_IMAGE
Codec control function to get a pointer to the new frame.
Definition aom.h:70
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
struct aom_codec_ctx aom_codec_ctx_t
Codec context structure.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:254
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
aom_codec_err_t
Algorithm return codes.
Definition aom_codec.h:155
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition aom_codec.h:520
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:288
#define AOM_FRAME_IS_KEY
Definition aom_codec.h:271
@ AOM_BITS_12
Definition aom_codec.h:321
@ AOM_BITS_8
Definition aom_codec.h:319
@ AOM_BITS_10
Definition aom_codec.h:320
@ AOM_CODEC_INVALID_PARAM
An application-supplied parameter is not valid.
Definition aom_codec.h:200
@ AOM_CODEC_MEM_ERROR
Memory operation failed.
Definition aom_codec.h:163
@ AOM_CODEC_OK
Operation completed without error.
Definition aom_codec.h:157
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, size_t data_sz, void *user_priv)
Decode data.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition aom_decoder.h:129
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
struct aom_codec_cx_pkt aom_codec_cx_pkt_t
Encoder output packet.
aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned long duration, aom_enc_frame_flags_t flags)
Encode a frame.
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition aom_encoder.h:931
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int usage)
Get the default configuration for a usage.
struct aom_codec_enc_cfg aom_codec_enc_cfg_t
Encoder configuration structure.
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition aom_encoder.h:1004
@ AOM_CBR
Definition aom_encoder.h:167
@ AOM_KF_AUTO
Definition aom_encoder.h:182
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:98
aom_codec_err_t err
Definition aom_codec.h:301
size_t sz
Definition aom_encoder.h:115
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:111
union aom_codec_cx_pkt::@202210014045072156205127107315337341215221351166 data
aom_codec_frame_flags_t flags
Definition aom_encoder.h:120
struct aom_codec_cx_pkt::@202210014045072156205127107315337341215221351166::@052232317104146204273007241322037340334334344046 frame
void * buf
Definition aom_encoder.h:114
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition aom_encoder.h:450
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition aom_encoder.h:515
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:464
unsigned int g_usage
Algorithm specific "usage" value.
Definition aom_encoder.h:379
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition aom_encoder.h:679
unsigned int g_h
Height of the frame.
Definition aom_encoder.h:415
enum aom_kf_mode kf_mode
Keyframe placement mode.
Definition aom_encoder.h:742
enum aom_rc_mode rc_end_usage
Rate control algorithm to use.
Definition aom_encoder.h:598
unsigned int g_threads
Maximum number of threads to use.
Definition aom_encoder.h:387
unsigned int kf_min_dist
Keyframe minimum interval.
Definition aom_encoder.h:751
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition aom_encoder.h:493
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition aom_encoder.h:688
unsigned int g_profile
Bitstream profile to use.
Definition aom_encoder.h:397
aom_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition aom_encoder.h:442
unsigned int g_w
Width of the frame.
Definition aom_encoder.h:406
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition aom_encoder.h:655
unsigned int kf_max_dist
Keyframe maximum interval.
Definition aom_encoder.h:760
aom_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition aom_encoder.h:472
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition aom_encoder.h:642
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition aom_encoder.h:697
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition aom_encoder.h:632
unsigned int rc_target_bitrate
Target data rate.
Definition aom_encoder.h:618
unsigned int rc_resize_mode
Mode for spatial resampling, if supported by the codec.
Definition aom_encoder.h:524
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition aom_encoder.h:664
aom_img_fmt_t fmt
Definition aom_image.h:172
unsigned int d_w
Definition aom_image.h:186
unsigned int d_h
Definition aom_image.h:187
int num
Definition aom_encoder.h:153
int den
Definition aom_encoder.h:154
aom image scaling mode
Definition aomcx.h:1394
int temporal_layer_id
Definition aomcx.h:1437
int spatial_layer_id
Definition aomcx.h:1436
int max_quantizers[32]
Definition aomcx.h:1444
int number_spatial_layers
Definition aomcx.h:1442
int layer_target_bitrate[32]
Definition aomcx.h:1449
int framerate_factor[8]
Definition aomcx.h:1451
int min_quantizers[32]
Definition aomcx.h:1445
int scaling_factor_den[4]
Definition aomcx.h:1447
int number_temporal_layers
Definition aomcx.h:1443
int scaling_factor_num[4]
Definition aomcx.h:1446
int reference[7]
Definition aomcx.h:1458
int refresh[8]
Definition aomcx.h:1461
int ref_idx[7]
Definition aomcx.h:1460