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 < INTER_REFS_PER_FRAME; i++) ref_frame_config->reference[i] = 0;
262 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->refresh[i] = 0;
263 // Note for this layered patterns only use LAST and GF for prediction in
264 // non-rd mode (speed >= 7).
265 int layer_flags = AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
266 AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD |
267 AOM_EFLAG_NO_REF_ARF2;
268 if (ksvc_mode) {
269 // Same pattern as case 8.
270 layering_mode = 8;
271 if (!is_key_frame)
272 // No inter-layer prediction on inter-frames.
273 layer_flags |= AOM_EFLAG_NO_REF_GF;
274 }
275 switch (layering_mode) {
276 case 0:
277 // 1-layer: update LAST on every frame, reference LAST and GF.
278 layer_id->temporal_layer_id = 0;
279 ref_frame_config->refresh[0] = 1;
280 break;
281 case 1:
282 // 2-temporal layer.
283 // 1 3 5
284 // 0 2 4
285 if (superframe_cnt % 2 == 0) {
286 layer_id->temporal_layer_id = 0;
287 // Update LAST on layer 0, reference LAST and GF.
288 ref_frame_config->refresh[0] = 1;
289 } else {
290 layer_id->temporal_layer_id = 1;
291 // No updates on layer 1, only reference LAST (TL0).
292 layer_flags |= AOM_EFLAG_NO_REF_GF;
293 }
294 break;
295 case 2:
296 // 3-temporal layer:
297 // 1 3 5 7
298 // 2 6
299 // 0 4 8
300 if (superframe_cnt % 4 == 0) {
301 // Base layer.
302 layer_id->temporal_layer_id = 0;
303 // Update LAST on layer 0, reference LAST and GF.
304 ref_frame_config->refresh[0] = 1;
305 } else if ((superframe_cnt - 1) % 4 == 0) {
306 layer_id->temporal_layer_id = 2;
307 // First top layer: no updates, only reference LAST (TL0).
308 layer_flags |= AOM_EFLAG_NO_REF_GF;
309 } else if ((superframe_cnt - 2) % 4 == 0) {
310 layer_id->temporal_layer_id = 1;
311 // Middle layer (TL1): update LAST2, only reference LAST (TL0).
312 ref_frame_config->refresh[1] = 1;
313 layer_flags |= AOM_EFLAG_NO_REF_GF;
314 } else if ((superframe_cnt - 3) % 4 == 0) {
315 layer_id->temporal_layer_id = 2;
316 // Second top layer: no updates, only reference LAST.
317 // Set buffer idx for LAST to slot 1, since that was the slot
318 // updated in previous frame. So LAST is TL1 frame.
319 ref_frame_config->ref_idx[0] = 1;
320 ref_frame_config->ref_idx[1] = 0;
321 layer_flags |= AOM_EFLAG_NO_REF_GF;
322 }
323 break;
324 case 3:
325 // 3-temporal layer: but middle layer updates GF, so 2nd TL2 will
326 // only reference GF (not LAST). Other frames only reference LAST.
327 // 1 3 5 7
328 // 2 6
329 // 0 4 8
330 if (superframe_cnt % 4 == 0) {
331 // Base layer.
332 layer_id->temporal_layer_id = 0;
333 // Update LAST on layer 0, only reference LAST.
334 ref_frame_config->refresh[0] = 1;
335 layer_flags |= AOM_EFLAG_NO_REF_GF;
336 } else if ((superframe_cnt - 1) % 4 == 0) {
337 layer_id->temporal_layer_id = 2;
338 // First top layer: no updates, only reference LAST (TL0).
339 layer_flags |= AOM_EFLAG_NO_REF_GF;
340 } else if ((superframe_cnt - 2) % 4 == 0) {
341 layer_id->temporal_layer_id = 1;
342 // Middle layer (TL1): update GF, only reference LAST (TL0).
343 ref_frame_config->refresh[3] = 1;
344 layer_flags |= AOM_EFLAG_NO_REF_GF;
345 } else if ((superframe_cnt - 3) % 4 == 0) {
346 layer_id->temporal_layer_id = 2;
347 // Second top layer: no updates, only reference GF.
348 layer_flags |= AOM_EFLAG_NO_REF_LAST;
349 }
350 break;
351 case 4:
352 // 2-temporal layer with the old update flags, not with the new
353 // SVC control.
354 *use_svc_control = 0;
355 // 1 3 5
356 // 0 2 4
357 if (superframe_cnt % 2 == 0) {
358 layer_id->temporal_layer_id = 0;
359 // Update LAST on layer 0, reference LAST and GF.
360 layer_flags |= AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF;
361 } else {
362 layer_id->temporal_layer_id = 1;
363 // No updates on layer 1, only reference LAST (TL0).
364 layer_flags |= AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF |
365 AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_REF_GF;
366 }
367 break;
368 case 5:
369 // 2 spatial layers, 1 temporal.
370 layer_id->temporal_layer_id = 0;
371 if (layer_id->spatial_layer_id == 0) {
372 // Reference LAST, update LAST.
373 ref_frame_config->refresh[0] = 1;
374 layer_flags |= AOM_EFLAG_NO_REF_GF;
375 } else if (layer_id->spatial_layer_id == 1) {
376 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1
377 // and GOLDEN to slot 0. Update slot 1 (LAST).
378 ref_frame_config->ref_idx[0] = 1;
379 ref_frame_config->ref_idx[3] = 0;
380 ref_frame_config->refresh[1] = 1;
381 }
382 break;
383 case 6:
384 // 3 spatial layers, 1 temporal.
385 // Note for this case, we set the buffer idx for all references to be
386 // either LAST or GOLDEN, which are always valid references, since decoder
387 // will check if any of the 7 references is valid scale in
388 // valid_ref_frame_size().
389 layer_id->temporal_layer_id = 0;
390 if (layer_id->spatial_layer_id == 0) {
391 // Reference LAST, update LAST. Set all buffer_idx to 0.
392 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
393 ref_frame_config->ref_idx[i] = 0;
394 ref_frame_config->refresh[0] = 1;
395 layer_flags |= AOM_EFLAG_NO_REF_GF;
396 } else if (layer_id->spatial_layer_id == 1) {
397 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1
398 // and GOLDEN (and all other refs) to slot 0.
399 // Update slot 1 (LAST).
400 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
401 ref_frame_config->ref_idx[i] = 0;
402 ref_frame_config->ref_idx[0] = 1;
403 ref_frame_config->refresh[1] = 1;
404 } else if (layer_id->spatial_layer_id == 2) {
405 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2
406 // and GOLDEN (and all other refs) to slot 1.
407 // Update slot 2 (LAST).
408 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
409 ref_frame_config->ref_idx[i] = 1;
410 ref_frame_config->ref_idx[0] = 2;
411 ref_frame_config->refresh[2] = 1;
412 }
413 break;
414 case 7:
415 // 3 spatial and 3 temporal layer.
416 // Same as case 8 but overalap in the buffer slot updates.
417 // (shift = 2). The slots 3 and 4 updated by first TL2 are
418 // reused for update in TL1 superframe.
419 // Note for this case, frame order hint must be disabled for
420 // lower resolutios (operating points > 0) to be decoedable.
421 case 8:
422 // 3 spatial and 3 temporal layer.
423 // No overlap in buffer updates between TL2 and TL1.
424 // TL2 updates slot 3 and 4, TL1 updates 5, 6, 7.
425 // Set the references via the svc_ref_frame_config control.
426 layer_flags = 0;
427 // Always reference LAST.
428 ref_frame_config->reference[0] = 1;
429 if (superframe_cnt % 4 == 0) {
430 // Base temporal layer.
431 layer_id->temporal_layer_id = 0;
432 if (layer_id->spatial_layer_id == 0) {
433 // Reference LAST, update LAST.
434 // Set all buffer_idx to 0.
435 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
436 ref_frame_config->ref_idx[i] = 0;
437 ref_frame_config->refresh[0] = 1;
438 } else if (layer_id->spatial_layer_id == 1) {
439 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
440 // GOLDEN (and all other refs) to slot 0.
441 // Update slot 1 (LAST).
442 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
443 ref_frame_config->ref_idx[i] = 0;
444 ref_frame_config->ref_idx[0] = 1;
445 ref_frame_config->refresh[1] = 1;
446 } else if (layer_id->spatial_layer_id == 2) {
447 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
448 // GOLDEN (and all other refs) to slot 1.
449 // Update slot 2 (LAST).
450 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
451 ref_frame_config->ref_idx[i] = 1;
452 ref_frame_config->ref_idx[0] = 2;
453 ref_frame_config->refresh[2] = 1;
454 }
455 } else if ((superframe_cnt - 1) % 4 == 0) {
456 // First top temporal enhancement layer.
457 layer_id->temporal_layer_id = 2;
458 if (layer_id->spatial_layer_id == 0) {
459 // Reference LAST (slot 0).
460 // Set GOLDEN to slot 3 and update slot 3.
461 // Set all other buffer_idx to slot 0.
462 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
463 ref_frame_config->ref_idx[i] = 0;
464 ref_frame_config->ref_idx[3] = 3;
465 ref_frame_config->refresh[3] = 1;
466 } else if (layer_id->spatial_layer_id == 1) {
467 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
468 // GOLDEN (and all other refs) to slot 3.
469 // Set LAST2 to slot 4 and Update slot 4.
470 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
471 ref_frame_config->ref_idx[i] = 3;
472 ref_frame_config->ref_idx[0] = 1;
473 ref_frame_config->ref_idx[1] = 4;
474 ref_frame_config->refresh[4] = 1;
475 } else if (layer_id->spatial_layer_id == 2) {
476 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
477 // GOLDEN (and all other refs) to slot 4.
478 // No update.
479 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
480 ref_frame_config->ref_idx[i] = 4;
481 ref_frame_config->ref_idx[0] = 2;
482 }
483 } else if ((superframe_cnt - 2) % 4 == 0) {
484 // Middle temporal enhancement layer.
485 layer_id->temporal_layer_id = 1;
486 if (layer_id->spatial_layer_id == 0) {
487 // Reference LAST.
488 // Set all buffer_idx to 0.
489 // Set GOLDEN to slot 5 and update slot 5.
490 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
491 ref_frame_config->ref_idx[i] = 0;
492 ref_frame_config->ref_idx[3] = 5 - shift;
493 ref_frame_config->refresh[5 - shift] = 1;
494 } else if (layer_id->spatial_layer_id == 1) {
495 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
496 // GOLDEN (and all other refs) to slot 5.
497 // Set LAST2 to slot 6 and update slot 6.
498 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
499 ref_frame_config->ref_idx[i] = 5 - shift;
500 ref_frame_config->ref_idx[0] = 1;
501 ref_frame_config->ref_idx[2] = 6 - shift;
502 ref_frame_config->refresh[6 - shift] = 1;
503 } else if (layer_id->spatial_layer_id == 2) {
504 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
505 // GOLDEN (and all other refs) to slot 6.
506 // Set LAST2 to slot 6 and update slot 7.
507 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
508 ref_frame_config->ref_idx[i] = 6 - shift;
509 ref_frame_config->ref_idx[0] = 2;
510 ref_frame_config->ref_idx[2] = 7 - shift;
511 ref_frame_config->refresh[7 - shift] = 1;
512 }
513 } else if ((superframe_cnt - 3) % 4 == 0) {
514 // Second top temporal enhancement layer.
515 layer_id->temporal_layer_id = 2;
516 if (layer_id->spatial_layer_id == 0) {
517 // Set LAST to slot 5 and reference LAST.
518 // Set GOLDEN to slot 3 and update slot 3.
519 // Set all other buffer_idx to 0.
520 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
521 ref_frame_config->ref_idx[i] = 0;
522 ref_frame_config->ref_idx[0] = 5 - shift;
523 ref_frame_config->ref_idx[3] = 3;
524 ref_frame_config->refresh[3] = 1;
525 } else if (layer_id->spatial_layer_id == 1) {
526 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 6,
527 // GOLDEN to slot 3. Set LAST2 to slot 4 and update slot 4.
528 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
529 ref_frame_config->ref_idx[i] = 0;
530 ref_frame_config->ref_idx[0] = 6 - shift;
531 ref_frame_config->ref_idx[3] = 3;
532 ref_frame_config->ref_idx[1] = 4;
533 ref_frame_config->refresh[4] = 1;
534 } else if (layer_id->spatial_layer_id == 2) {
535 // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 7,
536 // GOLDEN to slot 4. No update.
537 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
538 ref_frame_config->ref_idx[i] = 0;
539 ref_frame_config->ref_idx[0] = 7 - shift;
540 ref_frame_config->ref_idx[3] = 4;
541 }
542 }
543 if (layer_id->spatial_layer_id > 0)
544 ref_frame_config->reference[3] = 1; // Reference GOLDEN.
545 break;
546 default: assert(0); die("Error: Unsupported temporal layering mode!\n");
547 }
548 return layer_flags;
549 }
550
551 int main(int argc, char **argv) {
552 AvxVideoWriter *outfile[AOM_MAX_LAYERS] = { NULL };
553 aom_codec_ctx_t codec;
554 aom_codec_enc_cfg_t cfg;
555 int frame_cnt = 0;
556 aom_image_t raw;
557 aom_codec_err_t res;
558 unsigned int width;
559 unsigned int height;
560 uint32_t error_resilient = 0;
561 int speed;
562 int frame_avail;
563 int got_data = 0;
564 int flags = 0;
565 unsigned i;
566 int pts = 0; // PTS starts at 0.
567 int frame_duration = 1; // 1 timebase tick per frame.
568 int layering_mode = 0;
569 aom_svc_layer_id_t layer_id;
570 aom_svc_params_t svc_params;
571 aom_svc_ref_frame_config_t ref_frame_config;
572 const AvxInterface *encoder = NULL;
573 struct AvxInputContext input_ctx;
574 struct RateControlMetrics rc;
575 int64_t cx_time = 0;
576 const int min_args_base = 13;
577 const int min_args = min_args_base;
578 double sum_bitrate = 0.0;
579 double sum_bitrate2 = 0.0;
580 double framerate = 30.0;
581 int use_svc_control = 1;
582 zero(rc.layer_target_bitrate);
583 memset(&layer_id, 0, sizeof(aom_svc_layer_id_t));
584 memset(&input_ctx, 0, sizeof(input_ctx));
585 memset(&svc_params, 0, sizeof(svc_params));
586
587 // Flag to test dynamic scaling of source frames for single
588 // spatial stream, using the scaling_mode control.
589 const int test_dynamic_scaling_single_layer = 0;
590
591 /* Setup default input stream settings */
592 input_ctx.framerate.numerator = 30;
593 input_ctx.framerate.denominator = 1;
594 input_ctx.only_i420 = 1;
595 input_ctx.bit_depth = 0;
596 unsigned int ts_number_layers = 1;
597 unsigned int ss_number_layers = 1;
598 exec_name = argv[0];
599 // Check usage and arguments.
600 if (argc < min_args) {
601 die("Usage: %s <infile> <outfile> <codec_type(av1)> <width> <height> "
602 "<rate_num> <rate_den> <speed> <frame_drop_threshold> "
603 "<error_resilient> <threads> <mode> "
604 "<Rate_0> ... <Rate_nlayers-1>\n",
605 argv[0]);
606 }
607
608 encoder = get_aom_encoder_by_name(argv[3]);
609
610 width = (unsigned int)strtoul(argv[4], NULL, 0);
611 height = (unsigned int)strtoul(argv[5], NULL, 0);
612 if (width < 16 || width % 2 || height < 16 || height % 2) {
613 die("Invalid resolution: %d x %d", width, height);
614 }
615
616 layering_mode = (int)strtol(argv[12], NULL, 0);
617 if (layering_mode < 0 || layering_mode > 13) {
618 die("Invalid layering mode (0..12) %s", argv[12]);
619 }
620
621 if (argc != min_args + mode_to_num_layers[layering_mode]) {
622 die("Invalid number of arguments");
623 }
624
625 ts_number_layers = mode_to_num_temporal_layers[layering_mode];
626 ss_number_layers = mode_to_num_spatial_layers[layering_mode];
627
628 input_ctx.filename = argv[1];
629 open_input_file(&input_ctx, 0);
630
631 // Y4M reader has its own allocation.
632 if (input_ctx.file_type != FILE_TYPE_Y4M) {
633 if (!aom_img_alloc(&raw, AOM_IMG_FMT_I420, width, height, 32)) {
634 die("Failed to allocate image", width, height);
635 }
636 }
637
638 // Populate encoder configuration.
639 res = aom_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
640 if (res) {
641 printf("Failed to get config: %s\n", aom_codec_err_to_string(res));
642 return EXIT_FAILURE;
643 }
644
645 // Update the default configuration with our settings.
646 cfg.g_w = width;
647 cfg.g_h = height;
648
649 // Timebase format e.g. 30fps: numerator=1, demoninator = 30.
650 cfg.g_timebase.num = (int)strtol(argv[6], NULL, 0);
651 cfg.g_timebase.den = (int)strtol(argv[7], NULL, 0);
652
653 speed = (int)strtol(argv[8], NULL, 0);
654 if (speed < 0 || speed > 8) {
655 die("Invalid speed setting: must be positive");
656 }
657
658 for (i = min_args_base;
659 (int)i < min_args_base + mode_to_num_layers[layering_mode]; ++i) {
660 rc.layer_target_bitrate[i - 13] = (int)strtol(argv[i], NULL, 0);
661 svc_params.layer_target_bitrate[i - 13] = rc.layer_target_bitrate[i - 13];
662 }
663
664 cfg.rc_target_bitrate =
665 svc_params.layer_target_bitrate[ss_number_layers * ts_number_layers - 1];
666
667 svc_params.framerate_factor[0] = 1;
668 if (ts_number_layers == 2) {
669 svc_params.framerate_factor[0] = 2;
670 svc_params.framerate_factor[1] = 1;
671 } else if (ts_number_layers == 3) {
672 svc_params.framerate_factor[0] = 4;
673 svc_params.framerate_factor[1] = 2;
674 svc_params.framerate_factor[2] = 1;
675 }
676
677 // Real time parameters.
678 cfg.g_usage = AOM_USAGE_REALTIME;
679
680 cfg.rc_dropframe_thresh = (unsigned int)strtoul(argv[9], NULL, 0);
681 cfg.rc_end_usage = AOM_CBR;
682 cfg.rc_min_quantizer = 2;
683 cfg.rc_max_quantizer = 52;
684 cfg.rc_undershoot_pct = 50;
685 cfg.rc_overshoot_pct = 50;
686 cfg.rc_buf_initial_sz = 600;
687 cfg.rc_buf_optimal_sz = 600;
688 cfg.rc_buf_sz = 1000;
689
690 // Use 1 thread as default.
691 cfg.g_threads = (unsigned int)strtoul(argv[11], NULL, 0);
692
693 error_resilient = (uint32_t)strtoul(argv[10], NULL, 0);
694 if (error_resilient != 0 && error_resilient != 1) {
695 die("Invalid value for error resilient (0, 1): %d.", error_resilient);
696 }
697 // Enable error resilient mode.
698 cfg.g_error_resilient = error_resilient;
699 cfg.g_lag_in_frames = 0;
700 cfg.kf_mode = AOM_KF_AUTO;
701
702 // Disable automatic keyframe placement.
703 cfg.kf_min_dist = cfg.kf_max_dist = 3000;
704
705 framerate = cfg.g_timebase.den / cfg.g_timebase.num;
706 set_rate_control_metrics(&rc, framerate, ss_number_layers, ts_number_layers);
707
708 if (input_ctx.file_type == FILE_TYPE_Y4M) {
709 if (input_ctx.width != cfg.g_w || input_ctx.height != cfg.g_h) {
710 die("Incorrect width or height: %d x %d", cfg.g_w, cfg.g_h);
711 }
712 if (input_ctx.framerate.numerator != cfg.g_timebase.den ||
713 input_ctx.framerate.denominator != cfg.g_timebase.num) {
714 die("Incorrect framerate: numerator %d denominator %d",
715 cfg.g_timebase.num, cfg.g_timebase.den);
716 }
717 }
718
719 // Open an output file for each stream.
720 for (unsigned int sl = 0; sl < ss_number_layers; ++sl) {
721 for (unsigned tl = 0; tl < ts_number_layers; ++tl) {
722 i = sl * ts_number_layers + tl;
723 char file_name[PATH_MAX];
724 AvxVideoInfo info;
725 info.codec_fourcc = encoder->fourcc;
726 info.frame_width = cfg.g_w;
727 info.frame_height = cfg.g_h;
728 info.time_base.numerator = cfg.g_timebase.num;
729 info.time_base.denominator = cfg.g_timebase.den;
730
731 snprintf(file_name, sizeof(file_name), "%s_%d.av1", argv[2], i);
732 outfile[i] = aom_video_writer_open(file_name, kContainerIVF, &info);
733 if (!outfile[i]) die("Failed to open %s for writing", file_name);
734 assert(outfile[i] != NULL);
735 }
736 }
737
738 // Initialize codec.
739 if (aom_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
740 die_codec(&codec, "Failed to initialize encoder");
741
742 aom_codec_control(&codec, AOME_SET_CPUUSED, speed);
743 aom_codec_control(&codec, AV1E_SET_AQ_MODE, 3);
744 aom_codec_control(&codec, AV1E_SET_GF_CBR_BOOST_PCT, 0);
745 aom_codec_control(&codec, AV1E_SET_ENABLE_CDEF, 1);
746 aom_codec_control(&codec, AV1E_SET_ENABLE_ORDER_HINT, 0);
747 aom_codec_control(&codec, AV1E_SET_ENABLE_TPL_MODEL, 0);
748 aom_codec_control(&codec, AV1E_SET_DELTAQ_MODE, 0);
749
750 svc_params.number_spatial_layers = ss_number_layers;
751 svc_params.number_temporal_layers = ts_number_layers;
752 for (i = 0; i < ss_number_layers * ts_number_layers; ++i) {
753 svc_params.max_quantizers[i] = cfg.rc_max_quantizer;
754 svc_params.min_quantizers[i] = cfg.rc_min_quantizer;
755 }
756 for (i = 0; i < ss_number_layers; ++i) {
757 svc_params.scaling_factor_num[i] = 1;
758 svc_params.scaling_factor_den[i] = 1;
759 }
760 if (ss_number_layers == 2) {
761 svc_params.scaling_factor_num[0] = 1;
762 svc_params.scaling_factor_den[0] = 2;
763 } else if (ss_number_layers == 3) {
764 svc_params.scaling_factor_num[0] = 1;
765 svc_params.scaling_factor_den[0] = 4;
766 svc_params.scaling_factor_num[1] = 1;
767 svc_params.scaling_factor_den[1] = 2;
768 }
769
770 aom_codec_control(&codec, AV1E_SET_SVC_PARAMS, &svc_params);
771
772 // This controls the maximum target size of the key frame.
773 // For generating smaller key frames, use a smaller max_intra_size_pct
774 // value, like 100 or 200.
775 {
776 const int max_intra_size_pct = 300;
777 aom_codec_control(&codec, AOME_SET_MAX_INTRA_BITRATE_PCT,
778 max_intra_size_pct);
779 }
780
781 frame_avail = 1;
782 while (frame_avail || got_data) {
783 struct aom_usec_timer timer;
784 frame_avail = read_frame(&input_ctx, &raw);
785 int is_key_frame = (frame_cnt % cfg.kf_max_dist) == 0;
786 // Loop over spatial layers.
787 for (unsigned int slx = 0; slx < ss_number_layers; slx++) {
788 aom_codec_iter_t iter = NULL;
789 const aom_codec_cx_pkt_t *pkt;
790 int layer = 0;
791
792 // Set the reference/update flags, layer_id, and reference_map
793 // buffer index.
794 flags = set_layer_pattern(layering_mode, frame_cnt, &layer_id,
795 &ref_frame_config, &use_svc_control, slx,
796 is_key_frame, (layering_mode == 9));
797 aom_codec_control(&codec, AV1E_SET_SVC_LAYER_ID, &layer_id);
798 if (use_svc_control)
799 aom_codec_control(&codec, AV1E_SET_SVC_REF_FRAME_CONFIG,
800 &ref_frame_config);
801
802 layer = slx * ts_number_layers + layer_id.temporal_layer_id;
803 if (frame_avail && slx == 0) ++rc.layer_input_frames[layer];
804
805 if (test_dynamic_scaling_single_layer) {
806 if (frame_cnt >= 200 && frame_cnt <= 400) {
807 // Scale source down by 2x2.
808 struct aom_scaling_mode mode = { AOME_ONETWO, AOME_ONETWO };
809 aom_codec_control(&codec, AOME_SET_SCALEMODE, &mode);
810 } else {
811 // Source back up to original resolution (no scaling).
812 struct aom_scaling_mode mode = { AOME_NORMAL, AOME_NORMAL };
813 aom_codec_control(&codec, AOME_SET_SCALEMODE, &mode);
814 }
815 }
816
817 // Do the layer encode.
818 aom_usec_timer_start(&timer);
819 if (aom_codec_encode(&codec, frame_avail ? &raw : NULL, pts, 1, flags))
820 die_codec(&codec, "Failed to encode frame");
821 aom_usec_timer_mark(&timer);
822 cx_time += aom_usec_timer_elapsed(&timer);
823
824 got_data = 0;
825 while ((pkt = aom_codec_get_cx_data(&codec, &iter))) {
826 got_data = 1;
827 switch (pkt->kind) {
828 case AOM_CODEC_CX_FRAME_PKT:
829 for (unsigned int sl = layer_id.spatial_layer_id;
830 sl < ss_number_layers; ++sl) {
831 for (unsigned tl = layer_id.temporal_layer_id;
832 tl < ts_number_layers; ++tl) {
833 unsigned int j = sl * ts_number_layers + tl;
834 aom_video_writer_write_frame(outfile[j], pkt->data.frame.buf,
835 pkt->data.frame.sz, pts);
836 if (sl == (unsigned int)layer_id.spatial_layer_id)
837 rc.layer_encoding_bitrate[j] += 8.0 * pkt->data.frame.sz;
838 // Keep count of rate control stats per layer (for non-key).
839 if (tl == (unsigned int)layer_id.temporal_layer_id &&
840 sl == (unsigned int)layer_id.spatial_layer_id &&
841 !(pkt->data.frame.flags & AOM_FRAME_IS_KEY)) {
842 rc.layer_avg_frame_size[j] += 8.0 * pkt->data.frame.sz;
843 rc.layer_avg_rate_mismatch[j] +=
844 fabs(8.0 * pkt->data.frame.sz - rc.layer_pfb[j]) /
845 rc.layer_pfb[j];
846 if (slx == 0) ++rc.layer_enc_frames[tl];
847 }
848 }
849 }
850
851 // Update for short-time encoding bitrate states, for moving window
852 // of size rc->window, shifted by rc->window / 2.
853 // Ignore first window segment, due to key frame.
854 // For spatial layers: only do this for top/highest SL.
855 if (frame_cnt > rc.window_size && slx == ss_number_layers - 1) {
856 sum_bitrate += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
857 rc.window_size = (rc.window_size <= 0) ? 1 : rc.window_size;
858 if (frame_cnt % rc.window_size == 0) {
859 rc.window_count += 1;
860 rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
861 rc.variance_st_encoding_bitrate +=
862 (sum_bitrate / rc.window_size) *
863 (sum_bitrate / rc.window_size);
864 sum_bitrate = 0.0;
865 }
866 }
867 // Second shifted window.
868 if (frame_cnt > rc.window_size + rc.window_size / 2 &&
869 slx == ss_number_layers - 1) {
870 sum_bitrate2 += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
871 if (frame_cnt > 2 * rc.window_size &&
872 frame_cnt % rc.window_size == 0) {
873 rc.window_count += 1;
874 rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
875 rc.variance_st_encoding_bitrate +=
876 (sum_bitrate2 / rc.window_size) *
877 (sum_bitrate2 / rc.window_size);
878 sum_bitrate2 = 0.0;
879 }
880 }
881 break;
882 default: break;
883 }
884 }
885 } // loop over spatial layers
886 ++frame_cnt;
887 pts += frame_duration;
888 }
889 close_input_file(&input_ctx);
890 printout_rate_control_summary(&rc, frame_cnt, ss_number_layers,
891 ts_number_layers);
892 printf("\n");
893 printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f\n",
894 frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
895 1000000 * (double)frame_cnt / (double)cx_time);
896
897 if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
898
899 // Try to rewrite the output file headers with the actual frame count.
900 for (i = 0; i < ss_number_layers * ts_number_layers; ++i)
901 aom_video_writer_close(outfile[i]);
902
903 if (input_ctx.file_type != FILE_TYPE_Y4M) {
904 aom_img_free(&raw);
905 }
906 return EXIT_SUCCESS;
907 }
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:1014
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
aom_scaling_mode
aom image scaling mode
Definition: aomcx.h:1317
AOME_SET_CPUUSED
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition: aomcx.h:192
aom_svc_params::framerate_factor
int framerate_factor[8]
Definition: aomcx.h:1371
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:1362
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, unsigned int parameter.
Definition: aomcx.h:426
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, unsigned int parameter.
Definition: aomcx.h:302
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:1381
aom_codec_ctx
Codec context structure.
Definition: aom_codec.h:219
aom_codec_enc_cfg::rc_buf_sz
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition: aom_encoder.h:689
aom_svc_ref_frame_config::reference
int reference[7]
Definition: aomcx.h:1378
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, unsigned int parameter.
Definition: aomcx.h:1066
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:1364
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:1363
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:1355
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_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, aom_svc_layer_id_t* parameter.
Definition: aomcx.h:1214
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:1375
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 usage)
Get the default configuration for a usage.
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:1366
aom_svc_params::layer_target_bitrate
int layer_target_bitrate[32]
Definition: aomcx.h:1369
aom_svc_params::min_quantizers
int min_quantizers[32]
Definition: aomcx.h:1365
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:1352
aom_svc_params
Definition: aomcx.h:1361
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:1350
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.
AOME_SET_SCALEMODE
@ AOME_SET_SCALEMODE
Codec control function to set encoder scaling mode, aom_scaling_mode_t* parameter.
Definition: aomcx.h:174
aom_svc_params::scaling_factor_den
int scaling_factor_den[4]
Definition: aomcx.h:1367
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, unsigned int parameter.
Definition: aomcx.h:269
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, unsigned int parameter.
Definition: aomcx.h:622
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 (int parameter). Affects: joint compound mod...
Definition: aomcx.h:813
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, aom_svc_params_t* parameter.
Definition: aomcx.h:1219
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:1225
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_iter_t
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:209
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:1356
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:941
aom_image
Image Descriptor.
Definition: aom_image.h:171
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, unsigned int parameter.
Definition: aomcx.h:369
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:1380
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_codec_control
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
AOM_EFLAG_NO_REF_ARF
#define AOM_EFLAG_NO_REF_ARF
Don't reference the alternate reference frame.
Definition: aomcx.h:79
aom_svc_layer_id::temporal_layer_id
int temporal_layer_id
Definition: aomcx.h:1357
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