12 #include "apps/aomenc.h"
14 #include "config/aom_config.h"
24 #if CONFIG_AV1_DECODER
30 #include "aom/aom_integer.h"
32 #include "aom_dsp/aom_dsp_common.h"
33 #include "aom_ports/aom_timer.h"
34 #include "aom_ports/mem_ops.h"
35 #include "common/args.h"
36 #include "common/ivfenc.h"
37 #include "common/tools_common.h"
38 #include "common/warnings.h"
41 #include "common/webmenc.h"
44 #include "common/y4minput.h"
45 #include "examples/encoder_util.h"
46 #include "stats/aomstats.h"
47 #include "stats/rate_hist.h"
50 #include "third_party/libyuv/include/libyuv/scale.h"
54 static size_t wrap_fread(
void *ptr,
size_t size,
size_t nmemb, FILE *stream) {
55 return fread(ptr, size, nmemb, stream);
57 #define fread wrap_fread
59 static size_t wrap_fwrite(
const void *ptr,
size_t size,
size_t nmemb,
61 return fwrite(ptr, size, nmemb, stream);
63 #define fwrite wrap_fwrite
65 static const char *exec_name;
68 const char *s, va_list ap) {
72 vfprintf(stderr, s, ap);
75 if (detail) fprintf(stderr,
" %s\n", detail);
77 if (fatal) exit(EXIT_FAILURE);
81 static void ctx_exit_on_error(
aom_codec_ctx_t *ctx,
const char *s, ...) {
85 warn_or_exit_on_errorv(ctx, 1, s, ap);
94 warn_or_exit_on_errorv(ctx, fatal, s, ap);
98 static int read_frame(
struct AvxInputContext *input_ctx,
aom_image_t *img) {
99 FILE *f = input_ctx->file;
100 y4m_input *y4m = &input_ctx->y4m;
103 if (input_ctx->file_type == FILE_TYPE_Y4M) {
104 if (y4m_input_fetch_frame(y4m, f, img) < 1)
return 0;
106 shortread = read_yuv_frame(input_ctx, img);
112 static int file_is_y4m(
const char detect[4]) {
113 if (memcmp(detect,
"YUV4", 4) == 0) {
119 static int fourcc_is_ivf(
const char detect[4]) {
120 if (memcmp(detect,
"DKIF", 4) == 0) {
215 AV1E_SET_ENABLE_DNL_DENOISING,
231 const arg_def_t *main_args[] = { &g_av1_codec_arg_defs.help,
232 &g_av1_codec_arg_defs.use_cfg,
233 &g_av1_codec_arg_defs.debugmode,
234 &g_av1_codec_arg_defs.outputfile,
235 &g_av1_codec_arg_defs.codecarg,
236 &g_av1_codec_arg_defs.passes,
237 &g_av1_codec_arg_defs.pass_arg,
238 &g_av1_codec_arg_defs.fpf_name,
239 &g_av1_codec_arg_defs.limit,
240 &g_av1_codec_arg_defs.skip,
241 &g_av1_codec_arg_defs.good_dl,
242 &g_av1_codec_arg_defs.rt_dl,
243 &g_av1_codec_arg_defs.quietarg,
244 &g_av1_codec_arg_defs.verbosearg,
245 &g_av1_codec_arg_defs.psnrarg,
246 &g_av1_codec_arg_defs.use_webm,
247 &g_av1_codec_arg_defs.use_ivf,
248 &g_av1_codec_arg_defs.use_obu,
249 &g_av1_codec_arg_defs.q_hist_n,
250 &g_av1_codec_arg_defs.rate_hist_n,
251 &g_av1_codec_arg_defs.disable_warnings,
252 &g_av1_codec_arg_defs.disable_warning_prompt,
253 &g_av1_codec_arg_defs.recontest,
256 const arg_def_t *global_args[] = {
257 &g_av1_codec_arg_defs.use_yv12,
258 &g_av1_codec_arg_defs.use_i420,
259 &g_av1_codec_arg_defs.use_i422,
260 &g_av1_codec_arg_defs.use_i444,
261 &g_av1_codec_arg_defs.usage,
262 &g_av1_codec_arg_defs.threads,
263 &g_av1_codec_arg_defs.profile,
264 &g_av1_codec_arg_defs.width,
265 &g_av1_codec_arg_defs.height,
266 &g_av1_codec_arg_defs.forced_max_frame_width,
267 &g_av1_codec_arg_defs.forced_max_frame_height,
269 &g_av1_codec_arg_defs.stereo_mode,
271 &g_av1_codec_arg_defs.timebase,
272 &g_av1_codec_arg_defs.framerate,
273 &g_av1_codec_arg_defs.global_error_resilient,
274 &g_av1_codec_arg_defs.bitdeptharg,
275 &g_av1_codec_arg_defs.inbitdeptharg,
276 &g_av1_codec_arg_defs.lag_in_frames,
277 &g_av1_codec_arg_defs.large_scale_tile,
278 &g_av1_codec_arg_defs.monochrome,
279 &g_av1_codec_arg_defs.full_still_picture_hdr,
280 &g_av1_codec_arg_defs.use_16bit_internal,
281 &g_av1_codec_arg_defs.save_as_annexb,
285 const arg_def_t *rc_args[] = { &g_av1_codec_arg_defs.dropframe_thresh,
286 &g_av1_codec_arg_defs.resize_mode,
287 &g_av1_codec_arg_defs.resize_denominator,
288 &g_av1_codec_arg_defs.resize_kf_denominator,
289 &g_av1_codec_arg_defs.superres_mode,
290 &g_av1_codec_arg_defs.superres_denominator,
291 &g_av1_codec_arg_defs.superres_kf_denominator,
292 &g_av1_codec_arg_defs.superres_qthresh,
293 &g_av1_codec_arg_defs.superres_kf_qthresh,
294 &g_av1_codec_arg_defs.end_usage,
295 &g_av1_codec_arg_defs.target_bitrate,
296 &g_av1_codec_arg_defs.min_quantizer,
297 &g_av1_codec_arg_defs.max_quantizer,
298 &g_av1_codec_arg_defs.undershoot_pct,
299 &g_av1_codec_arg_defs.overshoot_pct,
300 &g_av1_codec_arg_defs.buf_sz,
301 &g_av1_codec_arg_defs.buf_initial_sz,
302 &g_av1_codec_arg_defs.buf_optimal_sz,
303 &g_av1_codec_arg_defs.bias_pct,
304 &g_av1_codec_arg_defs.minsection_pct,
305 &g_av1_codec_arg_defs.maxsection_pct,
308 const arg_def_t *kf_args[] = { &g_av1_codec_arg_defs.fwd_kf_enabled,
309 &g_av1_codec_arg_defs.kf_min_dist,
310 &g_av1_codec_arg_defs.kf_max_dist,
311 &g_av1_codec_arg_defs.kf_disabled,
312 &g_av1_codec_arg_defs.sframe_dist,
313 &g_av1_codec_arg_defs.sframe_mode,
316 const arg_def_t *av1_args[] = {
317 &g_av1_codec_arg_defs.cpu_used_av1,
318 &g_av1_codec_arg_defs.auto_altref,
319 &g_av1_codec_arg_defs.sharpness,
320 &g_av1_codec_arg_defs.static_thresh,
321 &g_av1_codec_arg_defs.rowmtarg,
322 &g_av1_codec_arg_defs.tile_cols,
323 &g_av1_codec_arg_defs.tile_rows,
324 &g_av1_codec_arg_defs.enable_tpl_model,
325 &g_av1_codec_arg_defs.enable_keyframe_filtering,
326 &g_av1_codec_arg_defs.arnr_maxframes,
327 &g_av1_codec_arg_defs.arnr_strength,
328 &g_av1_codec_arg_defs.tune_metric,
329 &g_av1_codec_arg_defs.cq_level,
330 &g_av1_codec_arg_defs.max_intra_rate_pct,
331 &g_av1_codec_arg_defs.max_inter_rate_pct,
332 &g_av1_codec_arg_defs.gf_cbr_boost_pct,
333 &g_av1_codec_arg_defs.lossless,
334 &g_av1_codec_arg_defs.enable_cdef,
335 &g_av1_codec_arg_defs.enable_restoration,
336 &g_av1_codec_arg_defs.enable_rect_partitions,
337 &g_av1_codec_arg_defs.enable_ab_partitions,
338 &g_av1_codec_arg_defs.enable_1to4_partitions,
339 &g_av1_codec_arg_defs.min_partition_size,
340 &g_av1_codec_arg_defs.max_partition_size,
341 &g_av1_codec_arg_defs.enable_dual_filter,
342 &g_av1_codec_arg_defs.enable_chroma_deltaq,
343 &g_av1_codec_arg_defs.enable_intra_edge_filter,
344 &g_av1_codec_arg_defs.enable_order_hint,
345 &g_av1_codec_arg_defs.enable_tx64,
346 &g_av1_codec_arg_defs.enable_flip_idtx,
347 &g_av1_codec_arg_defs.enable_rect_tx,
348 &g_av1_codec_arg_defs.enable_dist_wtd_comp,
349 &g_av1_codec_arg_defs.enable_masked_comp,
350 &g_av1_codec_arg_defs.enable_onesided_comp,
351 &g_av1_codec_arg_defs.enable_interintra_comp,
352 &g_av1_codec_arg_defs.enable_smooth_interintra,
353 &g_av1_codec_arg_defs.enable_diff_wtd_comp,
354 &g_av1_codec_arg_defs.enable_interinter_wedge,
355 &g_av1_codec_arg_defs.enable_interintra_wedge,
356 &g_av1_codec_arg_defs.enable_global_motion,
357 &g_av1_codec_arg_defs.enable_warped_motion,
358 &g_av1_codec_arg_defs.enable_filter_intra,
359 &g_av1_codec_arg_defs.enable_smooth_intra,
360 &g_av1_codec_arg_defs.enable_paeth_intra,
361 &g_av1_codec_arg_defs.enable_cfl_intra,
362 &g_av1_codec_arg_defs.force_video_mode,
363 &g_av1_codec_arg_defs.enable_obmc,
364 &g_av1_codec_arg_defs.enable_overlay,
365 &g_av1_codec_arg_defs.enable_palette,
366 &g_av1_codec_arg_defs.enable_intrabc,
367 &g_av1_codec_arg_defs.enable_angle_delta,
368 &g_av1_codec_arg_defs.disable_trellis_quant,
369 &g_av1_codec_arg_defs.enable_qm,
370 &g_av1_codec_arg_defs.qm_min,
371 &g_av1_codec_arg_defs.qm_max,
372 &g_av1_codec_arg_defs.reduced_tx_type_set,
373 &g_av1_codec_arg_defs.use_intra_dct_only,
374 &g_av1_codec_arg_defs.use_inter_dct_only,
375 &g_av1_codec_arg_defs.use_intra_default_tx_only,
376 &g_av1_codec_arg_defs.quant_b_adapt,
377 &g_av1_codec_arg_defs.coeff_cost_upd_freq,
378 &g_av1_codec_arg_defs.mode_cost_upd_freq,
379 &g_av1_codec_arg_defs.mv_cost_upd_freq,
380 &g_av1_codec_arg_defs.frame_parallel_decoding,
381 &g_av1_codec_arg_defs.error_resilient_mode,
382 &g_av1_codec_arg_defs.aq_mode,
383 &g_av1_codec_arg_defs.deltaq_mode,
384 &g_av1_codec_arg_defs.deltalf_mode,
385 &g_av1_codec_arg_defs.frame_periodic_boost,
386 &g_av1_codec_arg_defs.noise_sens,
387 &g_av1_codec_arg_defs.tune_content,
388 &g_av1_codec_arg_defs.cdf_update_mode,
389 &g_av1_codec_arg_defs.input_color_primaries,
390 &g_av1_codec_arg_defs.input_transfer_characteristics,
391 &g_av1_codec_arg_defs.input_matrix_coefficients,
392 &g_av1_codec_arg_defs.input_chroma_sample_position,
393 &g_av1_codec_arg_defs.min_gf_interval,
394 &g_av1_codec_arg_defs.max_gf_interval,
395 &g_av1_codec_arg_defs.gf_min_pyr_height,
396 &g_av1_codec_arg_defs.gf_max_pyr_height,
397 &g_av1_codec_arg_defs.superblock_size,
398 &g_av1_codec_arg_defs.num_tg,
399 &g_av1_codec_arg_defs.mtu_size,
400 &g_av1_codec_arg_defs.timing_info,
401 &g_av1_codec_arg_defs.film_grain_test,
402 &g_av1_codec_arg_defs.film_grain_table,
404 &g_av1_codec_arg_defs.denoise_noise_level,
405 &g_av1_codec_arg_defs.denoise_block_size,
406 &g_av1_codec_arg_defs.enable_dnl_denoising,
408 &g_av1_codec_arg_defs.max_reference_frames,
409 &g_av1_codec_arg_defs.reduced_reference_set,
410 &g_av1_codec_arg_defs.enable_ref_frame_mvs,
411 &g_av1_codec_arg_defs.target_seq_level_idx,
412 &g_av1_codec_arg_defs.set_tier_mask,
413 &g_av1_codec_arg_defs.set_min_cr,
414 &g_av1_codec_arg_defs.vbr_corpus_complexity_lap,
415 &g_av1_codec_arg_defs.input_chroma_subsampling_x,
416 &g_av1_codec_arg_defs.input_chroma_subsampling_y,
418 &g_av1_codec_arg_defs.vmaf_model_path,
423 static const arg_def_t *no_args[] = { NULL };
425 static void show_help(FILE *fout,
int shorthelp) {
426 fprintf(fout,
"Usage: %s <options> -o dst_filename src_filename \n",
430 fprintf(fout,
"Use --help to see the full list of options.\n");
434 fprintf(fout,
"\nOptions:\n");
435 arg_show_usage(fout, main_args);
436 fprintf(fout,
"\nEncoder Global Options:\n");
437 arg_show_usage(fout, global_args);
438 fprintf(fout,
"\nRate Control Options:\n");
439 arg_show_usage(fout, rc_args);
440 fprintf(fout,
"\nKeyframe Placement Options:\n");
441 arg_show_usage(fout, kf_args);
442 #if CONFIG_AV1_ENCODER
443 fprintf(fout,
"\nAV1 Specific Options:\n");
444 arg_show_usage(fout, av1_args);
447 "\nStream timebase (--timebase):\n"
448 " The desired precision of timestamps in the output, expressed\n"
449 " in fractional seconds. Default is 1/1000.\n");
450 fprintf(fout,
"\nIncluded encoders:\n\n");
452 const int num_encoder = get_aom_encoder_count();
453 for (
int i = 0; i < num_encoder; ++i) {
455 const char *defstr = (i == (num_encoder - 1)) ?
"(default)" :
"";
456 fprintf(fout,
" %-6s - %s %s\n", get_short_name_by_aom_encoder(encoder),
459 fprintf(fout,
"\n ");
460 fprintf(fout,
"Use --codec to switch to a non-default encoder.\n\n");
463 void usage_exit(
void) {
464 show_help(stderr, 1);
468 #if CONFIG_AV1_ENCODER
469 #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
473 typedef int stereo_format_t;
474 struct WebmOutputContext {
480 struct stream_config {
483 const char *stats_fn;
484 stereo_format_t stereo_fmt;
485 int arg_ctrls[ARG_CTRL_CNT_MAX][2];
488 const char *film_grain_filename;
491 int use_16bit_internal;
493 const char *vmaf_model_path;
498 struct stream_state {
500 struct stream_state *next;
501 struct stream_config config;
503 struct rate_hist *rate_hist;
504 struct WebmOutputContext webm_ctx;
505 uint64_t psnr_sse_total[2];
506 uint64_t psnr_samples_total[2];
507 double psnr_totals[2][4];
511 unsigned int frames_out;
518 unsigned int chroma_subsampling_x;
519 unsigned int chroma_subsampling_y;
522 static void validate_positive_rational(
const char *msg,
529 if (rat->
num < 0) die(
"Error: %s must be positive\n", msg);
531 if (!rat->
den) die(
"Error: %s has zero denominator\n", msg);
545 static void parse_global_config(
struct AvxEncoderConfig *global,
char ***argv) {
548 const int num_encoder = get_aom_encoder_count();
549 char **argv_local = (
char **)*argv;
550 if (num_encoder < 1) die(
"Error: no valid encoder available\n");
553 memset(global, 0,
sizeof(*global));
554 global->codec = get_aom_encoder_by_index(num_encoder - 1);
556 global->color_type = I420;
558 global->show_psnr = 0;
560 int cfg_included = 0;
561 init_config(&global->encoder_config);
563 for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
566 if (arg_match(&arg, &g_av1_codec_arg_defs.use_cfg, argi)) {
568 parse_cfg(arg.val, &global->encoder_config);
571 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.help, argi)) {
572 show_help(stdout, 0);
574 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.codecarg, argi)) {
575 global->codec = get_aom_encoder_by_short_name(arg.val);
577 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
578 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.passes, argi)) {
579 global->passes = arg_parse_uint(&arg);
581 if (global->passes < 1 || global->passes > 2)
582 die(
"Error: Invalid number of passes (%d)\n", global->passes);
583 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.pass_arg, argi)) {
584 global->pass = arg_parse_uint(&arg);
586 if (global->pass < 1 || global->pass > 2)
587 die(
"Error: Invalid pass selected (%d)\n", global->pass);
588 }
else if (arg_match(&arg,
589 &g_av1_codec_arg_defs.input_chroma_sample_position,
591 global->csp = arg_parse_enum(&arg);
594 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.usage, argi)) {
595 global->usage = arg_parse_uint(&arg);
596 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.good_dl, argi)) {
598 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rt_dl, argi)) {
600 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_yv12, argi)) {
601 global->color_type = YV12;
602 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i420, argi)) {
603 global->color_type = I420;
604 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i422, argi)) {
605 global->color_type = I422;
606 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i444, argi)) {
607 global->color_type = I444;
608 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.quietarg, argi)) {
610 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.verbosearg, argi)) {
612 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.limit, argi)) {
613 global->limit = arg_parse_uint(&arg);
614 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.skip, argi)) {
615 global->skip_frames = arg_parse_uint(&arg);
616 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.psnrarg, argi)) {
618 global->show_psnr = arg_parse_int(&arg);
620 global->show_psnr = 1;
621 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.recontest, argi)) {
622 global->test_decode = arg_parse_enum_or_int(&arg);
623 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.framerate, argi)) {
624 global->framerate = arg_parse_rational(&arg);
625 validate_positive_rational(arg.name, &global->framerate);
626 global->have_framerate = 1;
627 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.debugmode, argi)) {
629 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.q_hist_n, argi)) {
630 global->show_q_hist_buckets = arg_parse_uint(&arg);
631 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_hist_n, argi)) {
632 global->show_rate_hist_buckets = arg_parse_uint(&arg);
633 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warnings, argi)) {
634 global->disable_warnings = 1;
635 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warning_prompt,
637 global->disable_warning_prompt = 1;
645 if (global->pass > global->passes) {
646 warn(
"Assuming --pass=%d implies --passes=%d\n", global->pass,
648 global->passes = global->pass;
652 if (global->passes == 0) {
653 #if CONFIG_AV1_ENCODER
656 if (global->codec != NULL)
658 (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0 &&
668 warn(
"Enforcing one-pass encoding in realtime mode\n");
673 static void open_input_file(
struct AvxInputContext *input,
676 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
677 : set_binary_mode(stdin);
679 if (!input->file) fatal(
"Failed to open input file");
681 if (!fseeko(input->file, 0, SEEK_END)) {
685 input->length = ftello(input->file);
690 input->pixel_aspect_ratio.numerator = 1;
691 input->pixel_aspect_ratio.denominator = 1;
696 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
697 input->detect.position = 0;
699 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
700 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
701 input->only_i420) >= 0) {
702 input->file_type = FILE_TYPE_Y4M;
703 input->width = input->y4m.pic_w;
704 input->height = input->y4m.pic_h;
705 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
706 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
707 input->framerate.numerator = input->y4m.fps_n;
708 input->framerate.denominator = input->y4m.fps_d;
709 input->fmt = input->y4m.aom_fmt;
710 input->bit_depth = input->y4m.bit_depth;
711 input->color_range = input->y4m.color_range;
713 fatal(
"Unsupported Y4M stream.");
714 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
715 fatal(
"IVF is not supported as input.");
717 input->file_type = FILE_TYPE_RAW;
721 static void close_input_file(
struct AvxInputContext *input) {
723 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
726 static struct stream_state *new_stream(
struct AvxEncoderConfig *global,
727 struct stream_state *prev) {
728 struct stream_state *stream;
730 stream = calloc(1,
sizeof(*stream));
731 if (stream == NULL) {
732 fatal(
"Failed to allocate new stream.");
736 memcpy(stream, prev,
sizeof(*stream));
750 stream->config.cfg.g_timebase.den = 1000;
755 stream->config.cfg.g_w = 0;
756 stream->config.cfg.g_h = 0;
759 stream->config.write_webm = 1;
760 stream->config.write_ivf = 0;
763 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
764 stream->webm_ctx.last_pts_ns = -1;
765 stream->webm_ctx.writer = NULL;
766 stream->webm_ctx.segment = NULL;
770 stream->webm_ctx.debug = global->debug;
771 memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
772 sizeof(stream->config.cfg.encoder_cfg));
776 stream->config.out_fn = NULL;
782 static void set_config_arg_ctrls(
struct stream_config *config,
int key,
783 const struct arg *arg) {
786 config->film_grain_filename = arg->val;
793 j = config->arg_ctrl_cnt;
794 assert(j < (
int)ARG_CTRL_CNT_MAX);
795 config->arg_ctrls[j][0] = key;
796 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
797 ++config->arg_ctrl_cnt;
804 for (j = 0; j < config->arg_ctrl_cnt; j++)
805 if (config->arg_ctrls[j][0] == key)
break;
808 assert(j < (
int)ARG_CTRL_CNT_MAX);
809 config->arg_ctrls[j][0] = key;
810 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
813 warn(
"auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
814 config->arg_ctrls[j][1] = 1;
816 if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
819 static int parse_stream_params(
struct AvxEncoderConfig *global,
820 struct stream_state *stream,
char **argv) {
823 static const arg_def_t **ctrl_args = no_args;
824 static const int *ctrl_args_map = NULL;
825 struct stream_config *config = &stream->config;
826 int eos_mark_found = 0;
831 #if CONFIG_AV1_ENCODER
832 }
else if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
835 ctrl_args = av1_args;
836 ctrl_args_map = av1_arg_ctrl_map;
840 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
846 if (eos_mark_found) {
849 }
else if (!strcmp(*argj,
"--")) {
854 if (arg_match(&arg, &g_av1_codec_arg_defs.outputfile, argi)) {
855 config->out_fn = arg.val;
857 const size_t out_fn_len = strlen(config->out_fn);
858 if (out_fn_len >= 4 &&
859 !strcmp(config->out_fn + out_fn_len - 4,
".ivf")) {
860 config->write_webm = 0;
861 config->write_ivf = 1;
862 }
else if (out_fn_len >= 4 &&
863 !strcmp(config->out_fn + out_fn_len - 4,
".obu")) {
864 config->write_webm = 0;
865 config->write_ivf = 0;
868 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fpf_name, argi)) {
869 config->stats_fn = arg.val;
870 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_webm, argi)) {
872 config->write_webm = 1;
875 die(
"Error: --webm specified but webm is disabled.");
877 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_ivf, argi)) {
878 config->write_webm = 0;
879 config->write_ivf = 1;
880 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_obu, argi)) {
881 config->write_webm = 0;
882 config->write_ivf = 0;
883 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.threads, argi)) {
884 config->cfg.g_threads = arg_parse_uint(&arg);
885 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.profile, argi)) {
886 config->cfg.g_profile = arg_parse_uint(&arg);
887 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.width, argi)) {
888 config->cfg.g_w = arg_parse_uint(&arg);
889 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.height, argi)) {
890 config->cfg.g_h = arg_parse_uint(&arg);
891 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_width,
893 config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
894 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_height,
896 config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
897 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bitdeptharg, argi)) {
898 config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
899 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.inbitdeptharg, argi)) {
900 config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
901 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_x,
903 stream->chroma_subsampling_x = arg_parse_uint(&arg);
904 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_y,
906 stream->chroma_subsampling_y = arg_parse_uint(&arg);
908 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.stereo_mode, argi)) {
909 config->stereo_fmt = arg_parse_enum_or_int(&arg);
911 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.timebase, argi)) {
912 config->cfg.g_timebase = arg_parse_rational(&arg);
913 validate_positive_rational(arg.name, &config->cfg.g_timebase);
914 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.global_error_resilient,
916 config->cfg.g_error_resilient = arg_parse_uint(&arg);
917 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.lag_in_frames, argi)) {
918 config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
919 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.large_scale_tile, argi)) {
920 config->cfg.large_scale_tile = arg_parse_uint(&arg);
921 if (config->cfg.large_scale_tile) {
922 global->codec = get_aom_encoder_by_short_name(
"av1");
924 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.monochrome, argi)) {
925 config->cfg.monochrome = 1;
926 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.full_still_picture_hdr,
928 config->cfg.full_still_picture_hdr = 1;
929 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_16bit_internal,
931 config->use_16bit_internal = CONFIG_AV1_HIGHBITDEPTH;
932 if (!config->use_16bit_internal) {
933 warn(
"%s option ignored with CONFIG_AV1_HIGHBITDEPTH=0.\n", arg.name);
935 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.dropframe_thresh, argi)) {
936 config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
937 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_mode, argi)) {
938 config->cfg.rc_resize_mode = arg_parse_uint(&arg);
939 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_denominator,
941 config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
942 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_kf_denominator,
944 config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
945 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_mode, argi)) {
946 config->cfg.rc_superres_mode = arg_parse_uint(&arg);
947 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_denominator,
949 config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
950 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_denominator,
952 config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
953 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_qthresh, argi)) {
954 config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
955 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_qthresh,
957 config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
958 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.end_usage, argi)) {
959 config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
960 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.target_bitrate, argi)) {
961 config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
962 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.min_quantizer, argi)) {
963 config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
964 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.max_quantizer, argi)) {
965 config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
966 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.undershoot_pct, argi)) {
967 config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
968 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.overshoot_pct, argi)) {
969 config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
970 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_sz, argi)) {
971 config->cfg.rc_buf_sz = arg_parse_uint(&arg);
972 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_initial_sz, argi)) {
973 config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
974 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_optimal_sz, argi)) {
975 config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
976 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bias_pct, argi)) {
977 config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
978 if (global->passes < 2)
979 warn(
"option %s ignored in one-pass mode.\n", arg.name);
980 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.minsection_pct, argi)) {
981 config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
983 if (global->passes < 2)
984 warn(
"option %s ignored in one-pass mode.\n", arg.name);
985 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.maxsection_pct, argi)) {
986 config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
988 if (global->passes < 2)
989 warn(
"option %s ignored in one-pass mode.\n", arg.name);
990 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fwd_kf_enabled, argi)) {
991 config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
992 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_min_dist, argi)) {
993 config->cfg.kf_min_dist = arg_parse_uint(&arg);
994 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_max_dist, argi)) {
995 config->cfg.kf_max_dist = arg_parse_uint(&arg);
996 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_disabled, argi)) {
998 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_dist, argi)) {
999 config->cfg.sframe_dist = arg_parse_uint(&arg);
1000 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_mode, argi)) {
1001 config->cfg.sframe_mode = arg_parse_uint(&arg);
1002 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.save_as_annexb, argi)) {
1003 config->cfg.save_as_annexb = arg_parse_uint(&arg);
1004 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_width, argi)) {
1005 config->cfg.tile_width_count =
1007 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_height, argi)) {
1008 config->cfg.tile_height_count =
1010 #if CONFIG_TUNE_VMAF
1011 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argi)) {
1012 config->vmaf_model_path = arg.val;
1014 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_fixed_qp_offsets,
1016 config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg);
1017 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fixed_qp_offsets, argi)) {
1018 const int fixed_qp_offset_count = arg_parse_list(
1021 die(
"Option --fixed_qp_offsets requires %d comma-separated values, but "
1022 "only %d values were provided.\n",
1025 config->cfg.use_fixed_qp_offsets = 1;
1027 arg_match(&arg, &g_av1_codec_arg_defs.enable_restoration,
1029 if (arg_parse_uint(&arg) == 1) {
1030 warn(
"non-zero %s option ignored in realtime mode.\n", arg.name);
1034 for (i = 0; ctrl_args[i]; i++) {
1035 if (arg_match(&arg, ctrl_args[i], argi)) {
1037 if (ctrl_args_map) {
1038 set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1046 config->use_16bit_internal |= config->cfg.g_bit_depth >
AOM_BITS_8;
1049 warn(
"non-zero lag-in-frames option ignored in realtime mode.\n");
1050 config->cfg.g_lag_in_frames = 0;
1052 return eos_mark_found;
1055 #define FOREACH_STREAM(iterator, list) \
1056 for (struct stream_state *iterator = list; iterator; \
1057 iterator = iterator->next)
1059 static void validate_stream_config(
const struct stream_state *stream,
1060 const struct AvxEncoderConfig *global) {
1061 const struct stream_state *streami;
1064 if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1066 "Stream %d: Specify stream dimensions with --width (-w) "
1067 " and --height (-h)",
1073 assert(stream->config.cfg.g_input_bit_depth <=
1074 (
unsigned int)stream->config.cfg.g_bit_depth);
1076 for (streami = stream; streami; streami = streami->next) {
1078 if (!streami->config.out_fn)
1079 fatal(
"Stream %d: Output file is required (specify with -o)",
1083 if (streami != stream) {
1084 const char *a = stream->config.out_fn;
1085 const char *b = streami->config.out_fn;
1086 if (!strcmp(a, b) && strcmp(a,
"/dev/null") && strcmp(a,
":nul"))
1087 fatal(
"Stream %d: duplicate output file (from stream %d)",
1088 streami->index, stream->index);
1092 if (streami != stream) {
1093 const char *a = stream->config.stats_fn;
1094 const char *b = streami->config.stats_fn;
1095 if (a && b && !strcmp(a, b))
1096 fatal(
"Stream %d: duplicate stats file (from stream %d)",
1097 streami->index, stream->index);
1102 static void set_stream_dimensions(
struct stream_state *stream,
unsigned int w,
1104 if (!stream->config.cfg.g_w) {
1105 if (!stream->config.cfg.g_h)
1106 stream->config.cfg.g_w = w;
1108 stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1110 if (!stream->config.cfg.g_h) {
1111 stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1115 static const char *file_type_to_string(
enum VideoFileType t) {
1117 case FILE_TYPE_RAW:
return "RAW";
1118 case FILE_TYPE_Y4M:
return "Y4M";
1119 default:
return "Other";
1123 static const char *image_format_to_string(
aom_img_fmt_t f) {
1133 default:
return "Other";
1137 static void show_stream_config(
struct stream_state *stream,
1138 struct AvxEncoderConfig *global,
1139 struct AvxInputContext *input) {
1140 #define SHOW(field) \
1141 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1143 if (stream->index == 0) {
1145 fprintf(stderr,
"Source file: %s File Type: %s Format: %s\n",
1146 input->filename, file_type_to_string(input->file_type),
1147 image_format_to_string(input->fmt));
1149 if (stream->next || stream->index)
1150 fprintf(stderr,
"\nStream Index: %d\n", stream->index);
1151 fprintf(stderr,
"Destination file: %s\n", stream->config.out_fn);
1152 fprintf(stderr,
"Coding path: %s\n",
1153 stream->config.use_16bit_internal ?
"HBD" :
"LBD");
1154 fprintf(stderr,
"Encoder parameters:\n");
1162 SHOW(g_input_bit_depth);
1163 SHOW(g_timebase.num);
1164 SHOW(g_timebase.den);
1165 SHOW(g_error_resilient);
1167 SHOW(g_lag_in_frames);
1168 SHOW(large_scale_tile);
1169 SHOW(rc_dropframe_thresh);
1170 SHOW(rc_resize_mode);
1171 SHOW(rc_resize_denominator);
1172 SHOW(rc_resize_kf_denominator);
1173 SHOW(rc_superres_mode);
1174 SHOW(rc_superres_denominator);
1175 SHOW(rc_superres_kf_denominator);
1176 SHOW(rc_superres_qthresh);
1177 SHOW(rc_superres_kf_qthresh);
1179 SHOW(rc_target_bitrate);
1180 SHOW(rc_min_quantizer);
1181 SHOW(rc_max_quantizer);
1182 SHOW(rc_undershoot_pct);
1183 SHOW(rc_overshoot_pct);
1185 SHOW(rc_buf_initial_sz);
1186 SHOW(rc_buf_optimal_sz);
1187 SHOW(rc_2pass_vbr_bias_pct);
1188 SHOW(rc_2pass_vbr_minsection_pct);
1189 SHOW(rc_2pass_vbr_maxsection_pct);
1190 SHOW(fwd_kf_enabled);
1195 #define SHOW_PARAMS(field) \
1196 fprintf(stderr, " %-28s = %d\n", #field, \
1197 stream->config.cfg.encoder_cfg.field)
1198 if (global->encoder_config.init_by_cfg_file) {
1199 SHOW_PARAMS(super_block_size);
1200 SHOW_PARAMS(max_partition_size);
1201 SHOW_PARAMS(min_partition_size);
1202 SHOW_PARAMS(disable_ab_partition_type);
1203 SHOW_PARAMS(disable_rect_partition_type);
1204 SHOW_PARAMS(disable_1to4_partition_type);
1205 SHOW_PARAMS(disable_flip_idtx);
1206 SHOW_PARAMS(disable_cdef);
1207 SHOW_PARAMS(disable_lr);
1208 SHOW_PARAMS(disable_obmc);
1209 SHOW_PARAMS(disable_warp_motion);
1210 SHOW_PARAMS(disable_global_motion);
1211 SHOW_PARAMS(disable_dist_wtd_comp);
1212 SHOW_PARAMS(disable_diff_wtd_comp);
1213 SHOW_PARAMS(disable_inter_intra_comp);
1214 SHOW_PARAMS(disable_masked_comp);
1215 SHOW_PARAMS(disable_one_sided_comp);
1216 SHOW_PARAMS(disable_palette);
1217 SHOW_PARAMS(disable_intrabc);
1218 SHOW_PARAMS(disable_cfl);
1219 SHOW_PARAMS(disable_smooth_intra);
1220 SHOW_PARAMS(disable_filter_intra);
1221 SHOW_PARAMS(disable_dual_filter);
1222 SHOW_PARAMS(disable_intra_angle_delta);
1223 SHOW_PARAMS(disable_intra_edge_filter);
1224 SHOW_PARAMS(disable_tx_64x64);
1225 SHOW_PARAMS(disable_smooth_inter_intra);
1226 SHOW_PARAMS(disable_inter_inter_wedge);
1227 SHOW_PARAMS(disable_inter_intra_wedge);
1228 SHOW_PARAMS(disable_paeth_intra);
1229 SHOW_PARAMS(disable_trellis_quant);
1230 SHOW_PARAMS(disable_ref_frame_mv);
1231 SHOW_PARAMS(reduced_reference_set);
1232 SHOW_PARAMS(reduced_tx_type_set);
1236 static void open_output_file(
struct stream_state *stream,
1237 struct AvxEncoderConfig *global,
1238 const struct AvxRational *pixel_aspect_ratio,
1239 const char *encoder_settings) {
1240 const char *fn = stream->config.out_fn;
1245 stream->file = strcmp(fn,
"-") ? fopen(fn,
"wb") : set_binary_mode(stdout);
1247 if (!stream->file) fatal(
"Failed to open output file");
1249 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1250 fatal(
"WebM output to pipes not supported.");
1253 if (stream->config.write_webm) {
1254 stream->webm_ctx.stream = stream->file;
1255 if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1256 stream->config.stereo_fmt,
1257 get_fourcc_by_aom_encoder(global->codec),
1258 pixel_aspect_ratio, encoder_settings) != 0) {
1259 fatal(
"WebM writer initialization failed.");
1263 (void)pixel_aspect_ratio;
1264 (void)encoder_settings;
1267 if (!stream->config.write_webm && stream->config.write_ivf) {
1268 ivf_write_file_header(stream->file, cfg,
1269 get_fourcc_by_aom_encoder(global->codec), 0);
1273 static void close_output_file(
struct stream_state *stream,
1274 unsigned int fourcc) {
1280 if (stream->config.write_webm) {
1281 if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1282 fatal(
"WebM writer finalization failed.");
1287 if (!stream->config.write_webm && stream->config.write_ivf) {
1288 if (!fseek(stream->file, 0, SEEK_SET))
1289 ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1290 stream->frames_out);
1293 fclose(stream->file);
1296 static void setup_pass(
struct stream_state *stream,
1297 struct AvxEncoderConfig *global,
int pass) {
1298 if (stream->config.stats_fn) {
1299 if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1300 fatal(
"Failed to open statistics store");
1302 if (!stats_open_mem(&stream->stats, pass))
1303 fatal(
"Failed to open statistics store");
1306 stream->config.cfg.g_pass = global->passes == 2
1310 stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1313 stream->cx_time = 0;
1315 stream->frames_out = 0;
1318 static void initialize_encoder(
struct stream_state *stream,
1319 struct AvxEncoderConfig *global) {
1329 ctx_exit_on_error(&stream->encoder,
"Failed to initialize encoder");
1331 for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1332 int ctrl = stream->config.arg_ctrls[i][0];
1333 int value = stream->config.arg_ctrls[i][1];
1335 fprintf(stderr,
"Error: Tried to set control %d = %d\n", ctrl, value);
1337 ctx_exit_on_error(&stream->encoder,
"Failed to control codec");
1340 #if CONFIG_TUNE_VMAF
1341 if (stream->config.vmaf_model_path) {
1343 stream->config.vmaf_model_path);
1347 if (stream->config.film_grain_filename) {
1349 stream->config.film_grain_filename);
1352 stream->config.color_range);
1354 #if CONFIG_AV1_DECODER
1355 if (global->test_decode != TEST_DECODE_OFF) {
1357 get_short_name_by_aom_encoder(global->codec));
1361 if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
1363 stream->config.cfg.large_scale_tile);
1364 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_mode");
1367 stream->config.cfg.save_as_annexb);
1368 ctx_exit_on_error(&stream->decoder,
"Failed to set is_annexb");
1372 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_row");
1376 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_col");
1382 static void encode_frame(
struct stream_state *stream,
1383 struct AvxEncoderConfig *global,
struct aom_image *img,
1384 unsigned int frames_in) {
1387 struct aom_usec_timer timer;
1390 (cfg->
g_timebase.
den * (int64_t)(frames_in - 1) * global->framerate.den) /
1393 (cfg->
g_timebase.
den * (int64_t)(frames_in)*global->framerate.den) /
1401 fprintf(stderr,
"%s can only scale 4:2:0 inputs\n", exec_name);
1418 stream->img->stride[
AOM_PLANE_V] / 2, stream->img->d_w,
1419 stream->img->d_h, kFilterBox);
1422 stream->encoder.err = 1;
1423 ctx_exit_on_error(&stream->encoder,
1424 "Stream %d: Failed to encode frame.\n"
1425 "libyuv is required for scaling but is currently "
1427 "Be sure to specify -DCONFIG_LIBYUV=1 when running "
1433 if (img && (img->
d_w != cfg->
g_w || img->
d_h != cfg->
g_h)) {
1435 fprintf(stderr,
"%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1449 stream->img->d_w, stream->img->d_h, kFilterBox);
1452 stream->encoder.err = 1;
1453 ctx_exit_on_error(&stream->encoder,
1454 "Stream %d: Failed to encode frame.\n"
1455 "Scaling disabled in this configuration. \n"
1456 "To enable, configure with --enable-libyuv\n",
1461 aom_usec_timer_start(&timer);
1463 (uint32_t)(next_frame_start - frame_start), 0);
1464 aom_usec_timer_mark(&timer);
1465 stream->cx_time += aom_usec_timer_elapsed(&timer);
1466 ctx_exit_on_error(&stream->encoder,
"Stream %d: Failed to encode frame",
1470 static void update_quantizer_histogram(
struct stream_state *stream) {
1476 ctx_exit_on_error(&stream->encoder,
"Failed to read quantizer");
1477 stream->counts[q]++;
1481 static void get_cx_data(
struct stream_state *stream,
1482 struct AvxEncoderConfig *global,
int *got_data) {
1489 static size_t fsize = 0;
1490 static FileOffset ivf_header_pos = 0;
1492 switch (pkt->
kind) {
1494 ++stream->frames_out;
1496 fprintf(stderr,
" %6luF", (
unsigned long)pkt->
data.
frame.sz);
1498 update_rate_histogram(stream->rate_hist, cfg, pkt);
1500 if (stream->config.write_webm) {
1501 if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
1502 fatal(
"WebM writer failed.");
1506 if (!stream->config.write_webm) {
1507 if (stream->config.write_ivf) {
1508 if (pkt->
data.
frame.partition_id <= 0) {
1509 ivf_header_pos = ftello(stream->file);
1512 ivf_write_frame_header(stream->file, pkt->
data.
frame.pts, fsize);
1516 const FileOffset currpos = ftello(stream->file);
1517 fseeko(stream->file, ivf_header_pos, SEEK_SET);
1518 ivf_write_frame_size(stream->file, fsize);
1519 fseeko(stream->file, currpos, SEEK_SET);
1529 #if CONFIG_AV1_DECODER
1530 if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
1533 if (stream->decoder.err) {
1534 warn_or_exit_on_error(&stream->decoder,
1535 global->test_decode == TEST_DECODE_FATAL,
1536 "Failed to decode frame %d in stream %d",
1537 stream->frames_out + 1, stream->index);
1538 stream->mismatch_seen = stream->frames_out + 1;
1544 stream->frames_out++;
1551 if (global->show_psnr >= 1) {
1554 stream->psnr_sse_total[0] += pkt->
data.
psnr.sse[0];
1555 stream->psnr_samples_total[0] += pkt->
data.
psnr.samples[0];
1556 for (i = 0; i < 4; i++) {
1558 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr[i]);
1559 stream->psnr_totals[0][i] += pkt->
data.
psnr.psnr[i];
1561 stream->psnr_count[0]++;
1563 #if CONFIG_AV1_HIGHBITDEPTH
1564 if (stream->config.cfg.g_input_bit_depth <
1565 (
unsigned int)stream->config.cfg.g_bit_depth) {
1566 stream->psnr_sse_total[1] += pkt->
data.
psnr.sse_hbd[0];
1567 stream->psnr_samples_total[1] += pkt->
data.
psnr.samples_hbd[0];
1568 for (i = 0; i < 4; i++) {
1570 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr_hbd[i]);
1571 stream->psnr_totals[1][i] += pkt->
data.
psnr.psnr_hbd[i];
1573 stream->psnr_count[1]++;
1584 static void show_psnr(
struct stream_state *stream,
double peak, int64_t bps) {
1588 if (!stream->psnr_count[0])
return;
1590 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1591 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[0], peak,
1592 (
double)stream->psnr_sse_total[0]);
1593 fprintf(stderr,
" %.3f", ovpsnr);
1595 for (i = 0; i < 4; i++) {
1596 fprintf(stderr,
" %.3f", stream->psnr_totals[0][i] / stream->psnr_count[0]);
1599 fprintf(stderr,
" %7" PRId64
" bps", bps);
1601 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1602 fprintf(stderr,
"\n");
1605 #if CONFIG_AV1_HIGHBITDEPTH
1606 static void show_psnr_hbd(
struct stream_state *stream,
double peak,
1611 if (!stream->psnr_count[1])
return;
1613 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1614 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[1], peak,
1615 (
double)stream->psnr_sse_total[1]);
1616 fprintf(stderr,
" %.3f", ovpsnr);
1618 for (i = 0; i < 4; i++) {
1619 fprintf(stderr,
" %.3f", stream->psnr_totals[1][i] / stream->psnr_count[1]);
1622 fprintf(stderr,
" %7" PRId64
" bps", bps);
1624 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1625 fprintf(stderr,
"\n");
1629 static float usec_to_fps(uint64_t usec,
unsigned int frames) {
1630 return (
float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
1633 static void test_decode(
struct stream_state *stream,
1634 enum TestDecodeFatality fatal) {
1637 if (stream->mismatch_seen)
return;
1650 enc_img.
d_w, enc_img.
d_h, 16);
1651 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1652 enc_img = enc_hbd_img;
1657 dec_img.
d_w, dec_img.
d_h, 16);
1658 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1659 dec_img = dec_hbd_img;
1663 ctx_exit_on_error(&stream->encoder,
"Failed to get encoder reference frame");
1664 ctx_exit_on_error(&stream->decoder,
"Failed to get decoder reference frame");
1666 if (!aom_compare_img(&enc_img, &dec_img)) {
1667 int y[4], u[4], v[4];
1669 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1671 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1673 stream->decoder.err = 1;
1674 warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
1675 "Stream %d: Encode/decode mismatch on frame %d at"
1676 " Y[%d, %d] {%d/%d},"
1677 " U[%d, %d] {%d/%d},"
1678 " V[%d, %d] {%d/%d}",
1679 stream->index, stream->frames_out, y[0], y[1], y[2],
1680 y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
1681 stream->mismatch_seen = stream->frames_out;
1688 static void print_time(
const char *label, int64_t etl) {
1695 etl -= hours * 3600;
1700 fprintf(stderr,
"[%3s %2" PRId64
":%02" PRId64
":%02" PRId64
"] ", label,
1703 fprintf(stderr,
"[%3s unknown] ", label);
1707 int main(
int argc,
const char **argv_) {
1711 int allocated_raw_shift = 0;
1712 int do_16bit_internal = 0;
1713 int input_shift = 0;
1714 int frame_avail, got_data;
1716 struct AvxInputContext input;
1717 struct AvxEncoderConfig global;
1718 struct stream_state *streams = NULL;
1719 char **argv, **argi;
1720 uint64_t cx_time = 0;
1723 int profile_updated = 0;
1725 memset(&input, 0,
sizeof(input));
1726 memset(&raw, 0,
sizeof(raw));
1727 exec_name = argv_[0];
1730 input.framerate.numerator = 30;
1731 input.framerate.denominator = 1;
1732 input.only_i420 = 1;
1733 input.bit_depth = 0;
1739 argv = argv_dup(argc - 1, argv_ + 1);
1740 parse_global_config(&global, &argv);
1742 if (argc < 2) usage_exit();
1744 switch (global.color_type) {
1756 struct stream_state *stream = NULL;
1759 stream = new_stream(&global, stream);
1761 if (!streams) streams = stream;
1762 }
while (parse_stream_params(&global, stream, argv));
1766 for (argi = argv; *argi; argi++)
1767 if (argi[0][0] ==
'-' && argi[0][1])
1768 die(
"Error: Unrecognized option %s\n", *argi);
1770 FOREACH_STREAM(stream, streams) {
1771 check_encoder_config(global.disable_warning_prompt, &global,
1772 &stream->config.cfg);
1775 if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
1776 die(
"only support ivf output format while large-scale-tile=1\n");
1780 input.filename = argv[0];
1782 if (!input.filename) {
1783 fprintf(stderr,
"No input file specified!\n");
1788 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC)
1789 input.only_i420 = 0;
1791 for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
1792 int frames_in = 0, seen_frames = 0;
1793 int64_t estimated_time_left = -1;
1794 int64_t average_rate = -1;
1795 int64_t lagged_count = 0;
1797 open_input_file(&input, global.csp);
1802 if (!input.width || !input.height) {
1803 FOREACH_STREAM(stream, streams) {
1804 if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
1805 input.width = stream->config.cfg.g_w;
1806 input.height = stream->config.cfg.g_h;
1813 if (!input.width || !input.height)
1815 "Specify stream dimensions with --width (-w) "
1816 " and --height (-h)");
1823 if (!input.bit_depth) {
1824 FOREACH_STREAM(stream, streams) {
1825 if (stream->config.cfg.g_input_bit_depth)
1826 input.bit_depth = stream->config.cfg.g_input_bit_depth;
1828 input.bit_depth = stream->config.cfg.g_input_bit_depth =
1829 (int)stream->config.cfg.g_bit_depth;
1833 FOREACH_STREAM(stream, streams) {
1834 stream->config.cfg.g_input_bit_depth = input.bit_depth;
1838 FOREACH_STREAM(stream, streams) {
1842 switch (stream->config.cfg.g_profile) {
1846 if (!stream->config.cfg.monochrome) {
1847 stream->config.cfg.g_profile = 1;
1848 profile_updated = 1;
1852 stream->config.cfg.g_profile = 2;
1853 profile_updated = 1;
1859 stream->config.cfg.g_profile = 2;
1860 profile_updated = 1;
1861 }
else if (input.bit_depth < 12 &&
1864 stream->config.cfg.g_profile = 0;
1865 profile_updated = 1;
1871 stream->config.cfg.g_profile = 1;
1872 profile_updated = 1;
1873 }
else if (input.bit_depth < 12 &&
1876 stream->config.cfg.g_profile = 0;
1877 profile_updated = 1;
1878 }
else if (input.bit_depth == 12 &&
1879 input.file_type == FILE_TYPE_Y4M) {
1884 input.y4m.dst_c_dec_h >> 1);
1887 input.y4m.dst_c_dec_v >> 1);
1888 }
else if (input.bit_depth == 12 &&
1889 input.file_type == FILE_TYPE_RAW) {
1892 stream->chroma_subsampling_x);
1895 stream->chroma_subsampling_y);
1903 if (stream->config.cfg.g_input_bit_depth >
1904 (
unsigned int)stream->config.cfg.g_bit_depth) {
1905 stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
1906 if (!global.quiet) {
1908 "Warning: automatically updating bit depth to %d to "
1909 "match input format.\n",
1910 stream->config.cfg.g_input_bit_depth);
1913 #if !CONFIG_AV1_HIGHBITDEPTH
1914 if (stream->config.cfg.g_bit_depth > 8) {
1915 fatal(
"Unsupported bit-depth with CONFIG_AV1_HIGHBITDEPTH=0\n");
1918 if (stream->config.cfg.g_bit_depth > 10) {
1919 switch (stream->config.cfg.g_profile) {
1922 stream->config.cfg.g_profile = 2;
1923 profile_updated = 1;
1928 if (stream->config.cfg.g_bit_depth > 8) {
1929 stream->config.use_16bit_internal = 1;
1931 if (profile_updated && !global.quiet) {
1933 "Warning: automatically updating to profile %d to "
1934 "match input format.\n",
1935 stream->config.cfg.g_profile);
1937 if ((global.show_psnr == 2) && (stream->config.cfg.g_input_bit_depth ==
1938 stream->config.cfg.g_bit_depth)) {
1940 "Warning: --psnr==2 and --psnr==1 will provide same "
1941 "results when input bit-depth == stream bit-depth, "
1942 "falling back to default psnr value\n");
1943 global.show_psnr = 1;
1945 if (global.show_psnr < 0 || global.show_psnr > 2) {
1947 "Warning: --psnr can take only 0,1,2 as values,"
1948 "falling back to default psnr value\n");
1949 global.show_psnr = 1;
1952 stream->config.cfg.g_limit = global.limit;
1955 FOREACH_STREAM(stream, streams) {
1956 set_stream_dimensions(stream, input.width, input.height);
1957 stream->config.color_range = input.color_range;
1959 FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
1964 if (global.pass && global.passes == 2) {
1965 FOREACH_STREAM(stream, streams) {
1966 if (!stream->config.stats_fn)
1967 die(
"Stream %d: Must specify --fpf when --pass=%d"
1968 " and --passes=2\n",
1969 stream->index, global.pass);
1974 FOREACH_STREAM(stream, streams) {
1975 if (stream->config.write_webm) {
1976 stream->config.write_webm = 0;
1977 stream->config.write_ivf = 0;
1978 warn(
"aomenc compiled w/o WebM support. Writing OBU stream.");
1986 if (!global.have_framerate) {
1987 global.framerate.num = input.framerate.numerator;
1988 global.framerate.den = input.framerate.denominator;
1990 FOREACH_STREAM(stream, streams) {
1991 stream->config.cfg.g_timebase.den = global.framerate.num;
1992 stream->config.cfg.g_timebase.num = global.framerate.den;
1995 if (global.verbose && pass == 0) {
1996 FOREACH_STREAM(stream, streams) {
1997 show_stream_config(stream, &global, &input);
2001 if (pass == (global.pass ? global.pass - 1 : 0)) {
2003 if (input.file_type != FILE_TYPE_Y4M) {
2004 aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2006 FOREACH_STREAM(stream, streams) {
2008 init_rate_histogram(&stream->config.cfg, &global.framerate);
2012 FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2013 FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2014 FOREACH_STREAM(stream, streams) {
2015 char *encoder_settings = NULL;
2024 if (stream->config.write_webm && !stream->webm_ctx.debug) {
2025 encoder_settings = extract_encoder_settings(
2027 if (encoder_settings == NULL) {
2030 "Warning: unable to extract encoder settings. Continuing...\n");
2034 open_output_file(stream, &global, &input.pixel_aspect_ratio,
2036 free(encoder_settings);
2039 if (strcmp(get_short_name_by_aom_encoder(global.codec),
"av1") == 0) {
2043 FOREACH_STREAM(stream, streams) {
2044 if (stream->config.use_16bit_internal) {
2045 do_16bit_internal = 1;
2047 input_shift = (int)stream->config.cfg.g_bit_depth -
2048 stream->config.cfg.g_input_bit_depth;
2055 while (frame_avail || got_data) {
2056 struct aom_usec_timer timer;
2058 if (!global.limit || frames_in < global.limit) {
2059 frame_avail = read_frame(&input, &raw);
2061 if (frame_avail) frames_in++;
2063 frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2065 if (!global.quiet) {
2066 float fps = usec_to_fps(cx_time, seen_frames);
2067 fprintf(stderr,
"\rPass %d/%d ", pass + 1, global.passes);
2069 if (stream_cnt == 1)
2070 fprintf(stderr,
"frame %4d/%-4d %7" PRId64
"B ", frames_in,
2071 streams->frames_out, (int64_t)streams->nbytes);
2073 fprintf(stderr,
"frame %4d ", frames_in);
2075 fprintf(stderr,
"%7" PRId64
" %s %.2f %s ",
2076 cx_time > 9999999 ? cx_time / 1000 : cx_time,
2077 cx_time > 9999999 ?
"ms" :
"us", fps >= 1.0 ? fps : fps * 60,
2078 fps >= 1.0 ?
"fps" :
"fpm");
2079 print_time(
"ETA", estimated_time_left);
2086 if (frames_in > global.skip_frames) {
2088 if (input_shift || (do_16bit_internal && input.bit_depth == 8)) {
2089 assert(do_16bit_internal);
2092 if (!allocated_raw_shift) {
2094 input.width, input.height, 32);
2095 allocated_raw_shift = 1;
2097 aom_img_upshift(&raw_shift, &raw, input_shift);
2098 frame_to_encode = &raw_shift;
2100 frame_to_encode = &raw;
2102 aom_usec_timer_start(&timer);
2103 if (do_16bit_internal) {
2105 FOREACH_STREAM(stream, streams) {
2106 if (stream->config.use_16bit_internal)
2107 encode_frame(stream, &global,
2108 frame_avail ? frame_to_encode : NULL, frames_in);
2114 FOREACH_STREAM(stream, streams) {
2115 encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2119 aom_usec_timer_mark(&timer);
2120 cx_time += aom_usec_timer_elapsed(&timer);
2122 FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2125 FOREACH_STREAM(stream, streams) {
2126 get_cx_data(stream, &global, &got_data);
2129 if (!got_data && input.length && streams != NULL &&
2130 !streams->frames_out) {
2131 lagged_count = global.limit ? seen_frames : ftello(input.file);
2132 }
else if (input.length) {
2137 const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2139 rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2140 remaining = 1000 * (global.limit - global.skip_frames -
2141 seen_frames + lagged_count);
2143 const int64_t input_pos = ftello(input.file);
2144 const int64_t input_pos_lagged = input_pos - lagged_count;
2145 const int64_t input_limit = input.length;
2147 rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2148 remaining = input_limit - input_pos + lagged_count;
2152 (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2153 estimated_time_left = average_rate ? remaining / average_rate : -1;
2156 if (got_data && global.test_decode != TEST_DECODE_OFF) {
2157 FOREACH_STREAM(stream, streams) {
2158 test_decode(stream, global.test_decode);
2164 if (!global.quiet) fprintf(stderr,
"\033[K");
2167 if (stream_cnt > 1) fprintf(stderr,
"\n");
2169 if (!global.quiet) {
2170 FOREACH_STREAM(stream, streams) {
2172 seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2173 const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2175 "\rPass %d/%d frame %4d/%-4d %7" PRId64
"B %7" PRId64
2178 " %7" PRId64
" %s (%.2f fps)\033[K\n",
2179 pass + 1, global.passes, frames_in, stream->frames_out,
2180 (int64_t)stream->nbytes, bpf, bps,
2181 stream->cx_time > 9999999 ? stream->cx_time / 1000
2183 stream->cx_time > 9999999 ?
"ms" :
"us",
2184 usec_to_fps(stream->cx_time, seen_frames));
2188 if (global.show_psnr >= 1) {
2189 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) {
2190 FOREACH_STREAM(stream, streams) {
2192 if (global.show_psnr == 1) {
2193 if (stream->psnr_count[0] && seen_frames && global.framerate.den) {
2194 bps = (int64_t)stream->nbytes * 8 *
2195 (int64_t)global.framerate.num / global.framerate.den /
2198 show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2201 if (global.show_psnr == 2) {
2202 #if CONFIG_AV1_HIGHBITDEPTH
2203 if (stream->config.cfg.g_input_bit_depth <
2204 (
unsigned int)stream->config.cfg.g_bit_depth)
2205 show_psnr_hbd(stream, (1 << stream->config.cfg.g_bit_depth) - 1,
2211 FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2217 if (global.test_decode != TEST_DECODE_OFF) {
2221 close_input_file(&input);
2223 if (global.test_decode == TEST_DECODE_FATAL) {
2224 FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2226 FOREACH_STREAM(stream, streams) {
2227 close_output_file(stream, get_fourcc_by_aom_encoder(global.codec));
2230 FOREACH_STREAM(stream, streams) {
2231 stats_close(&stream->stats, global.passes - 1);
2234 if (global.pass)
break;
2237 if (global.show_q_hist_buckets) {
2238 FOREACH_STREAM(stream, streams) {
2239 show_q_histogram(stream->counts, global.show_q_hist_buckets);
2243 if (global.show_rate_hist_buckets) {
2244 FOREACH_STREAM(stream, streams) {
2245 show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2246 global.show_rate_hist_buckets);
2249 FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2251 #if CONFIG_INTERNAL_STATS
2255 if (!(global.pass == 1 && global.passes == 2)) {
2256 FOREACH_STREAM(stream, streams) {
2257 FILE *f = fopen(
"opsnr.stt",
"a");
2258 if (stream->mismatch_seen) {
2259 fprintf(f,
"First mismatch occurred in frame %d\n",
2260 stream->mismatch_seen);
2262 fprintf(f,
"No mismatch detected in recon buffers\n");
2273 return res ? EXIT_FAILURE : EXIT_SUCCESS;
Describes the decoder algorithm interface to applications.
Describes the encoder algorithm interface to applications.
#define MAX_TILE_WIDTHS
Maximum number of tile widths in tile widths array.
Definition: aom_encoder.h:836
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition: aom_encoder.h:849
#define FIXED_QP_OFFSET_COUNT
Number of fixed QP offsets.
Definition: aom_encoder.h:876
#define AOM_PLANE_U
Definition: aom_image.h:200
@ AOM_CSP_UNKNOWN
Definition: aom_image.h:133
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_PLANE_Y
Definition: aom_image.h:199
#define AOM_PLANE_V
Definition: aom_image.h:201
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.
enum aom_color_range aom_color_range_t
List of supported color range.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
@ AOM_IMG_FMT_I42216
Definition: aom_image.h:53
@ AOM_IMG_FMT_I42016
Definition: aom_image.h:51
@ AOM_IMG_FMT_YV1216
Definition: aom_image.h:52
@ AOM_IMG_FMT_I444
Definition: aom_image.h:50
@ AOM_IMG_FMT_I422
Definition: aom_image.h:49
@ AOM_IMG_FMT_I44416
Definition: aom_image.h:54
@ AOM_IMG_FMT_I420
Definition: aom_image.h:45
@ AOM_IMG_FMT_YV12
Definition: aom_image.h:43
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
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.
Provides definitions for using AOM or AV1 within the aom Decoder interface.
@ AV1_SET_TILE_MODE
Codec control function to set the tile coding mode, int parameter.
Definition: aomdx.h:309
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition: aomdx.h:345
@ AV1_SET_DECODE_TILE_ROW
Codec control function to set the range of tile decoding, int parameter.
Definition: aomdx.h:301
@ AV1E_SET_MATRIX_COEFFICIENTS
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:560
@ AV1E_SET_ENABLE_INTERINTER_WEDGE
Codec control function to turn on / off interinter wedge compound, int parameter.
Definition: aomcx.h:992
@ AV1E_SET_MAX_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:581
@ AV1E_SET_ROW_MT
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition: aomcx.h:348
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition: aomcx.h:1052
@ AOME_SET_SHARPNESS
Codec control function to set loop filter sharpness, unsigned int parameter.
Definition: aomcx.h:230
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition: aomcx.h:395
@ AOME_GET_LAST_QUANTIZER_64
Codec control function to get last quantizer chosen by the encoder, int* parameter.
Definition: aomcx.h:252
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition: aomcx.h:455
@ AV1E_SET_REDUCED_REFERENCE_SET
Control to use reduced set of single and compound references, int parameter.
Definition: aomcx.h:1204
@ AV1E_SET_GF_MIN_PYRAMID_HEIGHT
Control to select minimum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1300
@ AV1E_SET_ENABLE_PAETH_INTRA
Codec control function to turn on / off Paeth intra mode usage, int parameter.
Definition: aomcx.h:1060
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition: aomcx.h:484
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition: aomcx.h:493
@ AV1E_SET_CHROMA_SUBSAMPLING_X
Sets the chroma subsampling x value, unsigned int parameter.
Definition: aomcx.h:1167
@ AV1E_SET_COLOR_RANGE
Codec control function to set color range bit, int parameter.
Definition: aomcx.h:593
@ AV1E_SET_ENABLE_RESTORATION
Codec control function to encode with Loop Restoration Filter, unsigned int parameter.
Definition: aomcx.h:662
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition: aomcx.h:1099
@ AV1E_SET_MIN_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:574
@ AOME_SET_ARNR_MAXFRAMES
Codec control function to set the max no of frames to create arf, unsigned int parameter.
Definition: aomcx.h:257
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition: aomcx.h:1234
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition: aomcx.h:1183
@ AV1E_SET_TRANSFER_CHARACTERISTICS
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:539
@ AV1E_SET_MTU
Codec control function to set an MTU size for a tile group, unsigned int parameter.
Definition: aomcx.h:782
@ AV1E_SET_DISABLE_TRELLIS_QUANT
Codec control function to encode without trellis quantization, unsigned int parameter.
Definition: aomcx.h:689
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition: aomcx.h:1095
@ AV1E_SET_ENABLE_AB_PARTITIONS
Codec control function to enable/disable AB partitions, int parameter.
Definition: aomcx.h:800
@ AV1E_SET_ENABLE_INTERINTRA_COMP
Codec control function to turn on / off interintra compound for a sequence, int parameter.
Definition: aomcx.h:968
@ AV1E_SET_FILM_GRAIN_TEST_VECTOR
Codec control function to add film grain parameters (one of several preset types) info in the bitstre...
Definition: aomcx.h:1153
@ AV1E_SET_ENABLE_CHROMA_DELTAQ
Codec control function to turn on / off delta quantization in chroma planes for a sequence,...
Definition: aomcx.h:944
@ AV1E_SET_ENABLE_DUAL_FILTER
Codec control function to turn on / off dual interpolation filter for a sequence, int parameter.
Definition: aomcx.h:936
@ AV1E_SET_FRAME_PARALLEL_DECODING
Codec control function to enable frame parallel decoding feature, unsigned int parameter.
Definition: aomcx.h:418
@ AV1E_SET_MIN_PARTITION_SIZE
Codec control function to set min partition size, int parameter.
Definition: aomcx.h:819
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition: aomcx.h:1020
@ AV1E_SET_FORCE_VIDEO_MODE
Codec control function to force video mode, unsigned int parameter.
Definition: aomcx.h:669
@ AV1E_SET_CHROMA_SUBSAMPLING_Y
Sets the chroma subsampling y value, unsigned int parameter.
Definition: aomcx.h:1170
@ AV1E_SET_ENABLE_INTRA_EDGE_FILTER
Codec control function to turn on / off intra edge filter at sequence level, int parameter.
Definition: aomcx.h:838
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition: aomcx.h:1214
@ AV1E_SET_MAX_INTER_BITRATE_PCT
Codec control function to set max data rate for inter frames, unsigned int parameter.
Definition: aomcx.h:312
@ AV1E_SET_DENOISE_NOISE_LEVEL
Sets the noise level, int parameter.
Definition: aomcx.h:1161
@ AV1E_SET_INTRA_DCT_ONLY
Control to use dct only for intra modes, int parameter.
Definition: aomcx.h:1176
@ AV1E_SET_TILE_ROWS
Codec control function to set number of tile rows, unsigned int parameter.
Definition: aomcx.h:385
@ AV1E_SET_ENABLE_REF_FRAME_MVS
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level,...
Definition: aomcx.h:917
@ AV1E_SET_ENABLE_MASKED_COMP
Codec control function to turn on / off masked compound usage (wedge and diff-wtd compound modes) for...
Definition: aomcx.h:952
@ AV1E_SET_VBR_CORPUS_COMPLEXITY_LAP
Control to set average complexity of the corpus in the case of single pass vbr based on LAP,...
Definition: aomcx.h:1305
@ AV1E_SET_GF_MAX_PYRAMID_HEIGHT
Control to select maximum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1193
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition: aomcx.h:652
@ AV1E_SET_ENABLE_FLIP_IDTX
Codec control function to turn on / off flip and identity transforms, int parameter.
Definition: aomcx.h:882
@ AV1E_SET_FRAME_PERIODIC_BOOST
Codec control function to enable/disable periodic Q boost, unsigned int parameter.
Definition: aomcx.h:467
@ AV1E_SET_ENABLE_RECT_TX
Codec control function to turn on / off rectangular transforms, int parameter.
Definition: aomcx.h:894
@ AV1E_SET_ENABLE_DIST_WTD_COMP
Codec control function to turn on / off dist-wtd compound mode at sequence level, int parameter.
Definition: aomcx.h:906
@ AV1E_SET_TIMING_INFO_TYPE
Codec control function to signal picture timing info in the bitstream, aom_timing_info_type_t paramet...
Definition: aomcx.h:1146
@ AV1E_SET_SUPERBLOCK_SIZE
Codec control function to set intended superblock size, unsigned int parameter.
Definition: aomcx.h:634
@ AV1E_SET_TIER_MASK
Control to set bit mask that specifies which tier each of the 32 possible operating points conforms t...
Definition: aomcx.h:1242
@ AV1E_SET_ENABLE_INTERINTRA_WEDGE
Codec control function to turn on / off interintra wedge compound, int parameter.
Definition: aomcx.h:1000
@ AV1E_SET_NOISE_SENSITIVITY
Codec control function to set noise sensitivity, unsigned int parameter.
Definition: aomcx.h:475
@ AV1E_SET_ENABLE_DIFF_WTD_COMP
Codec control function to turn on / off difference weighted compound, int parameter.
Definition: aomcx.h:984
@ AV1E_SET_QUANT_B_ADAPT
Control to use adaptive quantize_b, int parameter.
Definition: aomcx.h:1186
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition: aomcx.h:1041
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition: aomcx.h:1091
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition: aomcx.h:1070
@ AV1E_SET_ENABLE_KEYFRAME_FILTERING
Codec control function to enable temporal filtering on key frame, unsigned int parameter.
Definition: aomcx.h:404
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition: aomcx.h:771
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition: aomcx.h:293
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition: aomcx.h:429
@ AV1E_SET_ENABLE_SMOOTH_INTERINTRA
Codec control function to turn on / off smooth inter-intra mode for a sequence, int parameter.
Definition: aomcx.h:976
@ AOME_SET_STATIC_THRESHOLD
Codec control function to set the threshold for MBs treated static, unsigned int parameter.
Definition: aomcx.h:235
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition: aomcx.h:679
@ AV1E_SET_MAX_PARTITION_SIZE
Codec control function to set max partition size, int parameter.
Definition: aomcx.h:830
@ AV1E_SET_ENABLE_1TO4_PARTITIONS
Codec control function to enable/disable 1:4 and 4:1 partitions, int parameter.
Definition: aomcx.h:808
@ AV1E_SET_DELTALF_MODE
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled,...
Definition: aomcx.h:1119
@ AV1E_SET_ENABLE_TX64
Codec control function to turn on / off 64-length transforms, int parameter.
Definition: aomcx.h:858
@ AOME_SET_TUNING
Codec control function to set visual tuning, aom_tune_metric (int) parameter.
Definition: aomcx.h:269
@ AV1E_SET_TARGET_SEQ_LEVEL_IDX
Control to set target sequence level index for a certain operating point(OP), int parameter Possible ...
Definition: aomcx.h:619
@ AV1E_SET_CHROMA_SAMPLE_POSITION
Codec control function to set chroma 4:2:0 sample position info, aom_chroma_sample_position_t paramet...
Definition: aomcx.h:567
@ AV1E_SET_REDUCED_TX_TYPE_SET
Control to use a reduced tx type set, int parameter.
Definition: aomcx.h:1173
@ AV1E_SET_INTER_DCT_ONLY
Control to use dct only for inter modes, int parameter.
Definition: aomcx.h:1179
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition: aomcx.h:221
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition: aomcx.h:367
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition: aomcx.h:847
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition: aomcx.h:1111
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition: aomcx.h:1010
@ AV1E_SET_FILM_GRAIN_TABLE
Codec control function to set the path to the film grain parameters, const char* parameter.
Definition: aomcx.h:1158
@ AV1E_SET_QM_MAX
Codec control function to set the max quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:725
@ AV1E_SET_MAX_REFERENCE_FRAMES
Control to select maximum reference frames allowed per frame, int parameter.
Definition: aomcx.h:1200
@ 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:326
@ AV1E_SET_ENABLE_ONESIDED_COMP
Codec control function to turn on / off one sided compound usage for a sequence, int parameter.
Definition: aomcx.h:960
@ AV1E_SET_DENOISE_BLOCK_SIZE
Sets the denoisers block size, unsigned int parameter.
Definition: aomcx.h:1164
@ AV1E_SET_VMAF_MODEL_PATH
Codec control function to set the path to the VMAF model used when tuning the encoder for VMAF,...
Definition: aomcx.h:1272
@ AV1E_SET_QM_MIN
Codec control function to set the min quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:713
@ AV1E_SET_ENABLE_QM
Codec control function to encode with quantisation matrices, unsigned int parameter.
Definition: aomcx.h:700
@ AV1E_SET_ENABLE_OVERLAY
Codec control function to turn on / off overlay frames for filtered ALTREF frames,...
Definition: aomcx.h:1088
@ AV1E_SET_ENABLE_RECT_PARTITIONS
Codec control function to enable/disable rectangular partitions, int parameter.
Definition: aomcx.h:792
@ AV1E_SET_COLOR_PRIMARIES
Codec control function to set color space info, int parameter.
Definition: aomcx.h:514
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition: aomcx.h:279
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition: aomcx.h:1224
@ AV1E_SET_MIN_CR
Control to set minimum compression ratio, unsigned int parameter Take integer values....
Definition: aomcx.h:1249
@ AV1E_SET_LOSSLESS
Codec control function to set lossless encoding mode, unsigned int parameter.
Definition: aomcx.h:340
@ AOME_SET_ARNR_STRENGTH
Codec control function to set the filter strength for the arf, unsigned int parameter.
Definition: aomcx.h:262
@ 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.
const char * aom_codec_error_detail(aom_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition: aom_codec.h:254
const char * aom_codec_error(aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
const char * aom_codec_version_str(void)
Return the version information (as a string)
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_codec.h:235
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
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
@ AOM_BITS_8
Definition: aom_codec.h:319
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
#define AOM_USAGE_GOOD_QUALITY
usage parameter analogous to AV1 GOOD QUALITY mode.
Definition: aom_encoder.h:1002
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.
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition: aom_encoder.h:1004
#define AOM_CODEC_USE_HIGHBITDEPTH
Make the encoder output one partition at a time.
Definition: aom_encoder.h:70
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition: aom_encoder.h:68
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_RC_ONE_PASS
Definition: aom_encoder.h:159
@ AOM_RC_LAST_PASS
Definition: aom_encoder.h:161
@ AOM_RC_FIRST_PASS
Definition: aom_encoder.h:160
@ AOM_KF_DISABLED
Definition: aom_encoder.h:183
@ AOM_CODEC_PSNR_PKT
Definition: aom_encoder.h:101
@ AOM_CODEC_CX_FRAME_PKT
Definition: aom_encoder.h:98
@ AOM_CODEC_STATS_PKT
Definition: aom_encoder.h:99
Codec context structure.
Definition: aom_codec.h:298
aom_codec_err_t err
Definition: aom_codec.h:301
Encoder output packet.
Definition: aom_encoder.h:110
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:111
double psnr[4]
Definition: aom_encoder.h:133
aom_fixed_buf_t twopass_stats
Definition: aom_encoder.h:128
aom_fixed_buf_t raw
Definition: aom_encoder.h:144
union aom_codec_cx_pkt::@1 data
struct aom_codec_cx_pkt::@1::@2 frame
Initialization Configurations.
Definition: aom_decoder.h:91
Encoder configuration structure.
Definition: aom_encoder.h:367
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:464
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:415
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:406
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: aom_encoder.h:479
size_t sz
Definition: aom_encoder.h:78
void * buf
Definition: aom_encoder.h:77
Image Descriptor.
Definition: aom_image.h:171
aom_img_fmt_t fmt
Definition: aom_image.h:172
int stride[3]
Definition: aom_image.h:203
unsigned int d_w
Definition: aom_image.h:186
unsigned int d_h
Definition: aom_image.h:187
unsigned char * planes[3]
Definition: aom_image.h:202
Rational Number.
Definition: aom_encoder.h:152
int num
Definition: aom_encoder.h:153
int den
Definition: aom_encoder.h:154
Encoder Config Options.
Definition: aom_encoder.h:207
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:223
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:219
unsigned int disable_trellis_quant
disable trellis quantization
Definition: aom_encoder.h:335
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition: aom_encoder.h:215