12#include "apps/aomenc.h"
14#include "config/aom_config.h"
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"
54static 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
59static 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
65static const char *exec_name;
67static AOM_TOOLS_FORMAT_PRINTF(3, 0) void warn_or_exit_on_errorv(
72 vfprintf(stderr, s, ap);
75 if (detail) fprintf(stderr,
" %s\n", detail);
84static AOM_TOOLS_FORMAT_PRINTF(2,
90 warn_or_exit_on_errorv(ctx, 1, s, ap);
94static AOM_TOOLS_FORMAT_PRINTF(3, 4) void warn_or_exit_on_error(
99 warn_or_exit_on_errorv(ctx, fatal, s, ap);
103static int read_frame(
struct AvxInputContext *input_ctx,
aom_image_t *img) {
104 FILE *f = input_ctx->file;
105 y4m_input *y4m = &input_ctx->y4m;
108 if (input_ctx->file_type == FILE_TYPE_Y4M) {
109 if (y4m_input_fetch_frame(y4m, f, img) < 1)
return 0;
111 shortread = read_yuv_frame(input_ctx, img);
117static int file_is_y4m(
const char detect[4]) {
118 if (memcmp(detect,
"YUV4", 4) == 0) {
124static int fourcc_is_ivf(
const char detect[4]) {
125 if (memcmp(detect,
"DKIF", 4) == 0) {
223 AV1E_SET_ENABLE_DNL_DENOISING,
247const arg_def_t *main_args[] = { &g_av1_codec_arg_defs.help,
248 &g_av1_codec_arg_defs.use_cfg,
249 &g_av1_codec_arg_defs.debugmode,
250 &g_av1_codec_arg_defs.outputfile,
251 &g_av1_codec_arg_defs.codecarg,
252 &g_av1_codec_arg_defs.passes,
253 &g_av1_codec_arg_defs.pass_arg,
254 &g_av1_codec_arg_defs.fpf_name,
255 &g_av1_codec_arg_defs.limit,
256 &g_av1_codec_arg_defs.skip,
257 &g_av1_codec_arg_defs.good_dl,
258 &g_av1_codec_arg_defs.rt_dl,
259 &g_av1_codec_arg_defs.ai_dl,
260 &g_av1_codec_arg_defs.quietarg,
261 &g_av1_codec_arg_defs.verbosearg,
262 &g_av1_codec_arg_defs.psnrarg,
263 &g_av1_codec_arg_defs.use_webm,
264 &g_av1_codec_arg_defs.use_ivf,
265 &g_av1_codec_arg_defs.use_obu,
266 &g_av1_codec_arg_defs.q_hist_n,
267 &g_av1_codec_arg_defs.rate_hist_n,
268 &g_av1_codec_arg_defs.disable_warnings,
269 &g_av1_codec_arg_defs.disable_warning_prompt,
270 &g_av1_codec_arg_defs.recontest,
273const arg_def_t *global_args[] = {
274 &g_av1_codec_arg_defs.use_nv12,
275 &g_av1_codec_arg_defs.use_yv12,
276 &g_av1_codec_arg_defs.use_i420,
277 &g_av1_codec_arg_defs.use_i422,
278 &g_av1_codec_arg_defs.use_i444,
279 &g_av1_codec_arg_defs.usage,
280 &g_av1_codec_arg_defs.threads,
281 &g_av1_codec_arg_defs.profile,
282 &g_av1_codec_arg_defs.width,
283 &g_av1_codec_arg_defs.height,
284 &g_av1_codec_arg_defs.forced_max_frame_width,
285 &g_av1_codec_arg_defs.forced_max_frame_height,
287 &g_av1_codec_arg_defs.stereo_mode,
289 &g_av1_codec_arg_defs.timebase,
290 &g_av1_codec_arg_defs.framerate,
291 &g_av1_codec_arg_defs.global_error_resilient,
292 &g_av1_codec_arg_defs.bitdeptharg,
293 &g_av1_codec_arg_defs.inbitdeptharg,
294 &g_av1_codec_arg_defs.lag_in_frames,
295 &g_av1_codec_arg_defs.large_scale_tile,
296 &g_av1_codec_arg_defs.monochrome,
297 &g_av1_codec_arg_defs.full_still_picture_hdr,
298 &g_av1_codec_arg_defs.use_16bit_internal,
299 &g_av1_codec_arg_defs.save_as_annexb,
303const arg_def_t *rc_args[] = { &g_av1_codec_arg_defs.dropframe_thresh,
304 &g_av1_codec_arg_defs.resize_mode,
305 &g_av1_codec_arg_defs.resize_denominator,
306 &g_av1_codec_arg_defs.resize_kf_denominator,
307 &g_av1_codec_arg_defs.superres_mode,
308 &g_av1_codec_arg_defs.superres_denominator,
309 &g_av1_codec_arg_defs.superres_kf_denominator,
310 &g_av1_codec_arg_defs.superres_qthresh,
311 &g_av1_codec_arg_defs.superres_kf_qthresh,
312 &g_av1_codec_arg_defs.end_usage,
313 &g_av1_codec_arg_defs.target_bitrate,
314 &g_av1_codec_arg_defs.min_quantizer,
315 &g_av1_codec_arg_defs.max_quantizer,
316 &g_av1_codec_arg_defs.undershoot_pct,
317 &g_av1_codec_arg_defs.overshoot_pct,
318 &g_av1_codec_arg_defs.buf_sz,
319 &g_av1_codec_arg_defs.buf_initial_sz,
320 &g_av1_codec_arg_defs.buf_optimal_sz,
321 &g_av1_codec_arg_defs.bias_pct,
322 &g_av1_codec_arg_defs.minsection_pct,
323 &g_av1_codec_arg_defs.maxsection_pct,
326const arg_def_t *kf_args[] = { &g_av1_codec_arg_defs.fwd_kf_enabled,
327 &g_av1_codec_arg_defs.kf_min_dist,
328 &g_av1_codec_arg_defs.kf_max_dist,
329 &g_av1_codec_arg_defs.kf_disabled,
330 &g_av1_codec_arg_defs.sframe_dist,
331 &g_av1_codec_arg_defs.sframe_mode,
336const arg_def_t *av1_ctrl_args[] = {
337 &g_av1_codec_arg_defs.cpu_used_av1,
338 &g_av1_codec_arg_defs.auto_altref,
339 &g_av1_codec_arg_defs.sharpness,
340 &g_av1_codec_arg_defs.static_thresh,
341 &g_av1_codec_arg_defs.rowmtarg,
342 &g_av1_codec_arg_defs.fpmtarg,
343 &g_av1_codec_arg_defs.tile_cols,
344 &g_av1_codec_arg_defs.tile_rows,
345 &g_av1_codec_arg_defs.enable_tpl_model,
346 &g_av1_codec_arg_defs.enable_keyframe_filtering,
347 &g_av1_codec_arg_defs.arnr_maxframes,
348 &g_av1_codec_arg_defs.arnr_strength,
349 &g_av1_codec_arg_defs.tune_metric,
350 &g_av1_codec_arg_defs.cq_level,
351 &g_av1_codec_arg_defs.max_intra_rate_pct,
352 &g_av1_codec_arg_defs.max_inter_rate_pct,
353 &g_av1_codec_arg_defs.gf_cbr_boost_pct,
354 &g_av1_codec_arg_defs.lossless,
355 &g_av1_codec_arg_defs.enable_cdef,
356 &g_av1_codec_arg_defs.enable_restoration,
357 &g_av1_codec_arg_defs.enable_rect_partitions,
358 &g_av1_codec_arg_defs.enable_ab_partitions,
359 &g_av1_codec_arg_defs.enable_1to4_partitions,
360 &g_av1_codec_arg_defs.min_partition_size,
361 &g_av1_codec_arg_defs.max_partition_size,
362 &g_av1_codec_arg_defs.enable_dual_filter,
363 &g_av1_codec_arg_defs.enable_chroma_deltaq,
364 &g_av1_codec_arg_defs.enable_intra_edge_filter,
365 &g_av1_codec_arg_defs.enable_order_hint,
366 &g_av1_codec_arg_defs.enable_tx64,
367 &g_av1_codec_arg_defs.enable_flip_idtx,
368 &g_av1_codec_arg_defs.enable_rect_tx,
369 &g_av1_codec_arg_defs.enable_dist_wtd_comp,
370 &g_av1_codec_arg_defs.enable_masked_comp,
371 &g_av1_codec_arg_defs.enable_onesided_comp,
372 &g_av1_codec_arg_defs.enable_interintra_comp,
373 &g_av1_codec_arg_defs.enable_smooth_interintra,
374 &g_av1_codec_arg_defs.enable_diff_wtd_comp,
375 &g_av1_codec_arg_defs.enable_interinter_wedge,
376 &g_av1_codec_arg_defs.enable_interintra_wedge,
377 &g_av1_codec_arg_defs.enable_global_motion,
378 &g_av1_codec_arg_defs.enable_warped_motion,
379 &g_av1_codec_arg_defs.enable_filter_intra,
380 &g_av1_codec_arg_defs.enable_smooth_intra,
381 &g_av1_codec_arg_defs.enable_paeth_intra,
382 &g_av1_codec_arg_defs.enable_cfl_intra,
383 &g_av1_codec_arg_defs.enable_diagonal_intra,
384 &g_av1_codec_arg_defs.force_video_mode,
385 &g_av1_codec_arg_defs.enable_obmc,
386 &g_av1_codec_arg_defs.enable_overlay,
387 &g_av1_codec_arg_defs.enable_palette,
388 &g_av1_codec_arg_defs.enable_intrabc,
389 &g_av1_codec_arg_defs.enable_angle_delta,
390 &g_av1_codec_arg_defs.disable_trellis_quant,
391 &g_av1_codec_arg_defs.enable_qm,
392 &g_av1_codec_arg_defs.qm_min,
393 &g_av1_codec_arg_defs.qm_max,
394 &g_av1_codec_arg_defs.reduced_tx_type_set,
395 &g_av1_codec_arg_defs.use_intra_dct_only,
396 &g_av1_codec_arg_defs.use_inter_dct_only,
397 &g_av1_codec_arg_defs.use_intra_default_tx_only,
398 &g_av1_codec_arg_defs.quant_b_adapt,
399 &g_av1_codec_arg_defs.coeff_cost_upd_freq,
400 &g_av1_codec_arg_defs.mode_cost_upd_freq,
401 &g_av1_codec_arg_defs.mv_cost_upd_freq,
402 &g_av1_codec_arg_defs.frame_parallel_decoding,
403 &g_av1_codec_arg_defs.error_resilient_mode,
404 &g_av1_codec_arg_defs.aq_mode,
405 &g_av1_codec_arg_defs.deltaq_mode,
406 &g_av1_codec_arg_defs.deltaq_strength,
407 &g_av1_codec_arg_defs.deltalf_mode,
408 &g_av1_codec_arg_defs.frame_periodic_boost,
409 &g_av1_codec_arg_defs.noise_sens,
410 &g_av1_codec_arg_defs.tune_content,
411 &g_av1_codec_arg_defs.cdf_update_mode,
412 &g_av1_codec_arg_defs.input_color_primaries,
413 &g_av1_codec_arg_defs.input_transfer_characteristics,
414 &g_av1_codec_arg_defs.input_matrix_coefficients,
415 &g_av1_codec_arg_defs.input_chroma_sample_position,
416 &g_av1_codec_arg_defs.min_gf_interval,
417 &g_av1_codec_arg_defs.max_gf_interval,
418 &g_av1_codec_arg_defs.gf_min_pyr_height,
419 &g_av1_codec_arg_defs.gf_max_pyr_height,
420 &g_av1_codec_arg_defs.superblock_size,
421 &g_av1_codec_arg_defs.num_tg,
422 &g_av1_codec_arg_defs.mtu_size,
423 &g_av1_codec_arg_defs.timing_info,
424 &g_av1_codec_arg_defs.film_grain_test,
425 &g_av1_codec_arg_defs.film_grain_table,
427 &g_av1_codec_arg_defs.denoise_noise_level,
428 &g_av1_codec_arg_defs.denoise_block_size,
429 &g_av1_codec_arg_defs.enable_dnl_denoising,
431 &g_av1_codec_arg_defs.max_reference_frames,
432 &g_av1_codec_arg_defs.reduced_reference_set,
433 &g_av1_codec_arg_defs.enable_ref_frame_mvs,
434 &g_av1_codec_arg_defs.target_seq_level_idx,
435 &g_av1_codec_arg_defs.set_tier_mask,
436 &g_av1_codec_arg_defs.set_min_cr,
437 &g_av1_codec_arg_defs.vbr_corpus_complexity_lap,
438 &g_av1_codec_arg_defs.input_chroma_subsampling_x,
439 &g_av1_codec_arg_defs.input_chroma_subsampling_y,
441 &g_av1_codec_arg_defs.vmaf_model_path,
443 &g_av1_codec_arg_defs.dv_cost_upd_freq,
444 &g_av1_codec_arg_defs.partition_info_path,
445 &g_av1_codec_arg_defs.enable_directional_intra,
446 &g_av1_codec_arg_defs.enable_tx_size_search,
447 &g_av1_codec_arg_defs.loopfilter_control,
448 &g_av1_codec_arg_defs.auto_intra_tools_off,
449 &g_av1_codec_arg_defs.enable_rate_guide_deltaq,
450 &g_av1_codec_arg_defs.rate_distribution_info,
454const arg_def_t *av1_key_val_args[] = {
455 &g_av1_codec_arg_defs.passes,
456 &g_av1_codec_arg_defs.two_pass_output,
457 &g_av1_codec_arg_defs.second_pass_log,
458 &g_av1_codec_arg_defs.fwd_kf_dist,
459 &g_av1_codec_arg_defs.strict_level_conformance,
460 &g_av1_codec_arg_defs.sb_qp_sweep,
461 &g_av1_codec_arg_defs.dist_metric,
462 &g_av1_codec_arg_defs.kf_max_pyr_height,
466static const arg_def_t *no_args[] = { NULL };
468static void show_help(FILE *fout,
int shorthelp) {
469 fprintf(fout,
"Usage: %s <options> -o dst_filename src_filename\n",
473 fprintf(fout,
"Use --help to see the full list of options.\n");
477 fprintf(fout,
"\nOptions:\n");
478 arg_show_usage(fout, main_args);
479 fprintf(fout,
"\nEncoder Global Options:\n");
480 arg_show_usage(fout, global_args);
481 fprintf(fout,
"\nRate Control Options:\n");
482 arg_show_usage(fout, rc_args);
483 fprintf(fout,
"\nKeyframe Placement Options:\n");
484 arg_show_usage(fout, kf_args);
485#if CONFIG_AV1_ENCODER
486 fprintf(fout,
"\nAV1 Specific Options:\n");
487 arg_show_usage(fout, av1_ctrl_args);
488 arg_show_usage(fout, av1_key_val_args);
491 "\nStream timebase (--timebase):\n"
492 " The desired precision of timestamps in the output, expressed\n"
493 " in fractional seconds. Default is 1/1000.\n");
494 fprintf(fout,
"\nIncluded encoders:\n\n");
496 const int num_encoder = get_aom_encoder_count();
497 for (
int i = 0; i < num_encoder; ++i) {
499 const char *defstr = (i == (num_encoder - 1)) ?
"(default)" :
"";
500 fprintf(fout,
" %-6s - %s %s\n", get_short_name_by_aom_encoder(encoder),
503 fprintf(fout,
"\n ");
504 fprintf(fout,
"Use --codec to switch to a non-default encoder.\n\n");
507void usage_exit(
void) {
508 show_help(stderr, 1);
512#if CONFIG_AV1_ENCODER
513#define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
514#define ARG_KEY_VAL_CNT_MAX NELEMENTS(av1_key_val_args)
518typedef int stereo_format_t;
519struct WebmOutputContext {
525struct stream_config {
528 const char *stats_fn;
529 stereo_format_t stereo_fmt;
530 int arg_ctrls[ARG_CTRL_CNT_MAX][2];
532 const char *arg_key_vals[ARG_KEY_VAL_CNT_MAX][2];
535 const char *film_grain_filename;
538 int use_16bit_internal;
540 const char *vmaf_model_path;
542 const char *partition_info_path;
543 unsigned int enable_rate_guide_deltaq;
544 const char *rate_distribution_info;
546 const char *two_pass_input;
547 const char *two_pass_output;
554 struct stream_state *next;
555 struct stream_config config;
557 struct rate_hist *rate_hist;
558 struct WebmOutputContext webm_ctx;
559 uint64_t psnr_sse_total[2];
560 uint64_t psnr_samples_total[2];
561 double psnr_totals[2][4];
565 unsigned int frames_out;
572 unsigned int chroma_subsampling_x;
573 unsigned int chroma_subsampling_y;
574 const char *orig_out_fn;
575 unsigned int orig_width;
576 unsigned int orig_height;
579 char tmp_out_fn[1000];
582static void validate_positive_rational(
const char *msg,
589 if (rat->
num < 0) die(
"Error: %s must be positive\n", msg);
591 if (!rat->
den) die(
"Error: %s has zero denominator\n", msg);
605static void parse_global_config(
struct AvxEncoderConfig *global,
char ***argv) {
608 const int num_encoder = get_aom_encoder_count();
609 char **argv_local = (
char **)*argv;
610 if (num_encoder < 1) die(
"Error: no valid encoder available\n");
613 memset(global, 0,
sizeof(*global));
614 global->codec = get_aom_encoder_by_index(num_encoder - 1);
616 global->color_type = I420;
618 global->show_psnr = 0;
620 int cfg_included = 0;
621 init_config(&global->encoder_config);
623 for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
626 if (arg_match(&arg, &g_av1_codec_arg_defs.use_cfg, argi)) {
628 parse_cfg(arg.val, &global->encoder_config);
631 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.help, argi)) {
632 show_help(stdout, 0);
634 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.codecarg, argi)) {
635 global->codec = get_aom_encoder_by_short_name(arg.val);
637 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
638 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.passes, argi)) {
639 global->passes = arg_parse_uint(&arg);
641 if (global->passes < 1 || global->passes > 3)
642 die(
"Error: Invalid number of passes (%d)\n", global->passes);
643 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.pass_arg, argi)) {
644 global->pass = arg_parse_uint(&arg);
646 if (global->pass < 1 || global->pass > 3)
647 die(
"Error: Invalid pass selected (%d)\n", global->pass);
648 }
else if (arg_match(&arg,
649 &g_av1_codec_arg_defs.input_chroma_sample_position,
651 global->csp = arg_parse_enum(&arg);
654 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.usage, argi)) {
655 global->usage = arg_parse_uint(&arg);
656 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.good_dl, argi)) {
658 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rt_dl, argi)) {
660 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.ai_dl, argi)) {
662 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_nv12, argi)) {
663 global->color_type = NV12;
664 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_yv12, argi)) {
665 global->color_type = YV12;
666 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i420, argi)) {
667 global->color_type = I420;
668 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i422, argi)) {
669 global->color_type = I422;
670 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i444, argi)) {
671 global->color_type = I444;
672 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.quietarg, argi)) {
674 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.verbosearg, argi)) {
676 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.limit, argi)) {
677 global->limit = arg_parse_uint(&arg);
678 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.skip, argi)) {
679 global->skip_frames = arg_parse_uint(&arg);
680 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.psnrarg, argi)) {
682 global->show_psnr = arg_parse_int(&arg);
684 global->show_psnr = 1;
685 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.recontest, argi)) {
686 global->test_decode = arg_parse_enum_or_int(&arg);
687 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.framerate, argi)) {
688 global->framerate = arg_parse_rational(&arg);
689 validate_positive_rational(arg.name, &global->framerate);
690 global->have_framerate = 1;
691 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.debugmode, argi)) {
693 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.q_hist_n, argi)) {
694 global->show_q_hist_buckets = arg_parse_uint(&arg);
695 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_hist_n, argi)) {
696 global->show_rate_hist_buckets = arg_parse_uint(&arg);
697 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warnings, argi)) {
698 global->disable_warnings = 1;
699 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warning_prompt,
701 global->disable_warning_prompt = 1;
709 if (global->pass > global->passes) {
710 aom_tools_warn(
"Assuming --pass=%d implies --passes=%d\n", global->pass,
712 global->passes = global->pass;
716 if (global->passes == 0) {
717#if CONFIG_AV1_ENCODER
720 if (global->codec != NULL)
722 (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0 &&
732 aom_tools_warn(
"Enforcing one-pass encoding in realtime mode\n");
733 if (global->pass > 1)
734 die(
"Error: Invalid --pass=%d for one-pass encoding\n", global->pass);
739 aom_tools_warn(
"Enforcing one-pass encoding in all intra mode\n");
744static void open_input_file(
struct AvxInputContext *input,
747 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
748 : set_binary_mode(stdin);
750 if (!input->file) fatal(
"Failed to open input file");
752 if (!fseeko(input->file, 0, SEEK_END)) {
756 input->length = ftello(input->file);
761 input->pixel_aspect_ratio.numerator = 1;
762 input->pixel_aspect_ratio.denominator = 1;
767 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
768 input->detect.position = 0;
770 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
771 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
772 input->only_i420) >= 0) {
773 input->file_type = FILE_TYPE_Y4M;
774 input->width = input->y4m.pic_w;
775 input->height = input->y4m.pic_h;
776 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
777 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
778 input->framerate.numerator = input->y4m.fps_n;
779 input->framerate.denominator = input->y4m.fps_d;
780 input->fmt = input->y4m.aom_fmt;
781 input->bit_depth = input->y4m.bit_depth;
782 input->color_range = input->y4m.color_range;
784 fatal(
"Unsupported Y4M stream.");
785 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
786 fatal(
"IVF is not supported as input.");
788 input->file_type = FILE_TYPE_RAW;
792static void close_input_file(
struct AvxInputContext *input) {
794 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
797static struct stream_state *new_stream(
struct AvxEncoderConfig *global,
798 struct stream_state *prev) {
799 struct stream_state *stream;
801 stream = calloc(1,
sizeof(*stream));
802 if (stream == NULL) {
803 fatal(
"Failed to allocate new stream.");
807 memcpy(stream, prev,
sizeof(*stream));
821 stream->config.cfg.g_timebase.den = 1000;
826 stream->config.cfg.g_w = 0;
827 stream->config.cfg.g_h = 0;
830 stream->config.write_webm = 1;
831 stream->config.write_ivf = 0;
834 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
835 stream->webm_ctx.last_pts_ns = -1;
836 stream->webm_ctx.writer = NULL;
837 stream->webm_ctx.segment = NULL;
841 stream->webm_ctx.debug = global->debug;
842 memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
843 sizeof(stream->config.cfg.encoder_cfg));
847 stream->config.out_fn = NULL;
848 stream->config.two_pass_input = NULL;
849 stream->config.two_pass_output = NULL;
850 stream->config.two_pass_width = 0;
851 stream->config.two_pass_height = 0;
857static void set_config_arg_ctrls(
struct stream_config *config,
int key,
858 const struct arg *arg) {
861 config->film_grain_filename = arg->val;
868 j = config->arg_ctrl_cnt;
869 assert(j < ARG_CTRL_CNT_MAX);
870 config->arg_ctrls[j][0] = key;
871 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
872 ++config->arg_ctrl_cnt;
879 for (j = 0; j < config->arg_ctrl_cnt; j++)
880 if (config->arg_ctrls[j][0] == key)
break;
883 assert(j < ARG_CTRL_CNT_MAX);
884 config->arg_ctrls[j][0] = key;
885 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
889 "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
890 config->arg_ctrls[j][1] = 1;
893 if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
896static void set_config_arg_key_vals(
struct stream_config *config,
897 const char *name,
const struct arg *arg) {
899 const char *val = arg->val;
902 if (strcmp(name,
"target-seq-level-idx") == 0) {
903 j = config->arg_key_val_cnt;
904 assert(j < ARG_KEY_VAL_CNT_MAX);
905 config->arg_key_vals[j][0] = name;
906 config->arg_key_vals[j][1] = val;
907 ++config->arg_key_val_cnt;
914 for (j = 0; j < config->arg_key_val_cnt; j++)
915 if (strcmp(name, config->arg_key_vals[j][0]) == 0)
break;
918 assert(j < ARG_KEY_VAL_CNT_MAX);
919 config->arg_key_vals[j][0] = name;
920 config->arg_key_vals[j][1] = val;
922 if (strcmp(name, g_av1_codec_arg_defs.auto_altref.long_name) == 0) {
923 int auto_altref = arg_parse_int(arg);
924 if (auto_altref > 1) {
926 "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
927 config->arg_key_vals[j][1] =
"1";
931 if (j == config->arg_key_val_cnt) config->arg_key_val_cnt++;
934static int parse_stream_params(
struct AvxEncoderConfig *global,
935 struct stream_state *stream,
char **argv) {
938 static const arg_def_t **ctrl_args = no_args;
939 static const arg_def_t **key_val_args = no_args;
940 static const int *ctrl_args_map = NULL;
941 struct stream_config *config = &stream->config;
942 int eos_mark_found = 0;
947#if CONFIG_AV1_ENCODER
948 }
else if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
951#if __STDC_VERSION__ >= 201112L
952 _Static_assert(NELEMENTS(av1_ctrl_args) == NELEMENTS(av1_arg_ctrl_map),
953 "The av1_ctrl_args and av1_arg_ctrl_map arrays must be of "
956 assert(NELEMENTS(av1_ctrl_args) == NELEMENTS(av1_arg_ctrl_map));
958 ctrl_args = av1_ctrl_args;
959 ctrl_args_map = av1_arg_ctrl_map;
960 key_val_args = av1_key_val_args;
964 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
970 if (eos_mark_found) {
973 }
else if (!strcmp(*argj,
"--")) {
978 if (arg_match(&arg, &g_av1_codec_arg_defs.outputfile, argi)) {
979 config->out_fn = arg.val;
981 const size_t out_fn_len = strlen(config->out_fn);
982 if (out_fn_len >= 4 &&
983 !strcmp(config->out_fn + out_fn_len - 4,
".ivf")) {
984 config->write_webm = 0;
985 config->write_ivf = 1;
986 }
else if (out_fn_len >= 4 &&
987 !strcmp(config->out_fn + out_fn_len - 4,
".obu")) {
988 config->write_webm = 0;
989 config->write_ivf = 0;
992 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fpf_name, argi)) {
993 config->stats_fn = arg.val;
994 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_webm, argi)) {
996 config->write_webm = 1;
999 die(
"Error: --webm specified but webm is disabled.");
1001 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_ivf, argi)) {
1002 config->write_webm = 0;
1003 config->write_ivf = 1;
1004 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_obu, argi)) {
1005 config->write_webm = 0;
1006 config->write_ivf = 0;
1007 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.threads, argi)) {
1008 config->cfg.g_threads = arg_parse_uint(&arg);
1009 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.profile, argi)) {
1010 config->cfg.g_profile = arg_parse_uint(&arg);
1011 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.width, argi)) {
1012 config->cfg.g_w = arg_parse_uint(&arg);
1013 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.height, argi)) {
1014 config->cfg.g_h = arg_parse_uint(&arg);
1015 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_width,
1017 config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
1018 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_height,
1020 config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
1021 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bitdeptharg, argi)) {
1022 config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
1023 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.inbitdeptharg, argi)) {
1024 config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
1025 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_x,
1027 stream->chroma_subsampling_x = arg_parse_uint(&arg);
1028 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_y,
1030 stream->chroma_subsampling_y = arg_parse_uint(&arg);
1032 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.stereo_mode, argi)) {
1033 config->stereo_fmt = arg_parse_enum_or_int(&arg);
1035 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.timebase, argi)) {
1036 config->cfg.g_timebase = arg_parse_rational(&arg);
1037 validate_positive_rational(arg.name, &config->cfg.g_timebase);
1038 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.global_error_resilient,
1040 config->cfg.g_error_resilient = arg_parse_uint(&arg);
1041 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.lag_in_frames, argi)) {
1042 config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
1043 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.large_scale_tile, argi)) {
1044 config->cfg.large_scale_tile = arg_parse_uint(&arg);
1045 if (config->cfg.large_scale_tile) {
1046 global->codec = get_aom_encoder_by_short_name(
"av1");
1048 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.monochrome, argi)) {
1049 config->cfg.monochrome = 1;
1050 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.full_still_picture_hdr,
1052 config->cfg.full_still_picture_hdr = 1;
1053 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_16bit_internal,
1055 config->use_16bit_internal = CONFIG_AV1_HIGHBITDEPTH;
1056 if (!config->use_16bit_internal) {
1057 aom_tools_warn(
"%s option ignored with CONFIG_AV1_HIGHBITDEPTH=0.\n",
1060 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.dropframe_thresh, argi)) {
1061 config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
1062 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_mode, argi)) {
1063 config->cfg.rc_resize_mode = arg_parse_uint(&arg);
1064 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_denominator,
1066 config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
1067 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_kf_denominator,
1069 config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
1070 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_mode, argi)) {
1071 config->cfg.rc_superres_mode = arg_parse_uint(&arg);
1072 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_denominator,
1074 config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
1075 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_denominator,
1077 config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
1078 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_qthresh, argi)) {
1079 config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
1080 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_qthresh,
1082 config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
1083 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.end_usage, argi)) {
1084 config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
1085 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.target_bitrate, argi)) {
1086 config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
1087 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.min_quantizer, argi)) {
1088 config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
1089 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.max_quantizer, argi)) {
1090 config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
1091 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.undershoot_pct, argi)) {
1092 config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
1093 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.overshoot_pct, argi)) {
1094 config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
1095 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_sz, argi)) {
1096 config->cfg.rc_buf_sz = arg_parse_uint(&arg);
1097 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_initial_sz, argi)) {
1098 config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
1099 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_optimal_sz, argi)) {
1100 config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
1101 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bias_pct, argi)) {
1102 config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
1103 if (global->passes < 2)
1104 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1105 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.minsection_pct, argi)) {
1106 config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
1108 if (global->passes < 2)
1109 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1110 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.maxsection_pct, argi)) {
1111 config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
1113 if (global->passes < 2)
1114 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1115 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fwd_kf_enabled, argi)) {
1116 config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
1117 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_min_dist, argi)) {
1118 config->cfg.kf_min_dist = arg_parse_uint(&arg);
1119 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_max_dist, argi)) {
1120 config->cfg.kf_max_dist = arg_parse_uint(&arg);
1121 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_disabled, argi)) {
1123 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_dist, argi)) {
1124 config->cfg.sframe_dist = arg_parse_uint(&arg);
1125 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_mode, argi)) {
1126 config->cfg.sframe_mode = arg_parse_uint(&arg);
1127 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.save_as_annexb, argi)) {
1128 config->cfg.save_as_annexb = arg_parse_uint(&arg);
1129 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_width, argi)) {
1130 config->cfg.tile_width_count =
1132 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_height, argi)) {
1133 config->cfg.tile_height_count =
1136 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argi)) {
1137 config->vmaf_model_path = arg.val;
1139 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.partition_info_path,
1141 config->partition_info_path = arg.val;
1142 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.enable_rate_guide_deltaq,
1144 config->enable_rate_guide_deltaq = arg_parse_uint(&arg);
1145 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_distribution_info,
1147 config->rate_distribution_info = arg.val;
1148 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_fixed_qp_offsets,
1150 config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg);
1151 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fixed_qp_offsets, argi)) {
1152 config->cfg.use_fixed_qp_offsets = 1;
1154 arg_match(&arg, &g_av1_codec_arg_defs.enable_restoration,
1156 if (arg_parse_uint(&arg) == 1) {
1157 aom_tools_warn(
"non-zero %s option ignored in realtime mode.\n",
1160 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_input, argi)) {
1161 config->two_pass_input = arg.val;
1162 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_output, argi)) {
1163 config->two_pass_output = arg.val;
1164 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_width, argi)) {
1165 config->two_pass_width = arg_parse_int(&arg);
1166 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_height, argi)) {
1167 config->two_pass_height = arg_parse_int(&arg);
1171 if (ctrl_args_map) {
1172 for (i = 0; ctrl_args[i]; i++) {
1173 if (arg_match(&arg, ctrl_args[i], argi)) {
1175 set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1182 for (i = 0; key_val_args[i]; i++) {
1183 if (arg_match(&arg, key_val_args[i], argi)) {
1185 set_config_arg_key_vals(config, key_val_args[i]->long_name, &arg);
1193 config->use_16bit_internal |= config->cfg.g_bit_depth >
AOM_BITS_8;
1196 aom_tools_warn(
"non-zero lag-in-frames option ignored in realtime mode.\n");
1197 config->cfg.g_lag_in_frames = 0;
1201 if (config->cfg.g_lag_in_frames != 0) {
1203 "non-zero lag-in-frames option ignored in all intra mode.\n");
1204 config->cfg.g_lag_in_frames = 0;
1206 if (config->cfg.kf_max_dist != 0) {
1208 "non-zero max key frame distance option ignored in all intra "
1210 config->cfg.kf_max_dist = 0;
1215 if (config->arg_key_val_cnt >= ARG_KEY_VAL_CNT_MAX) {
1216 die(
"Not enough buffer for the key & value API.");
1218 config->arg_key_vals[config->arg_key_val_cnt][0] =
"passes";
1219 switch (global->passes) {
1220 case 0: config->arg_key_vals[config->arg_key_val_cnt][1] =
"0";
break;
1221 case 1: config->arg_key_vals[config->arg_key_val_cnt][1] =
"1";
break;
1222 case 2: config->arg_key_vals[config->arg_key_val_cnt][1] =
"2";
break;
1223 case 3: config->arg_key_vals[config->arg_key_val_cnt][1] =
"3";
break;
1224 default: die(
"Invalid value of --passes.");
1226 config->arg_key_val_cnt++;
1229 if (!config->two_pass_output && global->passes == 3) {
1231 snprintf(stream->tmp_out_fn,
sizeof(stream->tmp_out_fn),
1232 "%.980s_pass2_%d.ivf", stream->config.out_fn, stream->index);
1233 stream->config.two_pass_output = stream->tmp_out_fn;
1235 if (config->two_pass_output) {
1236 config->arg_key_vals[config->arg_key_val_cnt][0] =
"two-pass-output";
1237 config->arg_key_vals[config->arg_key_val_cnt][1] = config->two_pass_output;
1238 config->arg_key_val_cnt++;
1241 return eos_mark_found;
1244#define FOREACH_STREAM(iterator, list) \
1245 for (struct stream_state *iterator = list; iterator; \
1246 iterator = iterator->next)
1248static void validate_stream_config(
const struct stream_state *stream,
1249 const struct AvxEncoderConfig *global) {
1250 const struct stream_state *streami;
1253 if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1255 "Stream %d: Specify stream dimensions with --width (-w) "
1256 " and --height (-h)",
1262 assert(stream->config.cfg.g_input_bit_depth <=
1263 (
unsigned int)stream->config.cfg.g_bit_depth);
1265 for (streami = stream; streami; streami = streami->next) {
1267 if (!streami->config.out_fn)
1268 fatal(
"Stream %d: Output file is required (specify with -o)",
1272 if (streami != stream) {
1273 const char *a = stream->config.out_fn;
1274 const char *b = streami->config.out_fn;
1275 if (!strcmp(a, b) && strcmp(a,
"/dev/null") && strcmp(a,
":nul"))
1276 fatal(
"Stream %d: duplicate output file (from stream %d)",
1277 streami->index, stream->index);
1281 if (streami != stream) {
1282 const char *a = stream->config.stats_fn;
1283 const char *b = streami->config.stats_fn;
1284 if (a && b && !strcmp(a, b))
1285 fatal(
"Stream %d: duplicate stats file (from stream %d)",
1286 streami->index, stream->index);
1291static void set_stream_dimensions(
struct stream_state *stream,
unsigned int w,
1293 if (!stream->config.cfg.g_w) {
1294 if (!stream->config.cfg.g_h)
1295 stream->config.cfg.g_w = w;
1297 stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1299 if (!stream->config.cfg.g_h) {
1300 stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1304static const char *file_type_to_string(
enum VideoFileType t) {
1306 case FILE_TYPE_RAW:
return "RAW";
1307 case FILE_TYPE_Y4M:
return "Y4M";
1308 default:
return "Other";
1312static void show_stream_config(
struct stream_state *stream,
1313 struct AvxEncoderConfig *global,
1314 struct AvxInputContext *input) {
1315#define SHOW(field) \
1316 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1318 if (stream->index == 0) {
1320 fprintf(stderr,
"Source file: %s File Type: %s Format: %s\n",
1321 input->filename, file_type_to_string(input->file_type),
1322 image_format_to_string(input->fmt));
1324 if (stream->next || stream->index)
1325 fprintf(stderr,
"\nStream Index: %d\n", stream->index);
1326 fprintf(stderr,
"Destination file: %s\n", stream->config.out_fn);
1327 fprintf(stderr,
"Coding path: %s\n",
1328 stream->config.use_16bit_internal ?
"HBD" :
"LBD");
1329 fprintf(stderr,
"Encoder parameters:\n");
1337 SHOW(g_input_bit_depth);
1338 SHOW(g_timebase.num);
1339 SHOW(g_timebase.den);
1340 SHOW(g_error_resilient);
1342 SHOW(g_lag_in_frames);
1343 SHOW(large_scale_tile);
1344 SHOW(rc_dropframe_thresh);
1345 SHOW(rc_resize_mode);
1346 SHOW(rc_resize_denominator);
1347 SHOW(rc_resize_kf_denominator);
1348 SHOW(rc_superres_mode);
1349 SHOW(rc_superres_denominator);
1350 SHOW(rc_superres_kf_denominator);
1351 SHOW(rc_superres_qthresh);
1352 SHOW(rc_superres_kf_qthresh);
1354 SHOW(rc_target_bitrate);
1355 SHOW(rc_min_quantizer);
1356 SHOW(rc_max_quantizer);
1357 SHOW(rc_undershoot_pct);
1358 SHOW(rc_overshoot_pct);
1360 SHOW(rc_buf_initial_sz);
1361 SHOW(rc_buf_optimal_sz);
1362 SHOW(rc_2pass_vbr_bias_pct);
1363 SHOW(rc_2pass_vbr_minsection_pct);
1364 SHOW(rc_2pass_vbr_maxsection_pct);
1365 SHOW(fwd_kf_enabled);
1370#define SHOW_PARAMS(field) \
1371 fprintf(stderr, " %-28s = %d\n", #field, \
1372 stream->config.cfg.encoder_cfg.field)
1373 if (global->encoder_config.init_by_cfg_file) {
1374 SHOW_PARAMS(super_block_size);
1375 SHOW_PARAMS(max_partition_size);
1376 SHOW_PARAMS(min_partition_size);
1377 SHOW_PARAMS(disable_ab_partition_type);
1378 SHOW_PARAMS(disable_rect_partition_type);
1379 SHOW_PARAMS(disable_1to4_partition_type);
1380 SHOW_PARAMS(disable_flip_idtx);
1381 SHOW_PARAMS(disable_cdef);
1382 SHOW_PARAMS(disable_lr);
1383 SHOW_PARAMS(disable_obmc);
1384 SHOW_PARAMS(disable_warp_motion);
1385 SHOW_PARAMS(disable_global_motion);
1386 SHOW_PARAMS(disable_dist_wtd_comp);
1387 SHOW_PARAMS(disable_diff_wtd_comp);
1388 SHOW_PARAMS(disable_inter_intra_comp);
1389 SHOW_PARAMS(disable_masked_comp);
1390 SHOW_PARAMS(disable_one_sided_comp);
1391 SHOW_PARAMS(disable_palette);
1392 SHOW_PARAMS(disable_intrabc);
1393 SHOW_PARAMS(disable_cfl);
1394 SHOW_PARAMS(disable_smooth_intra);
1395 SHOW_PARAMS(disable_filter_intra);
1396 SHOW_PARAMS(disable_dual_filter);
1397 SHOW_PARAMS(disable_intra_angle_delta);
1398 SHOW_PARAMS(disable_intra_edge_filter);
1399 SHOW_PARAMS(disable_tx_64x64);
1400 SHOW_PARAMS(disable_smooth_inter_intra);
1401 SHOW_PARAMS(disable_inter_inter_wedge);
1402 SHOW_PARAMS(disable_inter_intra_wedge);
1403 SHOW_PARAMS(disable_paeth_intra);
1404 SHOW_PARAMS(disable_trellis_quant);
1405 SHOW_PARAMS(disable_ref_frame_mv);
1406 SHOW_PARAMS(reduced_reference_set);
1407 SHOW_PARAMS(reduced_tx_type_set);
1411static void open_output_file(
struct stream_state *stream,
1412 struct AvxEncoderConfig *global,
1413 const struct AvxRational *pixel_aspect_ratio,
1414 const char *encoder_settings) {
1415 const char *fn = stream->config.out_fn;
1420 stream->file = strcmp(fn,
"-") ? fopen(fn,
"wb") : set_binary_mode(stdout);
1422 if (!stream->file) fatal(
"Failed to open output file");
1424 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1425 fatal(
"WebM output to pipes not supported.");
1428 if (stream->config.write_webm) {
1429 stream->webm_ctx.stream = stream->file;
1430 if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1431 stream->config.stereo_fmt,
1432 get_fourcc_by_aom_encoder(global->codec),
1433 pixel_aspect_ratio, encoder_settings) != 0) {
1434 fatal(
"WebM writer initialization failed.");
1438 (void)pixel_aspect_ratio;
1439 (void)encoder_settings;
1442 if (!stream->config.write_webm && stream->config.write_ivf) {
1443 ivf_write_file_header(stream->file, cfg,
1444 get_fourcc_by_aom_encoder(global->codec), 0);
1448static void close_output_file(
struct stream_state *stream,
1449 unsigned int fourcc) {
1455 if (stream->config.write_webm) {
1456 if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1457 fatal(
"WebM writer finalization failed.");
1462 if (!stream->config.write_webm && stream->config.write_ivf) {
1463 if (!fseek(stream->file, 0, SEEK_SET))
1464 ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1465 stream->frames_out);
1468 fclose(stream->file);
1471static void setup_pass(
struct stream_state *stream,
1472 struct AvxEncoderConfig *global,
int pass) {
1473 if (stream->config.stats_fn) {
1474 if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1475 fatal(
"Failed to open statistics store");
1477 if (!stats_open_mem(&stream->stats, pass))
1478 fatal(
"Failed to open statistics store");
1481 if (global->passes == 1) {
1488 default: fatal(
"Failed to set pass");
1493 stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1496 stream->cx_time = 0;
1498 stream->frames_out = 0;
1501static void initialize_encoder(
struct stream_state *stream,
1502 struct AvxEncoderConfig *global) {
1512 ctx_exit_on_error(&stream->encoder,
"Failed to initialize encoder");
1514 for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1515 int ctrl = stream->config.arg_ctrls[i][0];
1516 int value = stream->config.arg_ctrls[i][1];
1518 fprintf(stderr,
"Error: Tried to set control %d = %d\n", ctrl, value);
1520 ctx_exit_on_error(&stream->encoder,
"Failed to control codec");
1523 for (i = 0; i < stream->config.arg_key_val_cnt; i++) {
1524 const char *name = stream->config.arg_key_vals[i][0];
1525 const char *val = stream->config.arg_key_vals[i][1];
1527 fprintf(stderr,
"Error: Tried to set option %s = %s\n", name, val);
1529 ctx_exit_on_error(&stream->encoder,
"Failed to set codec option");
1533 if (stream->config.vmaf_model_path) {
1535 stream->config.vmaf_model_path);
1536 ctx_exit_on_error(&stream->encoder,
"Failed to set vmaf model path");
1539 if (stream->config.partition_info_path) {
1542 stream->config.partition_info_path);
1543 ctx_exit_on_error(&stream->encoder,
"Failed to set partition info path");
1545 if (stream->config.enable_rate_guide_deltaq) {
1548 stream->config.enable_rate_guide_deltaq);
1549 ctx_exit_on_error(&stream->encoder,
"Failed to enable rate guide deltaq");
1551 if (stream->config.rate_distribution_info) {
1554 stream->config.rate_distribution_info);
1555 ctx_exit_on_error(&stream->encoder,
"Failed to set rate distribution info");
1558 if (stream->config.film_grain_filename) {
1560 stream->config.film_grain_filename);
1561 ctx_exit_on_error(&stream->encoder,
"Failed to set film grain table");
1564 stream->config.color_range);
1565 ctx_exit_on_error(&stream->encoder,
"Failed to set color range");
1567#if CONFIG_AV1_DECODER
1568 if (global->test_decode != TEST_DECODE_OFF) {
1570 get_short_name_by_aom_encoder(global->codec));
1574 if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
1576 stream->config.cfg.large_scale_tile);
1577 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_mode");
1580 stream->config.cfg.save_as_annexb);
1581 ctx_exit_on_error(&stream->decoder,
"Failed to set is_annexb");
1585 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_row");
1589 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_col");
1600static void convert_image_to_monochrome(
const struct aom_image *img,
1602 *monochrome_img = *img;
1615 monochrome_img->
sz = 0;
1622static void encode_frame(
struct stream_state *stream,
1623 struct AvxEncoderConfig *global,
struct aom_image *img,
1624 unsigned int frames_in) {
1627 struct aom_usec_timer timer;
1630 (cfg->
g_timebase.
den * (int64_t)(frames_in - 1) * global->framerate.den) /
1633 (cfg->
g_timebase.
den * (int64_t)(frames_in)*global->framerate.den) /
1641 fprintf(stderr,
"%s can only scale 4:2:0 inputs\n", exec_name);
1658 stream->img->stride[
AOM_PLANE_V] / 2, stream->img->d_w,
1659 stream->img->d_h, kFilterBox);
1662 stream->encoder.err = 1;
1663 ctx_exit_on_error(&stream->encoder,
1664 "Stream %d: Failed to encode frame.\n"
1665 "libyuv is required for scaling but is currently "
1667 "Be sure to specify -DCONFIG_LIBYUV=1 when running "
1673 if (img && (img->
d_w != cfg->
g_w || img->
d_h != cfg->
g_h)) {
1675 fprintf(stderr,
"%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1689 stream->img->d_w, stream->img->d_h, kFilterBox);
1692 stream->encoder.err = 1;
1693 ctx_exit_on_error(&stream->encoder,
1694 "Stream %d: Failed to encode frame.\n"
1695 "Scaling disabled in this configuration. \n"
1696 "To enable, configure with --enable-libyuv\n",
1703 convert_image_to_monochrome(img, &monochrome_img);
1704 img = &monochrome_img;
1707 aom_usec_timer_start(&timer);
1709 (uint32_t)(next_frame_start - frame_start), 0);
1710 aom_usec_timer_mark(&timer);
1711 stream->cx_time += aom_usec_timer_elapsed(&timer);
1712 ctx_exit_on_error(&stream->encoder,
"Stream %d: Failed to encode frame",
1716static void update_quantizer_histogram(
struct stream_state *stream) {
1722 ctx_exit_on_error(&stream->encoder,
"Failed to read quantizer");
1723 stream->counts[q]++;
1727static void get_cx_data(
struct stream_state *stream,
1728 struct AvxEncoderConfig *global,
int *got_data) {
1735 static size_t fsize = 0;
1736 static FileOffset ivf_header_pos = 0;
1738 switch (pkt->
kind) {
1740 ++stream->frames_out;
1742 fprintf(stderr,
" %6luF", (
unsigned long)pkt->
data.
frame.
sz);
1744 update_rate_histogram(stream->rate_hist, cfg, pkt);
1746 if (stream->config.write_webm) {
1747 if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
1748 fatal(
"WebM writer failed.");
1752 if (!stream->config.write_webm) {
1753 if (stream->config.write_ivf) {
1755 ivf_header_pos = ftello(stream->file);
1758 ivf_write_frame_header(stream->file, pkt->
data.
frame.
pts, fsize);
1762 const FileOffset currpos = ftello(stream->file);
1763 fseeko(stream->file, ivf_header_pos, SEEK_SET);
1764 ivf_write_frame_size(stream->file, fsize);
1765 fseeko(stream->file, currpos, SEEK_SET);
1775#if CONFIG_AV1_DECODER
1776 if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
1779 if (stream->decoder.err) {
1780 warn_or_exit_on_error(&stream->decoder,
1781 global->test_decode == TEST_DECODE_FATAL,
1782 "Failed to decode frame %d in stream %d",
1783 stream->frames_out + 1, stream->index);
1784 stream->mismatch_seen = stream->frames_out + 1;
1790 stream->frames_out++;
1797 if (global->show_psnr >= 1) {
1800 stream->psnr_sse_total[0] += pkt->
data.
psnr.sse[0];
1801 stream->psnr_samples_total[0] += pkt->
data.
psnr.samples[0];
1802 for (i = 0; i < 4; i++) {
1804 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr[i]);
1805 stream->psnr_totals[0][i] += pkt->
data.
psnr.psnr[i];
1807 stream->psnr_count[0]++;
1809#if CONFIG_AV1_HIGHBITDEPTH
1810 if (stream->config.cfg.g_input_bit_depth <
1811 (
unsigned int)stream->config.cfg.g_bit_depth) {
1812 stream->psnr_sse_total[1] += pkt->
data.
psnr.sse_hbd[0];
1813 stream->psnr_samples_total[1] += pkt->
data.
psnr.samples_hbd[0];
1814 for (i = 0; i < 4; i++) {
1816 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr_hbd[i]);
1817 stream->psnr_totals[1][i] += pkt->
data.
psnr.psnr_hbd[i];
1819 stream->psnr_count[1]++;
1830static void show_psnr(
struct stream_state *stream,
double peak, int64_t bps) {
1834 if (!stream->psnr_count[0])
return;
1836 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1837 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[0], peak,
1838 (
double)stream->psnr_sse_total[0]);
1839 fprintf(stderr,
" %.3f", ovpsnr);
1841 for (i = 0; i < 4; i++) {
1842 fprintf(stderr,
" %.3f", stream->psnr_totals[0][i] / stream->psnr_count[0]);
1845 fprintf(stderr,
" %7" PRId64
" bps", bps);
1847 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1848 fprintf(stderr,
"\n");
1851#if CONFIG_AV1_HIGHBITDEPTH
1852static void show_psnr_hbd(
struct stream_state *stream,
double peak,
1857 if (!stream->psnr_count[1])
return;
1859 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1860 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[1], peak,
1861 (
double)stream->psnr_sse_total[1]);
1862 fprintf(stderr,
" %.3f", ovpsnr);
1864 for (i = 0; i < 4; i++) {
1865 fprintf(stderr,
" %.3f", stream->psnr_totals[1][i] / stream->psnr_count[1]);
1868 fprintf(stderr,
" %7" PRId64
" bps", bps);
1870 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1871 fprintf(stderr,
"\n");
1875static float usec_to_fps(uint64_t usec,
unsigned int frames) {
1876 return (
float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
1879static void test_decode(
struct stream_state *stream,
1880 enum TestDecodeFatality fatal) {
1883 if (stream->mismatch_seen)
return;
1896 enc_img.
d_w, enc_img.
d_h, 16);
1897 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1898 enc_img = enc_hbd_img;
1903 dec_img.
d_w, dec_img.
d_h, 16);
1904 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1905 dec_img = dec_hbd_img;
1909 ctx_exit_on_error(&stream->encoder,
"Failed to get encoder reference frame");
1910 ctx_exit_on_error(&stream->decoder,
"Failed to get decoder reference frame");
1912 if (!aom_compare_img(&enc_img, &dec_img)) {
1913 int y[4], u[4], v[4];
1915 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1917 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1919 stream->decoder.err = 1;
1920 warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
1921 "Stream %d: Encode/decode mismatch on frame %d at"
1922 " Y[%d, %d] {%d/%d},"
1923 " U[%d, %d] {%d/%d},"
1924 " V[%d, %d] {%d/%d}",
1925 stream->index, stream->frames_out, y[0], y[1], y[2],
1926 y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
1927 stream->mismatch_seen = stream->frames_out;
1934static void print_time(
const char *label, int64_t etl) {
1941 etl -= hours * 3600;
1946 fprintf(stderr,
"[%3s %2" PRId64
":%02" PRId64
":%02" PRId64
"] ", label,
1949 fprintf(stderr,
"[%3s unknown] ", label);
1953static void clear_stream_count_state(
struct stream_state *stream) {
1955 for (
int k = 0; k < 2; k++) {
1956 stream->psnr_sse_total[k] = 0;
1957 stream->psnr_samples_total[k] = 0;
1958 for (
int i = 0; i < 4; i++) {
1959 stream->psnr_totals[k][i] = 0;
1961 stream->psnr_count[k] = 0;
1964 memset(stream->counts, 0,
sizeof(stream->counts));
1973static int pass_need_downscale(
int global_pass,
int global_passes,
int pass) {
1974 return !global_pass && global_passes > 2 && pass == 1;
1977int main(
int argc,
const char **argv_) {
1981 int allocated_raw_shift = 0;
1982 int do_16bit_internal = 0;
1983 int input_shift = 0;
1984 int frame_avail, got_data;
1986 struct AvxInputContext input;
1987 struct AvxEncoderConfig global;
1988 struct stream_state *streams = NULL;
1989 char **argv, **argi;
1990 uint64_t cx_time = 0;
1993 int profile_updated = 0;
1995 memset(&input, 0,
sizeof(input));
1996 memset(&raw, 0,
sizeof(raw));
1997 exec_name = argv_[0];
2000 input.framerate.numerator = 30;
2001 input.framerate.denominator = 1;
2002 input.only_i420 = 1;
2003 input.bit_depth = 0;
2009 argv = argv_dup(argc - 1, argv_ + 1);
2011 fprintf(stderr,
"Error allocating argument list\n");
2012 return EXIT_FAILURE;
2014 parse_global_config(&global, &argv);
2016 if (argc < 2) usage_exit();
2018 switch (global.color_type) {
2031 struct stream_state *stream = NULL;
2034 stream = new_stream(&global, stream);
2036 if (!streams) streams = stream;
2037 }
while (parse_stream_params(&global, stream, argv));
2041 for (argi = argv; *argi; argi++)
2042 if (argi[0][0] ==
'-' && argi[0][1])
2043 die(
"Error: Unrecognized option %s\n", *argi);
2045 FOREACH_STREAM(stream, streams) {
2046 check_encoder_config(global.disable_warning_prompt, &global,
2047 &stream->config.cfg);
2050 if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
2051 die(
"only support ivf output format while large-scale-tile=1\n");
2055 input.filename = argv[0];
2056 const char *orig_input_filename = input.filename;
2057 FOREACH_STREAM(stream, streams) {
2058 stream->orig_out_fn = stream->config.out_fn;
2059 stream->orig_width = stream->config.cfg.g_w;
2060 stream->orig_height = stream->config.cfg.g_h;
2061 stream->orig_write_ivf = stream->config.write_ivf;
2062 stream->orig_write_webm = stream->config.write_webm;
2065 if (!input.filename) {
2066 fprintf(stderr,
"No input file specified!\n");
2071 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC)
2072 input.only_i420 = 0;
2074 for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
2076 FOREACH_STREAM(stream, streams) { clear_stream_count_state(stream); }
2079 int frames_in = 0, seen_frames = 0;
2080 int64_t estimated_time_left = -1;
2081 int64_t average_rate = -1;
2082 int64_t lagged_count = 0;
2083 const int need_downscale =
2084 pass_need_downscale(global.pass, global.passes, pass);
2088 FOREACH_STREAM(stream, streams) {
2089 if (need_downscale) {
2090 stream->config.out_fn = stream->config.two_pass_output;
2092 stream->config.write_ivf = 1;
2093 stream->config.write_webm = 0;
2095 stream->config.out_fn = stream->orig_out_fn;
2096 stream->config.write_ivf = stream->orig_write_ivf;
2097 stream->config.write_webm = stream->orig_write_webm;
2099 stream->config.cfg.g_w = stream->orig_width;
2100 stream->config.cfg.g_h = stream->orig_height;
2106 input.filename = orig_input_filename;
2107 const char *two_pass_input = NULL;
2108 if (need_downscale) {
2109 FOREACH_STREAM(stream, streams) {
2110 if (stream->config.two_pass_input) {
2111 two_pass_input = stream->config.two_pass_input;
2112 input.filename = two_pass_input;
2118 open_input_file(&input, global.csp);
2123 if (!input.width || !input.height) {
2124 if (two_pass_input) {
2125 FOREACH_STREAM(stream, streams) {
2126 if (stream->config.two_pass_width && stream->config.two_pass_height) {
2127 input.width = stream->config.two_pass_width;
2128 input.height = stream->config.two_pass_height;
2133 FOREACH_STREAM(stream, streams) {
2134 if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
2135 input.width = stream->config.cfg.g_w;
2136 input.height = stream->config.cfg.g_h;
2144 if (!input.width || !input.height) {
2145 if (two_pass_input) {
2147 "Specify downscaled stream dimensions with --two-pass-width "
2148 " and --two-pass-height");
2151 "Specify stream dimensions with --width (-w) "
2152 " and --height (-h)");
2156 if (need_downscale) {
2157 FOREACH_STREAM(stream, streams) {
2158 if (stream->config.two_pass_width && stream->config.two_pass_height) {
2159 stream->config.cfg.g_w = stream->config.two_pass_width;
2160 stream->config.cfg.g_h = stream->config.two_pass_height;
2161 }
else if (two_pass_input) {
2162 stream->config.cfg.g_w = input.width;
2163 stream->config.cfg.g_h = input.height;
2164 }
else if (stream->orig_width && stream->orig_height) {
2165#if CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL
2166 stream->config.cfg.g_w = stream->orig_width;
2167 stream->config.cfg.g_h = stream->orig_height;
2169 stream->config.cfg.g_w = (stream->orig_width + 1) / 2;
2170 stream->config.cfg.g_h = (stream->orig_height + 1) / 2;
2173#if CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL
2174 stream->config.cfg.g_w = input.width;
2175 stream->config.cfg.g_h = input.height;
2177 stream->config.cfg.g_w = (input.width + 1) / 2;
2178 stream->config.cfg.g_h = (input.height + 1) / 2;
2189 if (!input.bit_depth) {
2190 FOREACH_STREAM(stream, streams) {
2191 if (stream->config.cfg.g_input_bit_depth)
2192 input.bit_depth = stream->config.cfg.g_input_bit_depth;
2194 input.bit_depth = stream->config.cfg.g_input_bit_depth =
2195 (int)stream->config.cfg.g_bit_depth;
2199 FOREACH_STREAM(stream, streams) {
2200 stream->config.cfg.g_input_bit_depth = input.bit_depth;
2204 FOREACH_STREAM(stream, streams) {
2209 switch (stream->config.cfg.g_profile) {
2213 if (!stream->config.cfg.monochrome) {
2214 stream->config.cfg.g_profile = 1;
2215 profile_updated = 1;
2217 }
else if (input.bit_depth == 12 ||
2220 !stream->config.cfg.monochrome)) {
2221 stream->config.cfg.g_profile = 2;
2222 profile_updated = 1;
2228 stream->config.cfg.g_profile = 2;
2229 profile_updated = 1;
2230 }
else if (input.bit_depth < 12 &&
2233 stream->config.cfg.g_profile = 0;
2234 profile_updated = 1;
2240 stream->config.cfg.g_profile = 1;
2241 profile_updated = 1;
2242 }
else if (input.bit_depth < 12 &&
2245 stream->config.cfg.g_profile = 0;
2246 profile_updated = 1;
2247 }
else if (input.bit_depth == 12 &&
2248 input.file_type == FILE_TYPE_Y4M) {
2253 input.y4m.dst_c_dec_h >> 1);
2254 ctx_exit_on_error(&stream->encoder,
2255 "Failed to set chroma subsampling x");
2258 input.y4m.dst_c_dec_v >> 1);
2259 ctx_exit_on_error(&stream->encoder,
2260 "Failed to set chroma subsampling y");
2261 }
else if (input.bit_depth == 12 &&
2262 input.file_type == FILE_TYPE_RAW) {
2265 stream->chroma_subsampling_x);
2266 ctx_exit_on_error(&stream->encoder,
2267 "Failed to set chroma subsampling x");
2270 stream->chroma_subsampling_y);
2271 ctx_exit_on_error(&stream->encoder,
2272 "Failed to set chroma subsampling y");
2280 if (stream->config.cfg.g_input_bit_depth >
2281 (
unsigned int)stream->config.cfg.g_bit_depth) {
2282 stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
2283 if (!global.quiet) {
2285 "Warning: automatically updating bit depth to %d to "
2286 "match input format.\n",
2287 stream->config.cfg.g_input_bit_depth);
2290#if !CONFIG_AV1_HIGHBITDEPTH
2291 if (stream->config.cfg.g_bit_depth > 8) {
2292 fatal(
"Unsupported bit-depth with CONFIG_AV1_HIGHBITDEPTH=0\n");
2295 if (stream->config.cfg.g_bit_depth > 10) {
2296 switch (stream->config.cfg.g_profile) {
2299 stream->config.cfg.g_profile = 2;
2300 profile_updated = 1;
2305 if (stream->config.cfg.g_bit_depth > 8) {
2306 stream->config.use_16bit_internal = 1;
2308 if (profile_updated && !global.quiet) {
2310 "Warning: automatically updating to profile %d to "
2311 "match input format.\n",
2312 stream->config.cfg.g_profile);
2314 if ((global.show_psnr == 2) && (stream->config.cfg.g_input_bit_depth ==
2315 stream->config.cfg.g_bit_depth)) {
2317 "Warning: --psnr==2 and --psnr==1 will provide same "
2318 "results when input bit-depth == stream bit-depth, "
2319 "falling back to default psnr value\n");
2320 global.show_psnr = 1;
2322 if (global.show_psnr < 0 || global.show_psnr > 2) {
2324 "Warning: --psnr can take only 0,1,2 as values,"
2325 "falling back to default psnr value\n");
2326 global.show_psnr = 1;
2329 stream->config.cfg.g_limit = global.limit;
2332 FOREACH_STREAM(stream, streams) {
2333 set_stream_dimensions(stream, input.width, input.height);
2334 stream->config.color_range = input.color_range;
2336 FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
2341 if (global.pass > 0 && global.pass <= 3 && global.passes >= 2) {
2342 FOREACH_STREAM(stream, streams) {
2343 if (!stream->config.stats_fn)
2344 die(
"Stream %d: Must specify --fpf when --pass=%d"
2345 " and --passes=%d\n",
2346 stream->index, global.pass, global.passes);
2351 FOREACH_STREAM(stream, streams) {
2352 if (stream->config.write_webm) {
2353 stream->config.write_webm = 0;
2354 stream->config.write_ivf = 0;
2355 aom_tools_warn(
"aomenc compiled w/o WebM support. Writing OBU stream.");
2363 if (!global.have_framerate) {
2364 global.framerate.num = input.framerate.numerator;
2365 global.framerate.den = input.framerate.denominator;
2367 FOREACH_STREAM(stream, streams) {
2368 stream->config.cfg.g_timebase.den = global.framerate.num;
2369 stream->config.cfg.g_timebase.num = global.framerate.den;
2372 if (global.verbose && pass == 0) {
2373 FOREACH_STREAM(stream, streams) {
2374 show_stream_config(stream, &global, &input);
2378 if (pass == (global.pass ? global.pass - 1 : 0)) {
2380 if (input.file_type != FILE_TYPE_Y4M) {
2381 aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2383 FOREACH_STREAM(stream, streams) {
2385 init_rate_histogram(&stream->config.cfg, &global.framerate);
2389 FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2390 FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2391 FOREACH_STREAM(stream, streams) {
2392 char *encoder_settings = NULL;
2401 if (stream->config.write_webm && !stream->webm_ctx.debug) {
2402 encoder_settings = extract_encoder_settings(
2404 if (encoder_settings == NULL) {
2407 "Warning: unable to extract encoder settings. Continuing...\n");
2411 open_output_file(stream, &global, &input.pixel_aspect_ratio,
2413 free(encoder_settings);
2416 if (strcmp(get_short_name_by_aom_encoder(global.codec),
"av1") == 0) {
2420 FOREACH_STREAM(stream, streams) {
2421 if (stream->config.use_16bit_internal) {
2422 do_16bit_internal = 1;
2424 input_shift = (int)stream->config.cfg.g_bit_depth -
2425 stream->config.cfg.g_input_bit_depth;
2432 while (frame_avail || got_data) {
2433 struct aom_usec_timer timer;
2435 if (!global.limit || frames_in < global.limit) {
2436 frame_avail = read_frame(&input, &raw);
2438 if (frame_avail) frames_in++;
2440 frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2442 if (!global.quiet) {
2443 float fps = usec_to_fps(cx_time, seen_frames);
2444 fprintf(stderr,
"\rPass %d/%d ", pass + 1, global.passes);
2446 if (stream_cnt == 1)
2447 fprintf(stderr,
"frame %4d/%-4d %7" PRId64
"B ", frames_in,
2448 streams->frames_out, (int64_t)streams->nbytes);
2450 fprintf(stderr,
"frame %4d ", frames_in);
2452 fprintf(stderr,
"%7" PRId64
" %s %.2f %s ",
2453 cx_time > 9999999 ? cx_time / 1000 : cx_time,
2454 cx_time > 9999999 ?
"ms" :
"us", fps >= 1.0 ? fps : fps * 60,
2455 fps >= 1.0 ?
"fps" :
"fpm");
2456 print_time(
"ETA", estimated_time_left);
2468 if (frames_in > global.skip_frames) {
2470 if (input_shift || (do_16bit_internal && input.bit_depth == 8)) {
2471 assert(do_16bit_internal);
2474 if (!allocated_raw_shift) {
2476 input.width, input.height, 32);
2477 allocated_raw_shift = 1;
2479 aom_img_upshift(&raw_shift, &raw, input_shift);
2480 frame_to_encode = &raw_shift;
2482 frame_to_encode = &raw;
2484 aom_usec_timer_start(&timer);
2485 if (do_16bit_internal) {
2487 FOREACH_STREAM(stream, streams) {
2488 if (stream->config.use_16bit_internal)
2489 encode_frame(stream, &global,
2490 frame_avail ? frame_to_encode : NULL, frames_in);
2496 FOREACH_STREAM(stream, streams) {
2497 encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2501 aom_usec_timer_mark(&timer);
2502 cx_time += aom_usec_timer_elapsed(&timer);
2504 FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2507 FOREACH_STREAM(stream, streams) {
2508 get_cx_data(stream, &global, &got_data);
2511 if (!got_data && input.length && streams != NULL &&
2512 !streams->frames_out) {
2513 lagged_count = global.limit ? seen_frames : ftello(input.file);
2514 }
else if (input.length) {
2519 const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2521 rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2522 remaining = 1000 * (global.limit - global.skip_frames -
2523 seen_frames + lagged_count);
2525 const int64_t input_pos = ftello(input.file);
2526 const int64_t input_pos_lagged = input_pos - lagged_count;
2527 const int64_t input_limit = input.length;
2529 rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2530 remaining = input_limit - input_pos + lagged_count;
2534 (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2535 estimated_time_left = average_rate ? remaining / average_rate : -1;
2538 if (got_data && global.test_decode != TEST_DECODE_OFF) {
2539 FOREACH_STREAM(stream, streams) {
2540 test_decode(stream, global.test_decode);
2546 if (!global.quiet) fprintf(stderr,
"\033[K");
2549 if (stream_cnt > 1) fprintf(stderr,
"\n");
2551 if (!global.quiet) {
2552 FOREACH_STREAM(stream, streams) {
2554 seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2555 const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2557 "\rPass %d/%d frame %4d/%-4d %7" PRId64
"B %7" PRId64
2560 " %7" PRId64
" %s (%.2f fps)\033[K\n",
2561 pass + 1, global.passes, frames_in, stream->frames_out,
2562 (int64_t)stream->nbytes, bpf, bps,
2563 stream->cx_time > 9999999 ? stream->cx_time / 1000
2565 stream->cx_time > 9999999 ?
"ms" :
"us",
2566 usec_to_fps(stream->cx_time, seen_frames));
2572 if (global.show_psnr >= 1) {
2573 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) {
2574 FOREACH_STREAM(stream, streams) {
2576 if (global.show_psnr == 1) {
2577 if (stream->psnr_count[0] && seen_frames && global.framerate.den) {
2578 bps = (int64_t)stream->nbytes * 8 *
2579 (int64_t)global.framerate.num / global.framerate.den /
2582 show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2585 if (global.show_psnr == 2) {
2586#if CONFIG_AV1_HIGHBITDEPTH
2587 if (stream->config.cfg.g_input_bit_depth <
2588 (
unsigned int)stream->config.cfg.g_bit_depth)
2589 show_psnr_hbd(stream, (1 << stream->config.cfg.g_bit_depth) - 1,
2595 FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2599 if (pass == global.passes - 1) {
2600 FOREACH_STREAM(stream, streams) {
2601 int num_operating_points;
2603 int target_levels[32];
2605 &num_operating_points);
2610 for (
int i = 0; i < num_operating_points; i++) {
2611 if (levels[i] > target_levels[i]) {
2612 if (levels[i] == 31) {
2614 "Failed to encode to target level %d.%d for operating point "
2615 "%d. The output level is SEQ_LEVEL_MAX",
2616 2 + (target_levels[i] >> 2), target_levels[i] & 3, i);
2619 "Failed to encode to target level %d.%d for operating point "
2620 "%d. The output level is %d.%d",
2621 2 + (target_levels[i] >> 2), target_levels[i] & 3, i,
2622 2 + (levels[i] >> 2), levels[i] & 3);
2631 if (global.test_decode != TEST_DECODE_OFF) {
2635 close_input_file(&input);
2637 if (global.test_decode == TEST_DECODE_FATAL) {
2638 FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2640 FOREACH_STREAM(stream, streams) {
2641 close_output_file(stream, get_fourcc_by_aom_encoder(global.codec));
2644 FOREACH_STREAM(stream, streams) {
2645 stats_close(&stream->stats, global.passes - 1);
2648 if (global.pass)
break;
2651 if (global.show_q_hist_buckets) {
2652 FOREACH_STREAM(stream, streams) {
2653 show_q_histogram(stream->counts, global.show_q_hist_buckets);
2657 if (global.show_rate_hist_buckets) {
2658 FOREACH_STREAM(stream, streams) {
2659 show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2660 global.show_rate_hist_buckets);
2663 FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2665#if CONFIG_INTERNAL_STATS
2669 if (!(global.pass == 1 && global.passes == 2)) {
2670 FOREACH_STREAM(stream, streams) {
2671 FILE *f = fopen(
"opsnr.stt",
"a");
2672 if (stream->mismatch_seen) {
2673 fprintf(f,
"First mismatch occurred in frame %d\n",
2674 stream->mismatch_seen);
2676 fprintf(f,
"No mismatch detected in recon buffers\n");
2687 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:861
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition aom_encoder.h:874
#define AOM_PLANE_U
Definition aom_image.h:211
@ AOM_CSP_UNKNOWN
Definition aom_image.h:143
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_PLANE_Y
Definition aom_image.h:210
#define AOM_PLANE_V
Definition aom_image.h:212
enum aom_color_range aom_color_range_t
List of supported color range.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition aom_image.h:38
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
@ AOM_IMG_FMT_I42216
Definition aom_image.h:58
@ AOM_IMG_FMT_I42016
Definition aom_image.h:56
@ 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:59
@ AOM_IMG_FMT_I420
Definition aom_image.h:45
@ AOM_IMG_FMT_NV12
Definition aom_image.h:54
@ AOM_IMG_FMT_YV12
Definition aom_image.h:43
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, unsigned int parameter.
Definition aomdx.h:316
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition aomdx.h:352
@ AV1_SET_DECODE_TILE_ROW
Codec control function to set the range of tile decoding, int parameter.
Definition aomdx.h:307
@ AV1E_SET_MATRIX_COEFFICIENTS
Codec control function to set transfer function info, int parameter.
Definition aomcx.h:573
@ AV1E_SET_ENABLE_INTERINTER_WEDGE
Codec control function to turn on / off interinter wedge compound, int parameter.
Definition aomcx.h:1010
@ AV1E_SET_ENABLE_DIAGONAL_INTRA
Codec control function to turn on / off D45 to D203 intra mode usage, int parameter.
Definition aomcx.h:1348
@ AV1E_SET_MAX_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition aomcx.h:594
@ AV1E_SET_ROW_MT
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition aomcx.h:361
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition aomcx.h:1070
@ AOME_SET_SHARPNESS
Codec control function to set the sharpness parameter, unsigned int parameter.
Definition aomcx.h:241
@ AV1E_GET_TARGET_SEQ_LEVEL_IDX
Codec control function to get the target sequence level index for each operating point....
Definition aomcx.h:1455
@ AV1E_SET_RATE_DISTRIBUTION_INFO
Codec control to set the input file for rate distribution used in all intra mode, const char * parame...
Definition aomcx.h:1514
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition aomcx.h:408
@ AOME_GET_LAST_QUANTIZER_64
Codec control function to get last quantizer chosen by the encoder, int* parameter.
Definition aomcx.h:263
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition aomcx.h:468
@ AV1E_SET_REDUCED_REFERENCE_SET
Control to use reduced set of single and compound references, int parameter.
Definition aomcx.h:1224
@ AV1E_GET_NUM_OPERATING_POINTS
Codec control function to get the number of operating points. int* parameter.
Definition aomcx.h:1460
@ AV1E_SET_GF_MIN_PYRAMID_HEIGHT
Control to select minimum height for the GF group pyramid structure, unsigned int parameter.
Definition aomcx.h:1320
@ AV1E_SET_ENABLE_PAETH_INTRA
Codec control function to turn on / off Paeth intra mode usage, int parameter.
Definition aomcx.h:1078
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition aomcx.h:497
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition aomcx.h:506
@ AV1E_SET_CHROMA_SUBSAMPLING_X
Sets the chroma subsampling x value, unsigned int parameter.
Definition aomcx.h:1187
@ AV1E_SET_COLOR_RANGE
Codec control function to set color range bit, int parameter.
Definition aomcx.h:606
@ AV1E_SET_ENABLE_RESTORATION
Codec control function to encode with Loop Restoration Filter, unsigned int parameter.
Definition aomcx.h:680
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition aomcx.h:1117
@ AV1E_SET_MIN_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition aomcx.h:587
@ AOME_SET_ARNR_MAXFRAMES
Codec control function to set the max no of frames to create arf, unsigned int parameter.
Definition aomcx.h:268
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition aomcx.h:1254
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition aomcx.h:1203
@ AV1E_SET_TRANSFER_CHARACTERISTICS
Codec control function to set transfer function info, int parameter.
Definition aomcx.h:552
@ AV1E_SET_MTU
Codec control function to set an MTU size for a tile group, unsigned int parameter.
Definition aomcx.h:800
@ AV1E_SET_DISABLE_TRELLIS_QUANT
Codec control function to encode without trellis quantization, unsigned int parameter.
Definition aomcx.h:707
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition aomcx.h:1113
@ AV1E_SET_ENABLE_AB_PARTITIONS
Codec control function to enable/disable AB partitions, int parameter.
Definition aomcx.h:818
@ AV1E_SET_ENABLE_INTERINTRA_COMP
Codec control function to turn on / off interintra compound for a sequence, int parameter.
Definition aomcx.h:986
@ 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:1173
@ AV1E_SET_ENABLE_CHROMA_DELTAQ
Codec control function to turn on / off delta quantization in chroma planes for a sequence,...
Definition aomcx.h:962
@ AV1E_SET_ENABLE_DUAL_FILTER
Codec control function to turn on / off dual interpolation filter for a sequence, int parameter.
Definition aomcx.h:954
@ AV1E_SET_FRAME_PARALLEL_DECODING
Codec control function to enable frame parallel decoding feature, unsigned int parameter.
Definition aomcx.h:431
@ AV1E_SET_MIN_PARTITION_SIZE
Codec control function to set min partition size, int parameter.
Definition aomcx.h:837
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition aomcx.h:1038
@ AV1E_SET_FORCE_VIDEO_MODE
Codec control function to force video mode, unsigned int parameter.
Definition aomcx.h:687
@ AV1E_SET_CHROMA_SUBSAMPLING_Y
Sets the chroma subsampling y value, unsigned int parameter.
Definition aomcx.h:1190
@ AV1E_SET_ENABLE_INTRA_EDGE_FILTER
Codec control function to turn on / off intra edge filter at sequence level, int parameter.
Definition aomcx.h:856
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition aomcx.h:1234
@ AV1E_SET_ENABLE_DIRECTIONAL_INTRA
Codec control function to turn on / off directional intra mode usage, int parameter.
Definition aomcx.h:1377
@ AV1E_SET_MAX_INTER_BITRATE_PCT
Codec control function to set max data rate for inter frames, unsigned int parameter.
Definition aomcx.h:325
@ AV1E_SET_DENOISE_NOISE_LEVEL
Sets the noise level, int parameter.
Definition aomcx.h:1181
@ AV1E_SET_INTRA_DCT_ONLY
Control to use dct only for intra modes, int parameter.
Definition aomcx.h:1196
@ AV1E_SET_TILE_ROWS
Codec control function to set number of tile rows, unsigned int parameter.
Definition aomcx.h:398
@ AV1E_SET_ENABLE_REF_FRAME_MVS
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level,...
Definition aomcx.h:935
@ AV1E_SET_FP_MT
Codec control function to enable frame parallel multi-threading of the encoder, unsigned int paramete...
Definition aomcx.h:1435
@ 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:970
@ 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:1325
@ AV1E_SET_GF_MAX_PYRAMID_HEIGHT
Control to select maximum height for the GF group pyramid structure, unsigned int parameter.
Definition aomcx.h:1213
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition aomcx.h:670
@ AV1E_SET_ENABLE_FLIP_IDTX
Codec control function to turn on / off flip and identity transforms, int parameter.
Definition aomcx.h:900
@ AV1E_GET_SEQ_LEVEL_IDX
Codec control function to get sequence level index for each operating point. int* parameter....
Definition aomcx.h:643
@ AV1E_SET_FRAME_PERIODIC_BOOST
Codec control function to enable/disable periodic Q boost, unsigned int parameter.
Definition aomcx.h:480
@ AV1E_SET_DV_COST_UPD_FREQ
Control to set frequency of the cost updates for intrabc motion vectors, unsigned int parameter.
Definition aomcx.h:1358
@ AV1E_SET_AUTO_INTRA_TOOLS_OFF
Codec control to automatically turn off several intra coding tools, unsigned int parameter.
Definition aomcx.h:1419
@ AV1E_SET_ENABLE_RECT_TX
Codec control function to turn on / off rectangular transforms, int parameter.
Definition aomcx.h:912
@ 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:924
@ 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:1166
@ AV1E_SET_SUPERBLOCK_SIZE
Codec control function to set intended superblock size, unsigned int parameter.
Definition aomcx.h:651
@ 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:1262
@ AV1E_SET_ENABLE_INTERINTRA_WEDGE
Codec control function to turn on / off interintra wedge compound, int parameter.
Definition aomcx.h:1018
@ AV1E_SET_NOISE_SENSITIVITY
Codec control function to set noise sensitivity, unsigned int parameter.
Definition aomcx.h:488
@ AV1E_SET_ENABLE_DIFF_WTD_COMP
Codec control function to turn on / off difference weighted compound, int parameter.
Definition aomcx.h:1002
@ AV1E_SET_QUANT_B_ADAPT
Control to use adaptive quantize_b, int parameter.
Definition aomcx.h:1206
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition aomcx.h:1059
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition aomcx.h:1109
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition aomcx.h:1088
@ AV1E_SET_ENABLE_KEYFRAME_FILTERING
Codec control function to enable temporal filtering on key frame, unsigned int parameter.
Definition aomcx.h:417
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition aomcx.h:789
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition aomcx.h:306
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition aomcx.h:442
@ AV1E_SET_ENABLE_SMOOTH_INTERINTRA
Codec control function to turn on / off smooth inter-intra mode for a sequence, int parameter.
Definition aomcx.h:994
@ AOME_SET_STATIC_THRESHOLD
Codec control function to set the threshold for MBs treated static, unsigned int parameter.
Definition aomcx.h:246
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition aomcx.h:697
@ AV1E_SET_PARTITION_INFO_PATH
Codec control to set the path for partition stats read and write. const char * parameter.
Definition aomcx.h:1363
@ AV1E_SET_MAX_PARTITION_SIZE
Codec control function to set max partition size, int parameter.
Definition aomcx.h:848
@ AV1E_SET_ENABLE_1TO4_PARTITIONS
Codec control function to enable/disable 1:4 and 4:1 partitions, int parameter.
Definition aomcx.h:826
@ AV1E_SET_DELTALF_MODE
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled,...
Definition aomcx.h:1139
@ AV1E_SET_ENABLE_TX64
Codec control function to turn on / off 64-length transforms, int parameter.
Definition aomcx.h:876
@ AOME_SET_TUNING
Codec control function to set visual tuning, aom_tune_metric (int) parameter.
Definition aomcx.h:282
@ 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:636
@ 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:580
@ AV1E_SET_REDUCED_TX_TYPE_SET
Control to use a reduced tx type set, int parameter.
Definition aomcx.h:1193
@ AV1E_SET_DELTAQ_STRENGTH
Set –deltaq-mode strength.
Definition aomcx.h:1398
@ AV1E_SET_INTER_DCT_ONLY
Control to use dct only for inter modes, int parameter.
Definition aomcx.h:1199
@ AV1E_SET_LOOPFILTER_CONTROL
Codec control to control loop filter.
Definition aomcx.h:1407
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition aomcx.h:228
@ AV1E_ENABLE_RATE_GUIDE_DELTAQ
Codec control to enable the rate distribution guided delta quantization in all intra mode,...
Definition aomcx.h:1502
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition aomcx.h:380
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition aomcx.h:865
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition aomcx.h:1131
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition aomcx.h:1028
@ AV1E_SET_FILM_GRAIN_TABLE
Codec control function to set the path to the film grain parameters, const char* parameter.
Definition aomcx.h:1178
@ AV1E_SET_QM_MAX
Codec control function to set the max quant matrix flatness, unsigned int parameter.
Definition aomcx.h:743
@ AV1E_SET_MAX_REFERENCE_FRAMES
Control to select maximum reference frames allowed per frame, int parameter.
Definition aomcx.h:1220
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:220
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition aomcx.h:339
@ AV1E_SET_ENABLE_ONESIDED_COMP
Codec control function to turn on / off one sided compound usage for a sequence, int parameter.
Definition aomcx.h:978
@ AV1E_SET_DENOISE_BLOCK_SIZE
Sets the denoisers block size, unsigned int parameter.
Definition aomcx.h:1184
@ 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:1292
@ AV1E_SET_QM_MIN
Codec control function to set the min quant matrix flatness, unsigned int parameter.
Definition aomcx.h:731
@ AV1E_SET_ENABLE_QM
Codec control function to encode with quantisation matrices, unsigned int parameter.
Definition aomcx.h:718
@ AV1E_SET_ENABLE_OVERLAY
Codec control function to turn on / off overlay frames for filtered ALTREF frames,...
Definition aomcx.h:1106
@ AV1E_SET_ENABLE_RECT_PARTITIONS
Codec control function to enable/disable rectangular partitions, int parameter.
Definition aomcx.h:810
@ AV1E_SET_COLOR_PRIMARIES
Codec control function to set color space info, int parameter.
Definition aomcx.h:527
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition aomcx.h:292
@ AV1E_SET_ENABLE_TX_SIZE_SEARCH
Control to turn on / off transform size search. Note: it can not work with non RD pick mode in real-t...
Definition aomcx.h:1387
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition aomcx.h:1244
@ AV1E_SET_MIN_CR
Control to set minimum compression ratio, unsigned int parameter Take integer values....
Definition aomcx.h:1269
@ AV1E_SET_LOSSLESS
Codec control function to set lossless encoding mode, unsigned int parameter.
Definition aomcx.h:353
@ AOME_SET_ARNR_STRENGTH
Codec control function to set the filter strength for the arf, unsigned int parameter.
Definition aomcx.h:273
@ 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 struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:254
const char * aom_codec_version_str(void)
Return the version information (as a string)
aom_codec_err_t aom_codec_set_option(aom_codec_ctx_t *ctx, const char *name, const char *value)
Key & Value API.
const char * aom_codec_error(const aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
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.
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
aom_codec_err_t
Algorithm return codes.
Definition aom_codec.h:155
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition aom_codec.h:525
const char * aom_codec_error_detail(const aom_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
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:1009
#define AOM_USAGE_ALL_INTRA
usage parameter analogous to AV1 all intra mode.
Definition aom_encoder.h:1013
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_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:938
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:1011
#define AOM_CODEC_USE_HIGHBITDEPTH
Definition aom_encoder.h:80
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition aom_encoder.h:79
@ AOM_RC_ONE_PASS
Definition aom_encoder.h:175
@ AOM_RC_SECOND_PASS
Definition aom_encoder.h:177
@ AOM_RC_THIRD_PASS
Definition aom_encoder.h:178
@ AOM_RC_FIRST_PASS
Definition aom_encoder.h:176
@ AOM_KF_DISABLED
Definition aom_encoder.h:201
@ AOM_CODEC_PSNR_PKT
Definition aom_encoder.h:111
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:108
@ AOM_CODEC_STATS_PKT
Definition aom_encoder.h:109
Codec context structure.
Definition aom_codec.h:298
Encoder output packet.
Definition aom_encoder.h:120
size_t sz
Definition aom_encoder.h:125
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:121
double psnr[4]
Definition aom_encoder.h:143
aom_fixed_buf_t twopass_stats
Definition aom_encoder.h:138
aom_fixed_buf_t raw
Definition aom_encoder.h:154
union aom_codec_cx_pkt::@1 data
aom_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition aom_encoder.h:127
struct aom_codec_cx_pkt::@1::@2 frame
int partition_id
the partition id defines the decoding order of the partitions. Only applicable when "output partition...
Definition aom_encoder.h:134
void * buf
Definition aom_encoder.h:124
Initialization Configurations.
Definition aom_decoder.h:91
Encoder configuration structure.
Definition aom_encoder.h:385
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:487
unsigned int g_h
Height of the frame.
Definition aom_encoder.h:433
unsigned int monochrome
Monochrome mode.
Definition aom_encoder.h:820
unsigned int g_w
Width of the frame.
Definition aom_encoder.h:424
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition aom_encoder.h:502
size_t sz
Definition aom_encoder.h:88
void * buf
Definition aom_encoder.h:87
Image Descriptor.
Definition aom_image.h:182
aom_chroma_sample_position_t csp
Definition aom_image.h:188
unsigned int y_chroma_shift
Definition aom_image.h:206
aom_img_fmt_t fmt
Definition aom_image.h:183
int stride[3]
Definition aom_image.h:216
unsigned char * img_data
Definition aom_image.h:230
unsigned int x_chroma_shift
Definition aom_image.h:205
unsigned int d_w
Definition aom_image.h:197
int bps
Definition aom_image.h:219
int monochrome
Definition aom_image.h:187
unsigned int d_h
Definition aom_image.h:198
unsigned char * planes[3]
Definition aom_image.h:215
int img_data_owner
Definition aom_image.h:231
int self_allocd
Definition aom_image.h:232
size_t sz
Definition aom_image.h:217
Rational Number.
Definition aom_encoder.h:162
int num
Definition aom_encoder.h:163
int den
Definition aom_encoder.h:164
Encoder Config Options.
Definition aom_encoder.h:225
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition aom_encoder.h:241
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition aom_encoder.h:237
unsigned int disable_trellis_quant
disable trellis quantization
Definition aom_encoder.h:353
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition aom_encoder.h:233