AOMedia Codec SDK: svc_encoder_rtc

AOMedia Codec SDK

svc_encoder_rtc
1 /*
2 * Copyright (c) 2019, Alliance for Open Media. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 // This is an example demonstrating how to implement a multi-layer AOM
12 // encoding scheme for RTC video applications.
13
14 #include <assert.h>
15 #include <math.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "aom/aom_encoder.h"
21 #include "aom/aomcx.h"
22 #include "av1/common/enums.h"
23 #include "common/tools_common.h"
24 #include "common/video_writer.h"
25 #include "aom_ports/aom_timer.h"
26
27 #define zero(Dest) memset(&(Dest), 0, sizeof(Dest));
28
29 static const char *exec_name;
30
31 void usage_exit(void) { exit(EXIT_FAILURE); }
32
33 static int mode_to_num_temporal_layers[10] = { 1, 2, 3, 3, 2, 1, 1, 3, 3, 3 };
34 static int mode_to_num_spatial_layers[10] = { 1, 1, 1, 1, 1, 2, 3, 3, 3, 3 };
35 static int mode_to_num_layers[10] = { 1, 2, 3, 3, 2, 2, 3, 9, 9, 9 };
36
37 // For rate control encoding stats.
38 struct RateControlMetrics {
39 // Number of input frames per layer.
40 int layer_input_frames[AOM_MAX_TS_LAYERS];
41 // Number of encoded non-key frames per layer.
42 int layer_enc_frames[AOM_MAX_TS_LAYERS];
43 // Framerate per layer layer (cumulative).
44 double layer_framerate[AOM_MAX_TS_LAYERS];
45 // Target average frame size per layer (per-frame-bandwidth per layer).
46 double layer_pfb[AOM_MAX_LAYERS];
47 // Actual average frame size per layer.
48 double layer_avg_frame_size[AOM_MAX_LAYERS];
49 // Average rate mismatch per layer (|target - actual| / target).
50 double layer_avg_rate_mismatch[AOM_MAX_LAYERS];
51 // Actual encoding bitrate per layer (cumulative across temporal layers).
52 double layer_encoding_bitrate[AOM_MAX_LAYERS];
53 // Average of the short-time encoder actual bitrate.
54 // TODO(marpan): Should we add these short-time stats for each layer?
55 double avg_st_encoding_bitrate;
56 // Variance of the short-time encoder actual bitrate.
57 double variance_st_encoding_bitrate;
58 // Window (number of frames) for computing short-timee encoding bitrate.
59 int window_size;
60 // Number of window measurements.
61 int window_count;
62 int layer_target_bitrate[AOM_MAX_LAYERS];
63 };
64
65 static int read_frame(struct AvxInputContext *input_ctx, aom_image_t *img) {
66 FILE *f = input_ctx->file;
67 y4m_input *y4m = &input_ctx->y4m;
68 int shortread = 0;
69
70 if (input_ctx->file_type == FILE_TYPE_Y4M) {
71 if (y4m_input_fetch_frame(y4m, f, img) < 1) return 0;
72 } else {
73 shortread = read_yuv_frame(input_ctx, img);
74 }
75
76 return !shortread;
77 }
78
79 static int file_is_y4m(const char detect[4]) {
80 if (memcmp(detect, "YUV4", 4) == 0) {
81 return 1;
82 }
83 return 0;
84 }
85
86 static int fourcc_is_ivf(const char detect[4]) {
87 if (memcmp(detect, "DKIF", 4) == 0) {
88 return 1;
89 }
90 return 0;
91 }
92
93 static void close_input_file(struct AvxInputContext *input) {
94 fclose(input->file);
95 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
96 }
97
98 static void open_input_file(struct AvxInputContext *input,
99 aom_chroma_sample_position_t csp) {
100 /* Parse certain options from the input file, if possible */
101 input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb")
102 : set_binary_mode(stdin);
103
104 if (!input->file) fatal("Failed to open input file");
105
106 if (!fseeko(input->file, 0, SEEK_END)) {
107 /* Input file is seekable. Figure out how long it is, so we can get
108 * progress info.
109 */
110 input->length = ftello(input->file);
111 rewind(input->file);
112 }
113
114 /* Default to 1:1 pixel aspect ratio. */
115 input->pixel_aspect_ratio.numerator = 1;
116 input->pixel_aspect_ratio.denominator = 1;
117
118 /* For RAW input sources, these bytes will applied on the first frame
119 * in read_frame().
120 */
121 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
122 input->detect.position = 0;
123
124 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
125 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
126 input->only_i420) >= 0) {
127 input->file_type = FILE_TYPE_Y4M;
128 input->width = input->y4m.pic_w;
129 input->height = input->y4m.pic_h;
130 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
131 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
132 input->framerate.numerator = input->y4m.fps_n;
133 input->framerate.denominator = input->y4m.fps_d;
134 input->fmt = input->y4m.aom_fmt;
135 input->bit_depth = input->y4m.bit_depth;
136 } else {
137 fatal("Unsupported Y4M stream.");
138 }
139 } else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
140 fatal("IVF is not supported as input.");
141 } else {
142 input->file_type = FILE_TYPE_RAW;
143 }
144 }
145
146 // Note: these rate control metrics assume only 1 key frame in the
147 // sequence (i.e., first frame only). So for temporal pattern# 7
148 // (which has key frame for every frame on base layer), the metrics
149 // computation will be off/wrong.
150 // TODO(marpan): Update these metrics to account for multiple key frames
151 // in the stream.
152 static void set_rate_control_metrics(struct RateControlMetrics *rc,
153 double framerate,
154 unsigned int ss_number_layers,
155 unsigned int ts_number_layers) {
156 int ts_rate_decimator[AOM_MAX_TS_LAYERS] = { 1 };
157 ts_rate_decimator[0] = 1;
158 if (ts_number_layers == 2) {
159 ts_rate_decimator[0] = 2;
160 ts_rate_decimator[1] = 1;
161 }
162 if (ts_number_layers == 3) {
163 ts_rate_decimator[0] = 4;
164 ts_rate_decimator[1] = 2;
165 ts_rate_decimator[2] = 1;
166 }
167 // Set the layer (cumulative) framerate and the target layer (non-cumulative)
168 // per-frame-bandwidth, for the rate control encoding stats below.
169 for (unsigned int sl = 0; sl < ss_number_layers; ++sl) {
170 unsigned int i = sl * ts_number_layers;
171 rc->layer_framerate[0] = framerate / ts_rate_decimator[0];
172 rc->layer_pfb[i] =
173 1000.0 * rc->layer_target_bitrate[i] / rc->layer_framerate[0];
174 for (unsigned int tl = 0; tl < ts_number_layers; ++tl) {
175 i = sl * ts_number_layers + tl;
176 if (tl > 0) {
177 rc->layer_framerate[tl] = framerate / ts_rate_decimator[tl];
178 rc->layer_pfb[i] =
179 1000.0 *
180 (rc->layer_target_bitrate[i] - rc->layer_target_bitrate[i - 1]) /
181 (rc->layer_framerate[tl] - rc->layer_framerate[tl - 1]);
182 }
183 rc->layer_input_frames[tl] = 0;
184 rc->layer_enc_frames[tl] = 0;
185 rc->layer_encoding_bitrate[i] = 0.0;
186 rc->layer_avg_frame_size[i] = 0.0;
187 rc->layer_avg_rate_mismatch[i] = 0.0;
188 }
189 }
190 rc->window_count = 0;
191 rc->window_size = 15;
192 rc->avg_st_encoding_bitrate = 0.0;
193 rc->variance_st_encoding_bitrate = 0.0;
194 }
195
196 static void printout_rate_control_summary(struct RateControlMetrics *rc,
197 int frame_cnt,
198 unsigned int ss_number_layers,
199 unsigned int ts_number_layers) {
200 int tot_num_frames = 0;
201 double perc_fluctuation = 0.0;
202 printf("Total number of processed frames: %d\n\n", frame_cnt - 1);
203 printf("Rate control layer stats for %d layer(s):\n\n", ts_number_layers);
204 for (unsigned int sl = 0; sl < ss_number_layers; ++sl) {
205 tot_num_frames = 0;
206 for (unsigned int tl = 0; tl < ts_number_layers; ++tl) {
207 unsigned int i = sl * ts_number_layers + tl;
208 const int num_dropped =
209 tl > 0 ? rc->layer_input_frames[tl] - rc->layer_enc_frames[tl]
210 : rc->layer_input_frames[tl] - rc->layer_enc_frames[tl] - 1;
211 tot_num_frames += rc->layer_input_frames[tl];
212 rc->layer_encoding_bitrate[i] = 0.001 * rc->layer_framerate[tl] *
213 rc->layer_encoding_bitrate[i] /
214 tot_num_frames;
215 rc->layer_avg_frame_size[i] =
216 rc->layer_avg_frame_size[i] / rc->layer_enc_frames[tl];
217 rc->layer_avg_rate_mismatch[i] =
218 100.0 * rc->layer_avg_rate_mismatch[i] / rc->layer_enc_frames[tl];
219 printf("For layer#: %d %d \n", sl, tl);
220 printf("Bitrate (target vs actual): %d %f\n", rc->layer_target_bitrate[i],
221 rc->layer_encoding_bitrate[i]);
222 printf("Average frame size (target vs actual): %f %f\n", rc->layer_pfb[i],
223 rc->layer_avg_frame_size[i]);
224 printf("Average rate_mismatch: %f\n", rc->layer_avg_rate_mismatch[i]);
225 printf(
226 "Number of input frames, encoded (non-key) frames, "
227 "and perc dropped frames: %d %d %f\n",
228 rc->layer_input_frames[tl], rc->layer_enc_frames[tl],
229 100.0 * num_dropped / rc->layer_input_frames[tl]);
230 printf("\n");
231 }
232 }
233 rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
234 rc->variance_st_encoding_bitrate =
235 rc->variance_st_encoding_bitrate / rc->window_count -
236 (rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
237 perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
238 rc->avg_st_encoding_bitrate;
239 printf("Short-time stats, for window of %d frames:\n", rc->window_size);
240 printf("Average, rms-variance, and percent-fluct: %f %f %f\n",
241 rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
242 perc_fluctuation);
243 if (frame_cnt - 1 != tot_num_frames)
244 die("Error: Number of input frames not equal to output!\n");
245 }
246
247 // Layer pattern configuration.
248 static int set_layer_pattern(int layering_mode, int superframe_cnt,
249 aom_svc_layer_id_t *layer_id,
250 aom_svc_ref_frame_config_t *ref_frame_config,
251 int *use_svc_control, int spatial_layer_id,
252 int is_key_frame, int ksvc_mode) {
253 int i;
254 int shift = (layering_mode == 7) ? 2 : 0;
255 *use_svc_control = 1;
256 layer_id->spatial_layer_id = spatial_layer_id;
257 // Set the referende map buffer idx for the 7 references:
258 // LAST_FRAME (0), LAST2_FRAME(1), LAST3_FRAME(2), GOLDEN_FRAME(3),
259 // BWDREF_FRAME(4), ALTREF2_FRAME(5), ALTREF_FRAME(6).
260 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->ref_idx[i] = i;
261 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->refresh[i] = 0;
262 // Note only use LAST and GF for prediction in non-rd mode (speed 8).
263 int layer_flags = AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
264 AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD |
265 AOM_EFLAG_NO_REF_ARF2;
266 if (ksvc_mode) {
267 // Same pattern as case 8.
268 layering_mode = 8;
269 if (!is_key_frame)
270 // No inter-layer prediction on inter-frames.
271 layer_flags |= AOM_EFLAG_NO_REF_GF;
272 }
273 switch (layering_mode) {
274 case 0:
275 // 1-layer: update LAST on every frame, reference LAST and GF.
276 layer_id->temporal_layer_id = 0;
277 ref_frame_config->refresh[0] = 1;
278 break;
279 case 1:
280 // 2-temporal layer.
281 // 1 3 5
282 // 0 2 4
283 if (superframe_cnt % 2 == 0) {
284 layer_id->temporal_layer_id = 0;
285 // Update LAST on layer 0, reference LAST and GF.
286 ref_frame_config->refresh[0] = 1;
287 } else {
288 layer_id->temporal_layer_id = 1;
289 // No updates on layer 1, only reference LAST (TL0).
290 layer_flags |= AOM_EFLAG_NO_REF_GF;
291 }
292 break;
293 case 2:
294 // 3-temporal layer:
295 // 1 3 5 7
296 // 2 6
297 // 0 4 8
298 if (superframe_cnt % 4 == 0) {
299 // Base layer.
300 layer_id->temporal_layer_id = 0;
301 // Update LAST on layer 0, reference LAST and GF.
302 ref_frame_config->refresh[0] = 1;
303 } else if ((superframe_cnt - 1) % 4 == 0) {
304 layer_id->temporal_layer_id = 2;
305 // First top layer: no updates, only reference LAST (TL0).
306 layer_flags |= AOM_EFLAG_NO_REF_GF;
307 } else if ((superframe_cnt - 2) % 4 == 0) {
308 layer_id->temporal_layer_id = 1;
309 // Middle layer (TL1): update LAST2, only reference LAST (TL0).
310 ref_frame_config->refresh[1] = 1;
311 layer_flags |= AOM_EFLAG_NO_REF_GF;
312 } else if ((superframe_cnt - 3) % 4 == 0) {
313 layer_id->temporal_layer_id = 2;
314 // Second top layer: no updates, only reference LAST.
315 // Set buffer idx for LAST to slot 1, since that was the slot
316 // updated in previous frame. So LAST is TL1 frame.
317 ref_frame_config->ref_idx[0] = 1;
318 ref_frame_config->ref_idx[1] = 0;
319 layer_flags |= AOM_EFLAG_NO_REF_GF;
320 }
321 break;
322 case 3:
323 // 3-temporal layer: but middle layer updates GF, so 2nd TL2 will
324 // only reference GF (not LAST). Other frames only reference LAST.
325 // 1 3 5 7
326 // 2 6
327 // 0 4 8
328 if (superframe_cnt % 4 == 0) {
329 // Base layer.
330 layer_id->temporal_layer_id = 0;
331 // Update LAST on layer 0, only reference LAST.
332 ref_frame_config->refresh[0] = 1;
333 layer_flags |= AOM_EFLAG_NO_REF_GF;
334 } else if ((superframe_cnt - 1) % 4 == 0) {
335 layer_id->temporal_layer_id = 2;
336 // First top layer: no updates, only reference LAST (TL0).
337 layer_flags |= AOM_EFLAG_NO_REF_GF;
338 } else if ((superframe_cnt - 2) % 4 == 0) {
339 layer_id->temporal_layer_id = 1;
340 // Middle layer (TL1): update GF, only reference LAST (TL0).
341 ref_frame_config->refresh[3] = 1;
342 layer_flags |= AOM_EFLAG_NO_REF_GF;
343 } else if ((superframe_cnt - 3) % 4 == 0) {
344 layer_id->temporal_layer_id = 2;
345 // Second top layer: no updates, only reference GF.
346 layer_flags |= AOM_EFLAG_NO_REF_LAST;
347 }
348 break;
349 case 4:
350 // 2-temporla layer with the old update flags, not with the new
351 // SVC control.
352 *use_svc_control = 0;
353 // 1 3 5
354 // 0 2 4
355 if (superframe_cnt % 2 == 0) {
356 layer_id->temporal_layer_id = 0;
357 // Update LAST on layer 0, reference LAST and GF.
358 layer_flags |= AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF;
359 } else {
360 layer_id->temporal_layer_id = 1;
361 // No updates on layer 1, only reference LAST (TL0).
362 layer_flags |= AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF |
363 AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_REF_GF;
364 }
365 break;
366 case 5:
367 // 2 spatial layers, 1 temporal.
368 layer_id->temporal_layer_id = 0;
369 if (layer_id->spatial_layer_id == 0) {
370 // Reference LAST, update LAST.
371 ref_frame_config->refresh[0] = 1;
372 layer_flags |= AOM_EFLAG_NO_REF_GF;
373 } else if (layer_id->spatial_layer_id == 1) {
374 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1
375 // and GOLDEN to slot 0. Update slot 1 (LAST).
376 ref_frame_config->ref_idx[0] = 1;
377 ref_frame_config->ref_idx[3] = 0;
378 ref_frame_config->refresh[1] = 1;
379 }
380 break;
381 case 6:
382 // 3 spatial layers, 1 temporal.
383 // Note for this case, we set the buffer idx for all references to be
384 // either LAST or GOLDEN, which are always valid references, since decoder
385 // will check if any of the 7 references is valid scale in
386 // valid_ref_frame_size().
387 layer_id->temporal_layer_id = 0;
388 if (layer_id->spatial_layer_id == 0) {
389 // Reference LAST, update LAST. Set all buffer_idx to 0.
390 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
391 ref_frame_config->ref_idx[i] = 0;
392 ref_frame_config->refresh[0] = 1;
393 layer_flags |= AOM_EFLAG_NO_REF_GF;
394 } else if (layer_id->spatial_layer_id == 1) {
395 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1
396 // and GOLDEN (and all other refs) to slot 0.
397 // Update slot 1 (LAST).
398 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
399 ref_frame_config->ref_idx[i] = 0;
400 ref_frame_config->ref_idx[0] = 1;
401 ref_frame_config->refresh[1] = 1;
402 } else if (layer_id->spatial_layer_id == 2) {
403 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2
404 // and GOLDEN (and all other refs) to slot 1.
405 // Update slot 2 (LAST).
406 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
407 ref_frame_config->ref_idx[i] = 1;
408 ref_frame_config->ref_idx[0] = 2;
409 ref_frame_config->refresh[2] = 1;
410 }
411 break;
412 case 7:
413 // 3 spatial and 3 temporal layer.
414 // Same as case 8 but overalap in the buffer slot updates.
415 // (shift = 2). The slots 3 and 4 updated by first TL2 are
416 // reused for update in TL1 superframe.
417 // Note for this case, frame order hint must be disabled for
418 // lower resolutios (operating points > 0) to be decoedable.
419 case 8:
420 // 3 spatial and 3 temporal layer.
421 // No overlap in buffer updates between TL2 and TL1.
422 // TL2 updates slot 3 and 4, TL1 updates 5, 6, 7.
423 if (superframe_cnt % 4 == 0) {
424 // Base temporal layer.
425 layer_id->temporal_layer_id = 0;
426 if (layer_id->spatial_layer_id == 0) {
427 // Reference LAST, update LAST.
428 // Set all buffer_idx to 0.
429 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
430 ref_frame_config->ref_idx[i] = 0;
431 ref_frame_config->refresh[0] = 1;
432 layer_flags |= AOM_EFLAG_NO_REF_GF;
433 } else if (layer_id->spatial_layer_id == 1) {
434 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
435 // GOLDEN (and all other refs) to slot 0.
436 // Update slot 1 (LAST).
437 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
438 ref_frame_config->ref_idx[i] = 0;
439 ref_frame_config->ref_idx[0] = 1;
440 ref_frame_config->refresh[1] = 1;
441 } else if (layer_id->spatial_layer_id == 2) {
442 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
443 // GOLDEN (and all other refs) to slot 1.
444 // Update slot 2 (LAST).
445 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
446 ref_frame_config->ref_idx[i] = 1;
447 ref_frame_config->ref_idx[0] = 2;
448 ref_frame_config->refresh[2] = 1;
449 }
450 } else if ((superframe_cnt - 1) % 4 == 0) {
451 // First top temporal enhancement layer.
452 layer_id->temporal_layer_id = 2;
453 if (layer_id->spatial_layer_id == 0) {
454 // Reference LAST (slot 0).
455 // Set GOLDEN to slot 3 and update slot 3.
456 // Set all other buffer_idx to slot 0.
457 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
458 ref_frame_config->ref_idx[i] = 0;
459 ref_frame_config->ref_idx[3] = 3;
460 ref_frame_config->refresh[3] = 1;
461 layer_flags |= AOM_EFLAG_NO_REF_GF;
462 } else if (layer_id->spatial_layer_id == 1) {
463 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
464 // GOLDEN (and all other refs) to slot 3.
465 // Set LAST2 to slot 4 and Update slot 4.
466 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
467 ref_frame_config->ref_idx[i] = 3;
468 ref_frame_config->ref_idx[0] = 1;
469 ref_frame_config->ref_idx[1] = 4;
470 ref_frame_config->refresh[4] = 1;
471 } else if (layer_id->spatial_layer_id == 2) {
472 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
473 // GOLDEN (and all other refs) to slot 4.
474 // No update.
475 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
476 ref_frame_config->ref_idx[i] = 4;
477 ref_frame_config->ref_idx[0] = 2;
478 }
479 } else if ((superframe_cnt - 2) % 4 == 0) {
480 // Middle temporal enhancement layer.
481 layer_id->temporal_layer_id = 1;
482 if (layer_id->spatial_layer_id == 0) {
483 // Reference LAST.
484 // Set all buffer_idx to 0.
485 // Set GOLDEN to slot 5 and update slot 5.
486 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
487 ref_frame_config->ref_idx[i] = 0;
488 ref_frame_config->ref_idx[3] = 5 - shift;
489 ref_frame_config->refresh[5 - shift] = 1;
490 layer_flags |= AOM_EFLAG_NO_REF_GF;
491 } else if (layer_id->spatial_layer_id == 1) {
492 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
493 // GOLDEN (and all other refs) to slot 5.
494 // Set LAST2 to slot 6 and update slot 6.
495 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
496 ref_frame_config->ref_idx[i] = 5 - shift;
497 ref_frame_config->ref_idx[0] = 1;
498 ref_frame_config->ref_idx[2] = 6 - shift;
499 ref_frame_config->refresh[6 - shift] = 1;
500 } else if (layer_id->spatial_layer_id == 2) {
501 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
502 // GOLDEN (and all other refs) to slot 6.
503 // Set LAST2 to slot 6 and update slot 7.
504 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
505 ref_frame_config->ref_idx[i] = 6 - shift;
506 ref_frame_config->ref_idx[0] = 2;
507 ref_frame_config->ref_idx[2] = 7 - shift;
508 ref_frame_config->refresh[7 - shift] = 1;
509 }
510 } else if ((superframe_cnt - 3) % 4 == 0) {
511 // Second top temporal enhancement layer.
512 layer_id->temporal_layer_id = 2;
513 if (layer_id->spatial_layer_id == 0) {
514 // Set LAST to slot 5 and reference LAST.
515 // Set GOLDEN to slot 3 and update slot 3.
516 // Set all other buffer_idx to 0.
517 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
518 ref_frame_config->ref_idx[i] = 0;
519 ref_frame_config->ref_idx[0] = 5 - shift;
520 ref_frame_config->ref_idx[3] = 3;
521 ref_frame_config->refresh[3] = 1;
522 layer_flags |= AOM_EFLAG_NO_REF_GF;
523 } else if (layer_id->spatial_layer_id == 1) {
524 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 6,
525 // GOLDEN to slot 3. Set LAST2 to slot 4 and update slot 4.
526 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
527 ref_frame_config->ref_idx[i] = 0;
528 ref_frame_config->ref_idx[0] = 6 - shift;
529 ref_frame_config->ref_idx[3] = 3;
530 ref_frame_config->ref_idx[1] = 4;
531 ref_frame_config->refresh[4] = 1;
532 } else if (layer_id->spatial_layer_id == 2) {
533 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 7,
534 // GOLDEN to slot 4. No update.
535 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
536 ref_frame_config->ref_idx[i] = 0;
537 ref_frame_config->ref_idx[0] = 7 - shift;
538 ref_frame_config->ref_idx[3] = 4;
539 }
540 }
541 break;
542 default: assert(0); die("Error: Unsupported temporal layering mode!\n");
543 }
544 return layer_flags;
545 }
546
547 int main(int argc, char **argv) {
548 AvxVideoWriter *outfile[AOM_MAX_LAYERS] = { NULL };
549 aom_codec_ctx_t codec;
550 aom_codec_enc_cfg_t cfg;
551 int frame_cnt = 0;
552 aom_image_t raw;
553 aom_codec_err_t res;
554 unsigned int width;
555 unsigned int height;
556 uint32_t error_resilient = 0;
557 int speed;
558 int frame_avail;
559 int got_data = 0;
560 int flags = 0;
561 unsigned i;
562 int pts = 0; // PTS starts at 0.
563 int frame_duration = 1; // 1 timebase tick per frame.
564 int layering_mode = 0;
565 aom_svc_layer_id_t layer_id;
566 aom_svc_params_t svc_params;
567 aom_svc_ref_frame_config_t ref_frame_config;
568 const AvxInterface *encoder = NULL;
569 struct AvxInputContext input_ctx;
570 struct RateControlMetrics rc;
571 int64_t cx_time = 0;
572 const int min_args_base = 13;
573 const int min_args = min_args_base;
574 double sum_bitrate = 0.0;
575 double sum_bitrate2 = 0.0;
576 double framerate = 30.0;
577 int use_svc_control = 1;
578 zero(rc.layer_target_bitrate);
579 memset(&layer_id, 0, sizeof(aom_svc_layer_id_t));
580 memset(&input_ctx, 0, sizeof(input_ctx));
581 memset(&svc_params, 0, sizeof(svc_params));
582
583 /* Setup default input stream settings */
584 input_ctx.framerate.numerator = 30;
585 input_ctx.framerate.denominator = 1;
586 input_ctx.only_i420 = 1;
587 input_ctx.bit_depth = 0;
588 unsigned int ts_number_layers = 1;
589 unsigned int ss_number_layers = 1;
590 exec_name = argv[0];
591 // Check usage and arguments.
592 if (argc < min_args) {
593 die("Usage: %s <infile> <outfile> <codec_type(av1)> <width> <height> "
594 "<rate_num> <rate_den> <speed> <frame_drop_threshold> "
595 "<error_resilient> <threads> <mode> "
596 "<Rate_0> ... <Rate_nlayers-1>\n",
597 argv[0]);
598 }
599
600 encoder = get_aom_encoder_by_name(argv[3]);
601
602 width = (unsigned int)strtoul(argv[4], NULL, 0);
603 height = (unsigned int)strtoul(argv[5], NULL, 0);
604 if (width < 16 || width % 2 || height < 16 || height % 2) {
605 die("Invalid resolution: %d x %d", width, height);
606 }
607
608 layering_mode = (int)strtol(argv[12], NULL, 0);
609 if (layering_mode < 0 || layering_mode > 13) {
610 die("Invalid layering mode (0..12) %s", argv[12]);
611 }
612
613 if (argc != min_args + mode_to_num_layers[layering_mode]) {
614 die("Invalid number of arguments");
615 }
616
617 ts_number_layers = mode_to_num_temporal_layers[layering_mode];
618 ss_number_layers = mode_to_num_spatial_layers[layering_mode];
619
620 input_ctx.filename = argv[1];
621 open_input_file(&input_ctx, 0);
622
623 // Y4M reader has its own allocation.
624 if (input_ctx.file_type != FILE_TYPE_Y4M) {
625 if (!aom_img_alloc(&raw, AOM_IMG_FMT_I420, width, height, 32)) {
626 die("Failed to allocate image", width, height);
627 }
628 }
629
630 // Populate encoder configuration.
631 res = aom_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
632 if (res) {
633 printf("Failed to get config: %s\n", aom_codec_err_to_string(res));
634 return EXIT_FAILURE;
635 }
636
637 // Update the default configuration with our settings.
638 cfg.g_w = width;
639 cfg.g_h = height;
640
641 // Timebase format e.g. 30fps: numerator=1, demoninator = 30.
642 cfg.g_timebase.num = (int)strtol(argv[6], NULL, 0);
643 cfg.g_timebase.den = (int)strtol(argv[7], NULL, 0);
644
645 speed = (int)strtol(argv[8], NULL, 0);
646 if (speed < 0 || speed > 8) {
647 die("Invalid speed setting: must be positive");
648 }
649
650 for (i = min_args_base;
651 (int)i < min_args_base + mode_to_num_layers[layering_mode]; ++i) {
652 rc.layer_target_bitrate[i - 13] = (int)strtol(argv[i], NULL, 0);
653 svc_params.layer_target_bitrate[i - 13] = rc.layer_target_bitrate[i - 13];
654 }
655
656 cfg.rc_target_bitrate =
657 svc_params.layer_target_bitrate[ss_number_layers * ts_number_layers - 1];
658
659 svc_params.framerate_factor[0] = 1;
660 if (ts_number_layers == 2) {
661 svc_params.framerate_factor[0] = 2;
662 svc_params.framerate_factor[1] = 1;
663 } else if (ts_number_layers == 3) {
664 svc_params.framerate_factor[0] = 4;
665 svc_params.framerate_factor[1] = 2;
666 svc_params.framerate_factor[2] = 1;
667 }
668
669 // Real time parameters.
670 cfg.g_usage = AOM_USAGE_REALTIME;
671
672 cfg.rc_dropframe_thresh = (unsigned int)strtoul(argv[9], NULL, 0);
673 cfg.rc_end_usage = AOM_CBR;
674 cfg.rc_min_quantizer = 2;
675 cfg.rc_max_quantizer = 52;
676 cfg.rc_undershoot_pct = 50;
677 cfg.rc_overshoot_pct = 50;
678 cfg.rc_buf_initial_sz = 600;
679 cfg.rc_buf_optimal_sz = 600;
680 cfg.rc_buf_sz = 1000;
681
682 // Use 1 thread as default.
683 cfg.g_threads = (unsigned int)strtoul(argv[11], NULL, 0);
684
685 error_resilient = (uint32_t)strtoul(argv[10], NULL, 0);
686 if (error_resilient != 0 && error_resilient != 1) {
687 die("Invalid value for error resilient (0, 1): %d.", error_resilient);
688 }
689 // Enable error resilient mode.
690 cfg.g_error_resilient = error_resilient;
691 cfg.g_lag_in_frames = 0;
692 cfg.kf_mode = AOM_KF_AUTO;
693
694 // Disable automatic keyframe placement.
695 cfg.kf_min_dist = cfg.kf_max_dist = 3000;
696
697 framerate = cfg.g_timebase.den / cfg.g_timebase.num;
698 set_rate_control_metrics(&rc, framerate, ss_number_layers, ts_number_layers);
699
700 if (input_ctx.file_type == FILE_TYPE_Y4M) {
701 if (input_ctx.width != cfg.g_w || input_ctx.height != cfg.g_h) {
702 die("Incorrect width or height: %d x %d", cfg.g_w, cfg.g_h);
703 }
704 if (input_ctx.framerate.numerator != cfg.g_timebase.den ||
705 input_ctx.framerate.denominator != cfg.g_timebase.num) {
706 die("Incorrect framerate: numerator %d denominator %d",
707 cfg.g_timebase.num, cfg.g_timebase.den);
708 }
709 }
710
711 // Open an output file for each stream.
712 for (unsigned int sl = 0; sl < ss_number_layers; ++sl) {
713 for (unsigned tl = 0; tl < ts_number_layers; ++tl) {
714 i = sl * ts_number_layers + tl;
715 char file_name[PATH_MAX];
716 AvxVideoInfo info;
717 info.codec_fourcc = encoder->fourcc;
718 info.frame_width = cfg.g_w;
719 info.frame_height = cfg.g_h;
720 info.time_base.numerator = cfg.g_timebase.num;
721 info.time_base.denominator = cfg.g_timebase.den;
722
723 snprintf(file_name, sizeof(file_name), "%s_%d.av1", argv[2], i);
724 outfile[i] = aom_video_writer_open(file_name, kContainerIVF, &info);
725 if (!outfile[i]) die("Failed to open %s for writing", file_name);
726 assert(outfile[i] != NULL);
727 }
728 }
729
730 // Initialize codec.
731 if (aom_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
732 die_codec(&codec, "Failed to initialize encoder");
733
734 aom_codec_control(&codec, AOME_SET_CPUUSED, speed);
735 aom_codec_control(&codec, AV1E_SET_AQ_MODE, 3);
736 aom_codec_control(&codec, AV1E_SET_GF_CBR_BOOST_PCT, 0);
737 aom_codec_control(&codec, AV1E_SET_ENABLE_CDEF, 1);
738 aom_codec_control(&codec, AV1E_SET_ENABLE_ORDER_HINT, 0);
739 aom_codec_control(&codec, AV1E_SET_ENABLE_TPL_MODEL, 0);
740 aom_codec_control(&codec, AV1E_SET_DELTAQ_MODE, 0);
741
742 svc_params.number_spatial_layers = ss_number_layers;
743 svc_params.number_temporal_layers = ts_number_layers;
744 for (i = 0; i < ss_number_layers * ts_number_layers; ++i) {
745 svc_params.max_quantizers[i] = cfg.rc_max_quantizer;
746 svc_params.min_quantizers[i] = cfg.rc_min_quantizer;
747 }
748 for (i = 0; i < ss_number_layers; ++i) {
749 svc_params.scaling_factor_num[i] = 1;
750 svc_params.scaling_factor_den[i] = 1;
751 }
752 if (ss_number_layers == 2) {
753 svc_params.scaling_factor_num[0] = 1;
754 svc_params.scaling_factor_den[0] = 2;
755 } else if (ss_number_layers == 3) {
756 svc_params.scaling_factor_num[0] = 1;
757 svc_params.scaling_factor_den[0] = 4;
758 svc_params.scaling_factor_num[1] = 1;
759 svc_params.scaling_factor_den[1] = 2;
760 }
761
762 aom_codec_control(&codec, AV1E_SET_SVC_PARAMS, &svc_params);
763
764 // This controls the maximum target size of the key frame.
765 // For generating smaller key frames, use a smaller max_intra_size_pct
766 // value, like 100 or 200.
767 {
768 const int max_intra_size_pct = 300;
769 aom_codec_control(&codec, AOME_SET_MAX_INTRA_BITRATE_PCT,
770 max_intra_size_pct);
771 }
772
773 frame_avail = 1;
774 while (frame_avail || got_data) {
775 struct aom_usec_timer timer;
776 frame_avail = read_frame(&input_ctx, &raw);
777 int is_key_frame = (frame_cnt % cfg.kf_max_dist) == 0;
778 // Loop over spatial layers.
779 for (unsigned int slx = 0; slx < ss_number_layers; slx++) {
780 aom_codec_iter_t iter = NULL;
781 const aom_codec_cx_pkt_t *pkt;
782 int layer = 0;
783
784 // Set the reference/update flags, layer_id, and reference_map
785 // buffer index.
786 flags = set_layer_pattern(layering_mode, frame_cnt, &layer_id,
787 &ref_frame_config, &use_svc_control, slx,
788 is_key_frame, (layering_mode == 9));
789 aom_codec_control(&codec, AV1E_SET_SVC_LAYER_ID, &layer_id);
790 if (use_svc_control)
791 aom_codec_control(&codec, AV1E_SET_SVC_REF_FRAME_CONFIG,
792 &ref_frame_config);
793
794 layer = slx * ts_number_layers + layer_id.temporal_layer_id;
795 if (frame_avail && slx == 0) ++rc.layer_input_frames[layer];
796
797 // Do the layer encode.
798 aom_usec_timer_start(&timer);
799 if (aom_codec_encode(&codec, frame_avail ? &raw : NULL, pts, 1, flags))
800 die_codec(&codec, "Failed to encode frame");
801 aom_usec_timer_mark(&timer);
802 cx_time += aom_usec_timer_elapsed(&timer);
803
804 got_data = 0;
805 while ((pkt = aom_codec_get_cx_data(&codec, &iter))) {
806 got_data = 1;
807 switch (pkt->kind) {
808 case AOM_CODEC_CX_FRAME_PKT:
809 for (unsigned int sl = layer_id.spatial_layer_id;
810 sl < ss_number_layers; ++sl) {
811 for (unsigned tl = layer_id.temporal_layer_id;
812 tl < ts_number_layers; ++tl) {
813 unsigned int j = sl * ts_number_layers + tl;
814 aom_video_writer_write_frame(outfile[j], pkt->data.frame.buf,
815 pkt->data.frame.sz, pts);
816 if (sl == (unsigned int)layer_id.spatial_layer_id)
817 rc.layer_encoding_bitrate[j] += 8.0 * pkt->data.frame.sz;
818 // Keep count of rate control stats per layer (for non-key).
819 if (tl == (unsigned int)layer_id.temporal_layer_id &&
820 sl == (unsigned int)layer_id.spatial_layer_id &&
821 !(pkt->data.frame.flags & AOM_FRAME_IS_KEY)) {
822 rc.layer_avg_frame_size[j] += 8.0 * pkt->data.frame.sz;
823 rc.layer_avg_rate_mismatch[j] +=
824 fabs(8.0 * pkt->data.frame.sz - rc.layer_pfb[j]) /
825 rc.layer_pfb[j];
826 if (slx == 0) ++rc.layer_enc_frames[tl];
827 }
828 }
829 }
830
831 // Update for short-time encoding bitrate states, for moving window
832 // of size rc->window, shifted by rc->window / 2.
833 // Ignore first window segment, due to key frame.
834 // For spatial layers: only do this for top/highest SL.
835 if (frame_cnt > rc.window_size && slx == ss_number_layers - 1) {
836 sum_bitrate += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
837 rc.window_size = (rc.window_size <= 0) ? 1 : rc.window_size;
838 if (frame_cnt % rc.window_size == 0) {
839 rc.window_count += 1;
840 rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
841 rc.variance_st_encoding_bitrate +=
842 (sum_bitrate / rc.window_size) *
843 (sum_bitrate / rc.window_size);
844 sum_bitrate = 0.0;
845 }
846 }
847 // Second shifted window.
848 if (frame_cnt > rc.window_size + rc.window_size / 2 &&
849 slx == ss_number_layers - 1) {
850 sum_bitrate2 += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
851 if (frame_cnt > 2 * rc.window_size &&
852 frame_cnt % rc.window_size == 0) {
853 rc.window_count += 1;
854 rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
855 rc.variance_st_encoding_bitrate +=
856 (sum_bitrate2 / rc.window_size) *
857 (sum_bitrate2 / rc.window_size);
858 sum_bitrate2 = 0.0;
859 }
860 }
861 break;
862 default: break;
863 }
864 }
865 } // loop over spatial layers
866 ++frame_cnt;
867 pts += frame_duration;
868 }
869 close_input_file(&input_ctx);
870 printout_rate_control_summary(&rc, frame_cnt, ss_number_layers,
871 ts_number_layers);
872 printf("\n");
873 printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f\n",
874 frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
875 1000000 * (double)frame_cnt / (double)cx_time);
876
877 if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
878
879 // Try to rewrite the output file headers with the actual frame count.
880 for (i = 0; i < ss_number_layers * ts_number_layers; ++i)
881 aom_video_writer_close(outfile[i]);
882
883 if (input_ctx.file_type != FILE_TYPE_Y4M) {
884 aom_img_free(&raw);
885 }
886 return EXIT_SUCCESS;
887 }
AOM_IMG_FMT_I420
@ AOM_IMG_FMT_I420
Definition: aom_image.h:45
AOM_USAGE_REALTIME
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition: aom_encoder.h:1008
aom_codec_enc_cfg::rc_dropframe_thresh
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition: aom_encoder.h:517
aom_codec_enc_cfg
Encoder configuration structure.
Definition: aom_encoder.h:369
AOM_EFLAG_NO_REF_LAST
#define AOM_EFLAG_NO_REF_LAST
Don't reference the last frame.
Definition: aomcx.h:50
AOME_SET_CPUUSED
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings.
Definition: aomcx.h:184
aom_svc_params::framerate_factor
int framerate_factor[8]
Definition: aomcx.h:1290
AOM_EFLAG_NO_REF_BWD
#define AOM_EFLAG_NO_REF_BWD
Don't reference the bwd reference frame.
Definition: aomcx.h:86
aom_svc_params::number_spatial_layers
int number_spatial_layers
Definition: aomcx.h:1281
aom_chroma_sample_position_t
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
AV1E_SET_AQ_MODE
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode.
Definition: aomcx.h:388
aom_codec_enc_cfg::g_lag_in_frames
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition: aom_encoder.h:495
AV1E_SET_GF_CBR_BOOST_PCT
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode.
Definition: aomcx.h:278
AOM_EFLAG_NO_REF_LAST3
#define AOM_EFLAG_NO_REF_LAST3
Don't reference the last3 frame.
Definition: aomcx.h:64
aom_svc_ref_frame_config::refresh
int refresh[8]
Definition: aomcx.h:1299
aom_codec_ctx
Codec context structure.
Definition: aom_codec.h:211
aom_codec_enc_cfg::rc_buf_sz
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition: aom_encoder.h:689
aom_codec_iter_t
const typedef void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:201
aomcx.h
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
aom_codec_err_to_string
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
aom_codec_enc_cfg::rc_target_bitrate
unsigned int rc_target_bitrate
Target data rate.
Definition: aom_encoder.h:622
AV1E_SET_DELTAQ_MODE
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode.
Definition: aomcx.h:1045
aom_img_free
void aom_img_free(aom_image_t *img)
Close an image descriptor.
aom_svc_params::max_quantizers
int max_quantizers[32]
Definition: aomcx.h:1283
aom_codec_enc_cfg::rc_min_quantizer
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition: aom_encoder.h:636
AOM_CBR
@ AOM_CBR
Definition: aom_encoder.h:186
aom_rational::den
int den
Definition: aom_encoder.h:173
aom_codec_enc_cfg::rc_undershoot_pct
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition: aom_encoder.h:662
aom_svc_params::number_temporal_layers
int number_temporal_layers
Definition: aomcx.h:1282
aom_codec_destroy
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
aom_svc_layer_id
Definition: aomcx.h:1274
aom_img_alloc
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_codec_control
#define aom_codec_control(ctx, id, data)
aom_codec_control wrapper macro
Definition: aom_codec.h:421
aom_codec_enc_cfg::rc_overshoot_pct
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition: aom_encoder.h:674
aom_codec_enc_cfg::kf_mode
enum aom_kf_mode kf_mode
Keyframe placement mode.
Definition: aom_encoder.h:752
aom_codec_enc_cfg::g_usage
unsigned int g_usage
Algorithm specific "usage" value.
Definition: aom_encoder.h:381
AV1E_SET_SVC_LAYER_ID
@ AV1E_SET_SVC_LAYER_ID
Codec control function to set the layer id.
Definition: aomcx.h:1170
AOM_EFLAG_NO_UPD_LAST
#define AOM_EFLAG_NO_UPD_LAST
Don't update the last frame.
Definition: aomcx.h:100
aom_svc_ref_frame_config
Definition: aomcx.h:1294
aom_codec_enc_cfg::rc_end_usage
enum aom_rc_mode rc_end_usage
Rate control algorithm to use.
Definition: aom_encoder.h:602
aom_svc_params::scaling_factor_num
int scaling_factor_num[4]
Definition: aomcx.h:1285
aom_svc_params::layer_target_bitrate
int layer_target_bitrate[32]
Definition: aomcx.h:1288
aom_svc_params::min_quantizers
int min_quantizers[32]
Definition: aomcx.h:1284
aom_codec_enc_cfg::g_w
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:408
AOM_MAX_TS_LAYERS
#define AOM_MAX_TS_LAYERS
Definition: aomcx.h:1271
aom_svc_params
Definition: aomcx.h:1280
aom_codec_enc_cfg::g_error_resilient
aom_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: aom_encoder.h:474
AOM_EFLAG_NO_UPD_GF
#define AOM_EFLAG_NO_UPD_GF
Don't update the golden frame.
Definition: aomcx.h:107
AOM_MAX_LAYERS
#define AOM_MAX_LAYERS
Definition: aomcx.h:1269
aom_codec_err_t
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:101
AOM_EFLAG_NO_REF_GF
#define AOM_EFLAG_NO_REF_GF
Don't reference the golden frame.
Definition: aomcx.h:71
aom_encoder.h
Describes the encoder algorithm interface to applications.
aom_codec_get_cx_data
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
aom_svc_params::scaling_factor_den
int scaling_factor_den[4]
Definition: aomcx.h:1286
aom_codec_encode
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.
aom_codec_enc_cfg::rc_buf_initial_sz
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition: aom_encoder.h:698
AOME_SET_MAX_INTRA_BITRATE_PCT
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set Max data rate for Intra frames.
Definition: aomcx.h:248
aom_codec_enc_cfg::rc_max_quantizer
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition: aom_encoder.h:646
aom_codec_cx_pkt::data
union aom_codec_cx_pkt::@1 data
AV1E_SET_ENABLE_CDEF
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF.
Definition: aomcx.h:579
aom_codec_cx_pkt::frame
struct aom_codec_cx_pkt::@1::@2 frame
aom_codec_cx_pkt
Encoder output packet.
Definition: aom_encoder.h:131
AV1E_SET_ENABLE_ORDER_HINT
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint for a few tools:
Definition: aomcx.h:816
AOM_EFLAG_NO_UPD_ARF
#define AOM_EFLAG_NO_UPD_ARF
Don't update the alternate reference frame.
Definition: aomcx.h:114
AV1E_SET_SVC_PARAMS
@ AV1E_SET_SVC_PARAMS
Codec control function to set SVC paramaeters.
Definition: aomcx.h:1174
AV1E_SET_SVC_REF_FRAME_CONFIG
@ 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:1179
AOM_EFLAG_NO_REF_LAST2
#define AOM_EFLAG_NO_REF_LAST2
Don't reference the last2 frame.
Definition: aomcx.h:57
AOM_KF_AUTO
@ AOM_KF_AUTO
Definition: aom_encoder.h:201
aom_codec_enc_cfg::g_h
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:417
aom_svc_layer_id::spatial_layer_id
int spatial_layer_id
Definition: aomcx.h:1275
AOM_CODEC_CX_FRAME_PKT
@ AOM_CODEC_CX_FRAME_PKT
Definition: aom_encoder.h:119
AOM_EFLAG_NO_REF_ARF2
#define AOM_EFLAG_NO_REF_ARF2
Don't reference the alt2 reference frame.
Definition: aomcx.h:93
aom_codec_enc_init
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition: aom_encoder.h:905
aom_image
Image Descriptor.
Definition: aom_image.h:151
aom_codec_cx_pkt::kind
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:132
aom_codec_enc_cfg::g_timebase
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:466
aom_codec_enc_cfg::g_threads
unsigned int g_threads
Maximum number of threads to use.
Definition: aom_encoder.h:389
AV1E_SET_ENABLE_TPL_MODEL
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency.
Definition: aomcx.h:339
AOM_FRAME_IS_KEY
#define AOM_FRAME_IS_KEY
Definition: aom_encoder.h:89
aom_svc_ref_frame_config::ref_idx
int ref_idx[7]
Definition: aomcx.h:1298
aom_codec_enc_cfg::rc_buf_optimal_sz
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition: aom_encoder.h:707
aom_codec_enc_cfg::kf_max_dist
unsigned int kf_max_dist
Keyframe maximum interval.
Definition: aom_encoder.h:770
AOM_EFLAG_NO_REF_ARF
#define AOM_EFLAG_NO_REF_ARF
Don't reference the alternate reference frame.
Definition: aomcx.h:79
aom_codec_enc_config_default
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int reserved)
Get a default configuration.
aom_svc_layer_id::temporal_layer_id
int temporal_layer_id
Definition: aomcx.h:1276
aom_codec_enc_cfg::kf_min_dist
unsigned int kf_min_dist
Keyframe minimum interval.
Definition: aom_encoder.h:761
aom_rational::num
int num
Definition: aom_encoder.h:172