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) {
216 AV1E_SET_ENABLE_DNL_DENOISING,
236 const arg_def_t *main_args[] = { &g_av1_codec_arg_defs.help,
237 &g_av1_codec_arg_defs.use_cfg,
238 &g_av1_codec_arg_defs.debugmode,
239 &g_av1_codec_arg_defs.outputfile,
240 &g_av1_codec_arg_defs.codecarg,
241 &g_av1_codec_arg_defs.passes,
242 &g_av1_codec_arg_defs.pass_arg,
243 &g_av1_codec_arg_defs.fpf_name,
244 &g_av1_codec_arg_defs.limit,
245 &g_av1_codec_arg_defs.skip,
246 &g_av1_codec_arg_defs.good_dl,
247 &g_av1_codec_arg_defs.rt_dl,
248 &g_av1_codec_arg_defs.ai_dl,
249 &g_av1_codec_arg_defs.quietarg,
250 &g_av1_codec_arg_defs.verbosearg,
251 &g_av1_codec_arg_defs.psnrarg,
252 &g_av1_codec_arg_defs.use_webm,
253 &g_av1_codec_arg_defs.use_ivf,
254 &g_av1_codec_arg_defs.use_obu,
255 &g_av1_codec_arg_defs.q_hist_n,
256 &g_av1_codec_arg_defs.rate_hist_n,
257 &g_av1_codec_arg_defs.disable_warnings,
258 &g_av1_codec_arg_defs.disable_warning_prompt,
259 &g_av1_codec_arg_defs.recontest,
262 const arg_def_t *global_args[] = {
263 &g_av1_codec_arg_defs.use_yv12,
264 &g_av1_codec_arg_defs.use_i420,
265 &g_av1_codec_arg_defs.use_i422,
266 &g_av1_codec_arg_defs.use_i444,
267 &g_av1_codec_arg_defs.usage,
268 &g_av1_codec_arg_defs.threads,
269 &g_av1_codec_arg_defs.profile,
270 &g_av1_codec_arg_defs.width,
271 &g_av1_codec_arg_defs.height,
272 &g_av1_codec_arg_defs.forced_max_frame_width,
273 &g_av1_codec_arg_defs.forced_max_frame_height,
275 &g_av1_codec_arg_defs.stereo_mode,
277 &g_av1_codec_arg_defs.timebase,
278 &g_av1_codec_arg_defs.framerate,
279 &g_av1_codec_arg_defs.global_error_resilient,
280 &g_av1_codec_arg_defs.bitdeptharg,
281 &g_av1_codec_arg_defs.inbitdeptharg,
282 &g_av1_codec_arg_defs.lag_in_frames,
283 &g_av1_codec_arg_defs.large_scale_tile,
284 &g_av1_codec_arg_defs.monochrome,
285 &g_av1_codec_arg_defs.full_still_picture_hdr,
286 &g_av1_codec_arg_defs.use_16bit_internal,
287 &g_av1_codec_arg_defs.save_as_annexb,
291 const arg_def_t *rc_args[] = { &g_av1_codec_arg_defs.dropframe_thresh,
292 &g_av1_codec_arg_defs.resize_mode,
293 &g_av1_codec_arg_defs.resize_denominator,
294 &g_av1_codec_arg_defs.resize_kf_denominator,
295 &g_av1_codec_arg_defs.superres_mode,
296 &g_av1_codec_arg_defs.superres_denominator,
297 &g_av1_codec_arg_defs.superres_kf_denominator,
298 &g_av1_codec_arg_defs.superres_qthresh,
299 &g_av1_codec_arg_defs.superres_kf_qthresh,
300 &g_av1_codec_arg_defs.end_usage,
301 &g_av1_codec_arg_defs.target_bitrate,
302 &g_av1_codec_arg_defs.min_quantizer,
303 &g_av1_codec_arg_defs.max_quantizer,
304 &g_av1_codec_arg_defs.undershoot_pct,
305 &g_av1_codec_arg_defs.overshoot_pct,
306 &g_av1_codec_arg_defs.buf_sz,
307 &g_av1_codec_arg_defs.buf_initial_sz,
308 &g_av1_codec_arg_defs.buf_optimal_sz,
309 &g_av1_codec_arg_defs.bias_pct,
310 &g_av1_codec_arg_defs.minsection_pct,
311 &g_av1_codec_arg_defs.maxsection_pct,
314 const arg_def_t *kf_args[] = { &g_av1_codec_arg_defs.fwd_kf_enabled,
315 &g_av1_codec_arg_defs.kf_min_dist,
316 &g_av1_codec_arg_defs.kf_max_dist,
317 &g_av1_codec_arg_defs.kf_disabled,
318 &g_av1_codec_arg_defs.sframe_dist,
319 &g_av1_codec_arg_defs.sframe_mode,
324 const arg_def_t *av1_ctrl_args[] = {
325 &g_av1_codec_arg_defs.cpu_used_av1,
326 &g_av1_codec_arg_defs.auto_altref,
327 &g_av1_codec_arg_defs.sharpness,
328 &g_av1_codec_arg_defs.static_thresh,
329 &g_av1_codec_arg_defs.rowmtarg,
330 &g_av1_codec_arg_defs.tile_cols,
331 &g_av1_codec_arg_defs.tile_rows,
332 &g_av1_codec_arg_defs.enable_tpl_model,
333 &g_av1_codec_arg_defs.enable_keyframe_filtering,
334 &g_av1_codec_arg_defs.arnr_maxframes,
335 &g_av1_codec_arg_defs.arnr_strength,
336 &g_av1_codec_arg_defs.tune_metric,
337 &g_av1_codec_arg_defs.cq_level,
338 &g_av1_codec_arg_defs.max_intra_rate_pct,
339 &g_av1_codec_arg_defs.max_inter_rate_pct,
340 &g_av1_codec_arg_defs.gf_cbr_boost_pct,
341 &g_av1_codec_arg_defs.lossless,
342 &g_av1_codec_arg_defs.enable_cdef,
343 &g_av1_codec_arg_defs.enable_restoration,
344 &g_av1_codec_arg_defs.enable_rect_partitions,
345 &g_av1_codec_arg_defs.enable_ab_partitions,
346 &g_av1_codec_arg_defs.enable_1to4_partitions,
347 &g_av1_codec_arg_defs.min_partition_size,
348 &g_av1_codec_arg_defs.max_partition_size,
349 &g_av1_codec_arg_defs.enable_dual_filter,
350 &g_av1_codec_arg_defs.enable_chroma_deltaq,
351 &g_av1_codec_arg_defs.enable_intra_edge_filter,
352 &g_av1_codec_arg_defs.enable_order_hint,
353 &g_av1_codec_arg_defs.enable_tx64,
354 &g_av1_codec_arg_defs.enable_flip_idtx,
355 &g_av1_codec_arg_defs.enable_rect_tx,
356 &g_av1_codec_arg_defs.enable_dist_wtd_comp,
357 &g_av1_codec_arg_defs.enable_masked_comp,
358 &g_av1_codec_arg_defs.enable_onesided_comp,
359 &g_av1_codec_arg_defs.enable_interintra_comp,
360 &g_av1_codec_arg_defs.enable_smooth_interintra,
361 &g_av1_codec_arg_defs.enable_diff_wtd_comp,
362 &g_av1_codec_arg_defs.enable_interinter_wedge,
363 &g_av1_codec_arg_defs.enable_interintra_wedge,
364 &g_av1_codec_arg_defs.enable_global_motion,
365 &g_av1_codec_arg_defs.enable_warped_motion,
366 &g_av1_codec_arg_defs.enable_filter_intra,
367 &g_av1_codec_arg_defs.enable_smooth_intra,
368 &g_av1_codec_arg_defs.enable_paeth_intra,
369 &g_av1_codec_arg_defs.enable_cfl_intra,
370 &g_av1_codec_arg_defs.enable_diagonal_intra,
371 &g_av1_codec_arg_defs.force_video_mode,
372 &g_av1_codec_arg_defs.enable_obmc,
373 &g_av1_codec_arg_defs.enable_overlay,
374 &g_av1_codec_arg_defs.enable_palette,
375 &g_av1_codec_arg_defs.enable_intrabc,
376 &g_av1_codec_arg_defs.enable_angle_delta,
377 &g_av1_codec_arg_defs.disable_trellis_quant,
378 &g_av1_codec_arg_defs.enable_qm,
379 &g_av1_codec_arg_defs.qm_min,
380 &g_av1_codec_arg_defs.qm_max,
381 &g_av1_codec_arg_defs.reduced_tx_type_set,
382 &g_av1_codec_arg_defs.use_intra_dct_only,
383 &g_av1_codec_arg_defs.use_inter_dct_only,
384 &g_av1_codec_arg_defs.use_intra_default_tx_only,
385 &g_av1_codec_arg_defs.quant_b_adapt,
386 &g_av1_codec_arg_defs.coeff_cost_upd_freq,
387 &g_av1_codec_arg_defs.mode_cost_upd_freq,
388 &g_av1_codec_arg_defs.mv_cost_upd_freq,
389 &g_av1_codec_arg_defs.frame_parallel_decoding,
390 &g_av1_codec_arg_defs.error_resilient_mode,
391 &g_av1_codec_arg_defs.aq_mode,
392 &g_av1_codec_arg_defs.deltaq_mode,
393 &g_av1_codec_arg_defs.deltalf_mode,
394 &g_av1_codec_arg_defs.frame_periodic_boost,
395 &g_av1_codec_arg_defs.noise_sens,
396 &g_av1_codec_arg_defs.tune_content,
397 &g_av1_codec_arg_defs.cdf_update_mode,
398 &g_av1_codec_arg_defs.input_color_primaries,
399 &g_av1_codec_arg_defs.input_transfer_characteristics,
400 &g_av1_codec_arg_defs.input_matrix_coefficients,
401 &g_av1_codec_arg_defs.input_chroma_sample_position,
402 &g_av1_codec_arg_defs.min_gf_interval,
403 &g_av1_codec_arg_defs.max_gf_interval,
404 &g_av1_codec_arg_defs.gf_min_pyr_height,
405 &g_av1_codec_arg_defs.gf_max_pyr_height,
406 &g_av1_codec_arg_defs.superblock_size,
407 &g_av1_codec_arg_defs.num_tg,
408 &g_av1_codec_arg_defs.mtu_size,
409 &g_av1_codec_arg_defs.timing_info,
410 &g_av1_codec_arg_defs.film_grain_test,
411 &g_av1_codec_arg_defs.film_grain_table,
413 &g_av1_codec_arg_defs.denoise_noise_level,
414 &g_av1_codec_arg_defs.denoise_block_size,
415 &g_av1_codec_arg_defs.enable_dnl_denoising,
417 &g_av1_codec_arg_defs.max_reference_frames,
418 &g_av1_codec_arg_defs.reduced_reference_set,
419 &g_av1_codec_arg_defs.enable_ref_frame_mvs,
420 &g_av1_codec_arg_defs.target_seq_level_idx,
421 &g_av1_codec_arg_defs.set_tier_mask,
422 &g_av1_codec_arg_defs.set_min_cr,
423 &g_av1_codec_arg_defs.vbr_corpus_complexity_lap,
424 &g_av1_codec_arg_defs.input_chroma_subsampling_x,
425 &g_av1_codec_arg_defs.input_chroma_subsampling_y,
427 &g_av1_codec_arg_defs.vmaf_model_path,
429 &g_av1_codec_arg_defs.dv_cost_upd_freq,
430 &g_av1_codec_arg_defs.partition_info_path,
431 &g_av1_codec_arg_defs.enable_directional_intra,
432 &g_av1_codec_arg_defs.enable_tx_size_search,
436 const arg_def_t *av1_key_val_args[] = {
437 &g_av1_codec_arg_defs.passes,
438 &g_av1_codec_arg_defs.two_pass_output,
439 &g_av1_codec_arg_defs.fwd_kf_dist,
443 static const arg_def_t *no_args[] = { NULL };
445 static void show_help(FILE *fout,
int shorthelp) {
446 fprintf(fout,
"Usage: %s <options> -o dst_filename src_filename\n",
450 fprintf(fout,
"Use --help to see the full list of options.\n");
454 fprintf(fout,
"\nOptions:\n");
455 arg_show_usage(fout, main_args);
456 fprintf(fout,
"\nEncoder Global Options:\n");
457 arg_show_usage(fout, global_args);
458 fprintf(fout,
"\nRate Control Options:\n");
459 arg_show_usage(fout, rc_args);
460 fprintf(fout,
"\nKeyframe Placement Options:\n");
461 arg_show_usage(fout, kf_args);
462 #if CONFIG_AV1_ENCODER
463 fprintf(fout,
"\nAV1 Specific Options:\n");
464 arg_show_usage(fout, av1_ctrl_args);
465 arg_show_usage(fout, av1_key_val_args);
468 "\nStream timebase (--timebase):\n"
469 " The desired precision of timestamps in the output, expressed\n"
470 " in fractional seconds. Default is 1/1000.\n");
471 fprintf(fout,
"\nIncluded encoders:\n\n");
473 const int num_encoder = get_aom_encoder_count();
474 for (
int i = 0; i < num_encoder; ++i) {
476 const char *defstr = (i == (num_encoder - 1)) ?
"(default)" :
"";
477 fprintf(fout,
" %-6s - %s %s\n", get_short_name_by_aom_encoder(encoder),
480 fprintf(fout,
"\n ");
481 fprintf(fout,
"Use --codec to switch to a non-default encoder.\n\n");
484 void usage_exit(
void) {
485 show_help(stderr, 1);
489 #if CONFIG_AV1_ENCODER
490 #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
491 #define ARG_KEY_VAL_CNT_MAX NELEMENTS(av1_key_val_args)
495 typedef int stereo_format_t;
496 struct WebmOutputContext {
502 struct stream_config {
505 const char *stats_fn;
506 stereo_format_t stereo_fmt;
507 int arg_ctrls[ARG_CTRL_CNT_MAX][2];
509 const char *arg_key_vals[ARG_KEY_VAL_CNT_MAX][2];
512 const char *film_grain_filename;
515 int use_16bit_internal;
517 const char *vmaf_model_path;
519 const char *partition_info_path;
521 const char *two_pass_input;
522 const char *two_pass_output;
527 struct stream_state {
529 struct stream_state *next;
530 struct stream_config config;
532 struct rate_hist *rate_hist;
533 struct WebmOutputContext webm_ctx;
534 uint64_t psnr_sse_total[2];
535 uint64_t psnr_samples_total[2];
536 double psnr_totals[2][4];
540 unsigned int frames_out;
547 unsigned int chroma_subsampling_x;
548 unsigned int chroma_subsampling_y;
549 const char *orig_out_fn;
550 unsigned int orig_width;
551 unsigned int orig_height;
557 static void validate_positive_rational(
const char *msg,
564 if (rat->
num < 0) die(
"Error: %s must be positive\n", msg);
566 if (!rat->
den) die(
"Error: %s has zero denominator\n", msg);
580 static void parse_global_config(
struct AvxEncoderConfig *global,
char ***argv) {
583 const int num_encoder = get_aom_encoder_count();
584 char **argv_local = (
char **)*argv;
585 if (num_encoder < 1) die(
"Error: no valid encoder available\n");
588 memset(global, 0,
sizeof(*global));
589 global->codec = get_aom_encoder_by_index(num_encoder - 1);
591 global->color_type = I420;
593 global->show_psnr = 0;
595 int cfg_included = 0;
596 init_config(&global->encoder_config);
598 for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
601 if (arg_match(&arg, &g_av1_codec_arg_defs.use_cfg, argi)) {
603 parse_cfg(arg.val, &global->encoder_config);
606 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.help, argi)) {
607 show_help(stdout, 0);
609 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.codecarg, argi)) {
610 global->codec = get_aom_encoder_by_short_name(arg.val);
612 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
613 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.passes, argi)) {
614 global->passes = arg_parse_uint(&arg);
616 if (global->passes < 1 || global->passes > 3)
617 die(
"Error: Invalid number of passes (%d)\n", global->passes);
618 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.pass_arg, argi)) {
619 global->pass = arg_parse_uint(&arg);
621 if (global->pass < 1 || global->pass > 3)
622 die(
"Error: Invalid pass selected (%d)\n", global->pass);
623 }
else if (arg_match(&arg,
624 &g_av1_codec_arg_defs.input_chroma_sample_position,
626 global->csp = arg_parse_enum(&arg);
629 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.usage, argi)) {
630 global->usage = arg_parse_uint(&arg);
631 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.good_dl, argi)) {
633 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rt_dl, argi)) {
635 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.ai_dl, argi)) {
637 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_yv12, argi)) {
638 global->color_type = YV12;
639 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i420, argi)) {
640 global->color_type = I420;
641 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i422, argi)) {
642 global->color_type = I422;
643 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i444, argi)) {
644 global->color_type = I444;
645 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.quietarg, argi)) {
647 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.verbosearg, argi)) {
649 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.limit, argi)) {
650 global->limit = arg_parse_uint(&arg);
651 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.skip, argi)) {
652 global->skip_frames = arg_parse_uint(&arg);
653 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.psnrarg, argi)) {
655 global->show_psnr = arg_parse_int(&arg);
657 global->show_psnr = 1;
658 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.recontest, argi)) {
659 global->test_decode = arg_parse_enum_or_int(&arg);
660 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.framerate, argi)) {
661 global->framerate = arg_parse_rational(&arg);
662 validate_positive_rational(arg.name, &global->framerate);
663 global->have_framerate = 1;
664 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.debugmode, argi)) {
666 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.q_hist_n, argi)) {
667 global->show_q_hist_buckets = arg_parse_uint(&arg);
668 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_hist_n, argi)) {
669 global->show_rate_hist_buckets = arg_parse_uint(&arg);
670 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warnings, argi)) {
671 global->disable_warnings = 1;
672 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warning_prompt,
674 global->disable_warning_prompt = 1;
682 if (global->pass > global->passes) {
683 aom_tools_warn(
"Assuming --pass=%d implies --passes=%d\n", global->pass,
685 global->passes = global->pass;
689 if (global->passes == 0) {
690 #if CONFIG_AV1_ENCODER
693 if (global->codec != NULL)
695 (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0 &&
705 aom_tools_warn(
"Enforcing one-pass encoding in realtime mode\n");
706 if (global->pass > 1)
707 die(
"Error: Invalid --pass=%d for one-pass encoding\n", global->pass);
712 aom_tools_warn(
"Enforcing one-pass encoding in all intra mode\n");
717 static void open_input_file(
struct AvxInputContext *input,
720 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
721 : set_binary_mode(stdin);
723 if (!input->file) fatal(
"Failed to open input file");
725 if (!fseeko(input->file, 0, SEEK_END)) {
729 input->length = ftello(input->file);
734 input->pixel_aspect_ratio.numerator = 1;
735 input->pixel_aspect_ratio.denominator = 1;
740 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
741 input->detect.position = 0;
743 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
744 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
745 input->only_i420) >= 0) {
746 input->file_type = FILE_TYPE_Y4M;
747 input->width = input->y4m.pic_w;
748 input->height = input->y4m.pic_h;
749 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
750 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
751 input->framerate.numerator = input->y4m.fps_n;
752 input->framerate.denominator = input->y4m.fps_d;
753 input->fmt = input->y4m.aom_fmt;
754 input->bit_depth = input->y4m.bit_depth;
755 input->color_range = input->y4m.color_range;
757 fatal(
"Unsupported Y4M stream.");
758 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
759 fatal(
"IVF is not supported as input.");
761 input->file_type = FILE_TYPE_RAW;
765 static void close_input_file(
struct AvxInputContext *input) {
767 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
770 static struct stream_state *new_stream(
struct AvxEncoderConfig *global,
771 struct stream_state *prev) {
772 struct stream_state *stream;
774 stream = calloc(1,
sizeof(*stream));
775 if (stream == NULL) {
776 fatal(
"Failed to allocate new stream.");
780 memcpy(stream, prev,
sizeof(*stream));
794 stream->config.cfg.g_timebase.den = 1000;
799 stream->config.cfg.g_w = 0;
800 stream->config.cfg.g_h = 0;
803 stream->config.write_webm = 1;
804 stream->config.write_ivf = 0;
807 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
808 stream->webm_ctx.last_pts_ns = -1;
809 stream->webm_ctx.writer = NULL;
810 stream->webm_ctx.segment = NULL;
814 stream->webm_ctx.debug = global->debug;
815 memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
816 sizeof(stream->config.cfg.encoder_cfg));
820 stream->config.out_fn = NULL;
821 stream->config.two_pass_input = NULL;
822 stream->config.two_pass_output = NULL;
823 stream->config.two_pass_width = 0;
824 stream->config.two_pass_height = 0;
830 static void set_config_arg_ctrls(
struct stream_config *config,
int key,
831 const struct arg *arg) {
834 config->film_grain_filename = arg->val;
841 j = config->arg_ctrl_cnt;
842 assert(j < ARG_CTRL_CNT_MAX);
843 config->arg_ctrls[j][0] = key;
844 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
845 ++config->arg_ctrl_cnt;
852 for (j = 0; j < config->arg_ctrl_cnt; j++)
853 if (config->arg_ctrls[j][0] == key)
break;
856 assert(j < ARG_CTRL_CNT_MAX);
857 config->arg_ctrls[j][0] = key;
858 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
862 "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
863 config->arg_ctrls[j][1] = 1;
866 if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
869 static void set_config_arg_key_vals(
struct stream_config *config,
870 const char *name,
const struct arg *arg) {
872 const char *val = arg->val;
875 if (strcmp(name,
"target-seq-level-idx") == 0) {
876 j = config->arg_key_val_cnt;
877 assert(j < ARG_KEY_VAL_CNT_MAX);
878 config->arg_key_vals[j][0] = name;
879 config->arg_key_vals[j][1] = val;
880 ++config->arg_key_val_cnt;
887 for (j = 0; j < config->arg_key_val_cnt; j++)
888 if (strcmp(name, config->arg_key_vals[j][0]) == 0)
break;
891 assert(j < ARG_KEY_VAL_CNT_MAX);
892 config->arg_key_vals[j][0] = name;
893 config->arg_key_vals[j][1] = val;
895 if (strcmp(name, g_av1_codec_arg_defs.auto_altref.long_name) == 0) {
896 int auto_altref = arg_parse_int(arg);
897 if (auto_altref > 1) {
899 "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
900 config->arg_key_vals[j][1] =
"1";
904 if (j == config->arg_key_val_cnt) config->arg_key_val_cnt++;
907 static int parse_stream_params(
struct AvxEncoderConfig *global,
908 struct stream_state *stream,
char **argv) {
911 static const arg_def_t **ctrl_args = no_args;
912 static const arg_def_t **key_val_args = no_args;
913 static const int *ctrl_args_map = NULL;
914 struct stream_config *config = &stream->config;
915 int eos_mark_found = 0;
920 #if CONFIG_AV1_ENCODER
921 }
else if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
924 ctrl_args = av1_ctrl_args;
925 ctrl_args_map = av1_arg_ctrl_map;
926 key_val_args = av1_key_val_args;
930 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
936 if (eos_mark_found) {
939 }
else if (!strcmp(*argj,
"--")) {
944 if (arg_match(&arg, &g_av1_codec_arg_defs.outputfile, argi)) {
945 config->out_fn = arg.val;
947 const size_t out_fn_len = strlen(config->out_fn);
948 if (out_fn_len >= 4 &&
949 !strcmp(config->out_fn + out_fn_len - 4,
".ivf")) {
950 config->write_webm = 0;
951 config->write_ivf = 1;
952 }
else if (out_fn_len >= 4 &&
953 !strcmp(config->out_fn + out_fn_len - 4,
".obu")) {
954 config->write_webm = 0;
955 config->write_ivf = 0;
958 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fpf_name, argi)) {
959 config->stats_fn = arg.val;
960 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_webm, argi)) {
962 config->write_webm = 1;
965 die(
"Error: --webm specified but webm is disabled.");
967 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_ivf, argi)) {
968 config->write_webm = 0;
969 config->write_ivf = 1;
970 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_obu, argi)) {
971 config->write_webm = 0;
972 config->write_ivf = 0;
973 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.threads, argi)) {
974 config->cfg.g_threads = arg_parse_uint(&arg);
975 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.profile, argi)) {
976 config->cfg.g_profile = arg_parse_uint(&arg);
977 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.width, argi)) {
978 config->cfg.g_w = arg_parse_uint(&arg);
979 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.height, argi)) {
980 config->cfg.g_h = arg_parse_uint(&arg);
981 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_width,
983 config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
984 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_height,
986 config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
987 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bitdeptharg, argi)) {
988 config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
989 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.inbitdeptharg, argi)) {
990 config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
991 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_x,
993 stream->chroma_subsampling_x = arg_parse_uint(&arg);
994 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_y,
996 stream->chroma_subsampling_y = arg_parse_uint(&arg);
998 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.stereo_mode, argi)) {
999 config->stereo_fmt = arg_parse_enum_or_int(&arg);
1001 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.timebase, argi)) {
1002 config->cfg.g_timebase = arg_parse_rational(&arg);
1003 validate_positive_rational(arg.name, &config->cfg.g_timebase);
1004 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.global_error_resilient,
1006 config->cfg.g_error_resilient = arg_parse_uint(&arg);
1007 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.lag_in_frames, argi)) {
1008 config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
1009 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.large_scale_tile, argi)) {
1010 config->cfg.large_scale_tile = arg_parse_uint(&arg);
1011 if (config->cfg.large_scale_tile) {
1012 global->codec = get_aom_encoder_by_short_name(
"av1");
1014 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.monochrome, argi)) {
1015 config->cfg.monochrome = 1;
1016 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.full_still_picture_hdr,
1018 config->cfg.full_still_picture_hdr = 1;
1019 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_16bit_internal,
1021 config->use_16bit_internal = CONFIG_AV1_HIGHBITDEPTH;
1022 if (!config->use_16bit_internal) {
1023 aom_tools_warn(
"%s option ignored with CONFIG_AV1_HIGHBITDEPTH=0.\n",
1026 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.dropframe_thresh, argi)) {
1027 config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
1028 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_mode, argi)) {
1029 config->cfg.rc_resize_mode = arg_parse_uint(&arg);
1030 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_denominator,
1032 config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
1033 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_kf_denominator,
1035 config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
1036 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_mode, argi)) {
1037 config->cfg.rc_superres_mode = arg_parse_uint(&arg);
1038 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_denominator,
1040 config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
1041 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_denominator,
1043 config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
1044 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_qthresh, argi)) {
1045 config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
1046 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_qthresh,
1048 config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
1049 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.end_usage, argi)) {
1050 config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
1051 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.target_bitrate, argi)) {
1052 config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
1053 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.min_quantizer, argi)) {
1054 config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
1055 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.max_quantizer, argi)) {
1056 config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
1057 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.undershoot_pct, argi)) {
1058 config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
1059 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.overshoot_pct, argi)) {
1060 config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
1061 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_sz, argi)) {
1062 config->cfg.rc_buf_sz = arg_parse_uint(&arg);
1063 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_initial_sz, argi)) {
1064 config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
1065 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_optimal_sz, argi)) {
1066 config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
1067 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bias_pct, argi)) {
1068 config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
1069 if (global->passes < 2)
1070 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1071 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.minsection_pct, argi)) {
1072 config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
1074 if (global->passes < 2)
1075 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1076 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.maxsection_pct, argi)) {
1077 config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
1079 if (global->passes < 2)
1080 aom_tools_warn(
"option %s ignored in one-pass mode.\n", arg.name);
1081 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fwd_kf_enabled, argi)) {
1082 config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
1083 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_min_dist, argi)) {
1084 config->cfg.kf_min_dist = arg_parse_uint(&arg);
1085 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_max_dist, argi)) {
1086 config->cfg.kf_max_dist = arg_parse_uint(&arg);
1087 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_disabled, argi)) {
1089 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_dist, argi)) {
1090 config->cfg.sframe_dist = arg_parse_uint(&arg);
1091 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_mode, argi)) {
1092 config->cfg.sframe_mode = arg_parse_uint(&arg);
1093 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.save_as_annexb, argi)) {
1094 config->cfg.save_as_annexb = arg_parse_uint(&arg);
1095 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_width, argi)) {
1096 config->cfg.tile_width_count =
1098 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_height, argi)) {
1099 config->cfg.tile_height_count =
1101 #if CONFIG_TUNE_VMAF
1102 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argi)) {
1103 config->vmaf_model_path = arg.val;
1105 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.partition_info_path,
1107 config->partition_info_path = arg.val;
1108 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_fixed_qp_offsets,
1110 config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg);
1111 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fixed_qp_offsets, argi)) {
1112 const int fixed_qp_offset_count = arg_parse_list(
1115 die(
"Option --fixed_qp_offsets requires %d comma-separated values, but "
1116 "only %d values were provided.\n",
1119 config->cfg.use_fixed_qp_offsets = 1;
1121 arg_match(&arg, &g_av1_codec_arg_defs.enable_restoration,
1123 if (arg_parse_uint(&arg) == 1) {
1124 aom_tools_warn(
"non-zero %s option ignored in realtime mode.\n",
1127 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_input, argi)) {
1128 config->two_pass_input = arg.val;
1129 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_output, argi)) {
1130 config->two_pass_output = arg.val;
1131 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_width, argi)) {
1132 config->two_pass_width = arg_parse_int(&arg);
1133 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_height, argi)) {
1134 config->two_pass_height = arg_parse_int(&arg);
1138 if (ctrl_args_map) {
1139 for (i = 0; ctrl_args[i]; i++) {
1140 if (arg_match(&arg, ctrl_args[i], argi)) {
1142 set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1149 for (i = 0; key_val_args[i]; i++) {
1150 if (arg_match(&arg, key_val_args[i], argi)) {
1152 set_config_arg_key_vals(config, key_val_args[i]->long_name, &arg);
1160 config->use_16bit_internal |= config->cfg.g_bit_depth >
AOM_BITS_8;
1163 aom_tools_warn(
"non-zero lag-in-frames option ignored in realtime mode.\n");
1164 config->cfg.g_lag_in_frames = 0;
1168 if (config->cfg.g_lag_in_frames != 0) {
1170 "non-zero lag-in-frames option ignored in all intra mode.\n");
1171 config->cfg.g_lag_in_frames = 0;
1173 if (config->cfg.kf_max_dist != 0) {
1175 "non-zero max key frame distance option ignored in all intra "
1177 config->cfg.kf_max_dist = 0;
1182 if (config->arg_key_val_cnt >= ARG_KEY_VAL_CNT_MAX) {
1183 die(
"Not enough buffer for the key & value API.");
1185 config->arg_key_vals[config->arg_key_val_cnt][0] =
"passes";
1186 switch (global->passes) {
1187 case 0: config->arg_key_vals[config->arg_key_val_cnt][1] =
"0";
break;
1188 case 1: config->arg_key_vals[config->arg_key_val_cnt][1] =
"1";
break;
1189 case 2: config->arg_key_vals[config->arg_key_val_cnt][1] =
"2";
break;
1190 case 3: config->arg_key_vals[config->arg_key_val_cnt][1] =
"3";
break;
1191 default: die(
"Invalid value of --passes.");
1193 config->arg_key_val_cnt++;
1196 if (!config->two_pass_output && global->passes == 3) {
1197 snprintf(stream->tmp_out_fn,
sizeof(stream->tmp_out_fn),
1198 "tmp_2pass_output_%d.ivf", stream->index);
1199 stream->config.two_pass_output = stream->tmp_out_fn;
1201 if (config->two_pass_output) {
1202 config->arg_key_vals[config->arg_key_val_cnt][0] =
"two-pass-output";
1203 config->arg_key_vals[config->arg_key_val_cnt][1] = config->two_pass_output;
1204 config->arg_key_val_cnt++;
1207 return eos_mark_found;
1210 #define FOREACH_STREAM(iterator, list) \
1211 for (struct stream_state *iterator = list; iterator; \
1212 iterator = iterator->next)
1214 static void validate_stream_config(
const struct stream_state *stream,
1215 const struct AvxEncoderConfig *global) {
1216 const struct stream_state *streami;
1219 if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1221 "Stream %d: Specify stream dimensions with --width (-w) "
1222 " and --height (-h)",
1228 assert(stream->config.cfg.g_input_bit_depth <=
1229 (
unsigned int)stream->config.cfg.g_bit_depth);
1231 for (streami = stream; streami; streami = streami->next) {
1233 if (!streami->config.out_fn)
1234 fatal(
"Stream %d: Output file is required (specify with -o)",
1238 if (streami != stream) {
1239 const char *a = stream->config.out_fn;
1240 const char *b = streami->config.out_fn;
1241 if (!strcmp(a, b) && strcmp(a,
"/dev/null") && strcmp(a,
":nul"))
1242 fatal(
"Stream %d: duplicate output file (from stream %d)",
1243 streami->index, stream->index);
1247 if (streami != stream) {
1248 const char *a = stream->config.stats_fn;
1249 const char *b = streami->config.stats_fn;
1250 if (a && b && !strcmp(a, b))
1251 fatal(
"Stream %d: duplicate stats file (from stream %d)",
1252 streami->index, stream->index);
1257 static void set_stream_dimensions(
struct stream_state *stream,
unsigned int w,
1259 if (!stream->config.cfg.g_w) {
1260 if (!stream->config.cfg.g_h)
1261 stream->config.cfg.g_w = w;
1263 stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1265 if (!stream->config.cfg.g_h) {
1266 stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1270 static const char *file_type_to_string(
enum VideoFileType t) {
1272 case FILE_TYPE_RAW:
return "RAW";
1273 case FILE_TYPE_Y4M:
return "Y4M";
1274 default:
return "Other";
1278 static const char *image_format_to_string(
aom_img_fmt_t f) {
1288 default:
return "Other";
1292 static void show_stream_config(
struct stream_state *stream,
1293 struct AvxEncoderConfig *global,
1294 struct AvxInputContext *input) {
1295 #define SHOW(field) \
1296 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1298 if (stream->index == 0) {
1300 fprintf(stderr,
"Source file: %s File Type: %s Format: %s\n",
1301 input->filename, file_type_to_string(input->file_type),
1302 image_format_to_string(input->fmt));
1304 if (stream->next || stream->index)
1305 fprintf(stderr,
"\nStream Index: %d\n", stream->index);
1306 fprintf(stderr,
"Destination file: %s\n", stream->config.out_fn);
1307 fprintf(stderr,
"Coding path: %s\n",
1308 stream->config.use_16bit_internal ?
"HBD" :
"LBD");
1309 fprintf(stderr,
"Encoder parameters:\n");
1317 SHOW(g_input_bit_depth);
1318 SHOW(g_timebase.num);
1319 SHOW(g_timebase.den);
1320 SHOW(g_error_resilient);
1322 SHOW(g_lag_in_frames);
1323 SHOW(large_scale_tile);
1324 SHOW(rc_dropframe_thresh);
1325 SHOW(rc_resize_mode);
1326 SHOW(rc_resize_denominator);
1327 SHOW(rc_resize_kf_denominator);
1328 SHOW(rc_superres_mode);
1329 SHOW(rc_superres_denominator);
1330 SHOW(rc_superres_kf_denominator);
1331 SHOW(rc_superres_qthresh);
1332 SHOW(rc_superres_kf_qthresh);
1334 SHOW(rc_target_bitrate);
1335 SHOW(rc_min_quantizer);
1336 SHOW(rc_max_quantizer);
1337 SHOW(rc_undershoot_pct);
1338 SHOW(rc_overshoot_pct);
1340 SHOW(rc_buf_initial_sz);
1341 SHOW(rc_buf_optimal_sz);
1342 SHOW(rc_2pass_vbr_bias_pct);
1343 SHOW(rc_2pass_vbr_minsection_pct);
1344 SHOW(rc_2pass_vbr_maxsection_pct);
1345 SHOW(fwd_kf_enabled);
1350 #define SHOW_PARAMS(field) \
1351 fprintf(stderr, " %-28s = %d\n", #field, \
1352 stream->config.cfg.encoder_cfg.field)
1353 if (global->encoder_config.init_by_cfg_file) {
1354 SHOW_PARAMS(super_block_size);
1355 SHOW_PARAMS(max_partition_size);
1356 SHOW_PARAMS(min_partition_size);
1357 SHOW_PARAMS(disable_ab_partition_type);
1358 SHOW_PARAMS(disable_rect_partition_type);
1359 SHOW_PARAMS(disable_1to4_partition_type);
1360 SHOW_PARAMS(disable_flip_idtx);
1361 SHOW_PARAMS(disable_cdef);
1362 SHOW_PARAMS(disable_lr);
1363 SHOW_PARAMS(disable_obmc);
1364 SHOW_PARAMS(disable_warp_motion);
1365 SHOW_PARAMS(disable_global_motion);
1366 SHOW_PARAMS(disable_dist_wtd_comp);
1367 SHOW_PARAMS(disable_diff_wtd_comp);
1368 SHOW_PARAMS(disable_inter_intra_comp);
1369 SHOW_PARAMS(disable_masked_comp);
1370 SHOW_PARAMS(disable_one_sided_comp);
1371 SHOW_PARAMS(disable_palette);
1372 SHOW_PARAMS(disable_intrabc);
1373 SHOW_PARAMS(disable_cfl);
1374 SHOW_PARAMS(disable_smooth_intra);
1375 SHOW_PARAMS(disable_filter_intra);
1376 SHOW_PARAMS(disable_dual_filter);
1377 SHOW_PARAMS(disable_intra_angle_delta);
1378 SHOW_PARAMS(disable_intra_edge_filter);
1379 SHOW_PARAMS(disable_tx_64x64);
1380 SHOW_PARAMS(disable_smooth_inter_intra);
1381 SHOW_PARAMS(disable_inter_inter_wedge);
1382 SHOW_PARAMS(disable_inter_intra_wedge);
1383 SHOW_PARAMS(disable_paeth_intra);
1384 SHOW_PARAMS(disable_trellis_quant);
1385 SHOW_PARAMS(disable_ref_frame_mv);
1386 SHOW_PARAMS(reduced_reference_set);
1387 SHOW_PARAMS(reduced_tx_type_set);
1391 static void open_output_file(
struct stream_state *stream,
1392 struct AvxEncoderConfig *global,
1393 const struct AvxRational *pixel_aspect_ratio,
1394 const char *encoder_settings) {
1395 const char *fn = stream->config.out_fn;
1400 stream->file = strcmp(fn,
"-") ? fopen(fn,
"wb") : set_binary_mode(stdout);
1402 if (!stream->file) fatal(
"Failed to open output file");
1404 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1405 fatal(
"WebM output to pipes not supported.");
1408 if (stream->config.write_webm) {
1409 stream->webm_ctx.stream = stream->file;
1410 if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1411 stream->config.stereo_fmt,
1412 get_fourcc_by_aom_encoder(global->codec),
1413 pixel_aspect_ratio, encoder_settings) != 0) {
1414 fatal(
"WebM writer initialization failed.");
1418 (void)pixel_aspect_ratio;
1419 (void)encoder_settings;
1422 if (!stream->config.write_webm && stream->config.write_ivf) {
1423 ivf_write_file_header(stream->file, cfg,
1424 get_fourcc_by_aom_encoder(global->codec), 0);
1428 static void close_output_file(
struct stream_state *stream,
1429 unsigned int fourcc) {
1435 if (stream->config.write_webm) {
1436 if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1437 fatal(
"WebM writer finalization failed.");
1442 if (!stream->config.write_webm && stream->config.write_ivf) {
1443 if (!fseek(stream->file, 0, SEEK_SET))
1444 ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1445 stream->frames_out);
1448 fclose(stream->file);
1451 static void setup_pass(
struct stream_state *stream,
1452 struct AvxEncoderConfig *global,
int pass) {
1453 if (stream->config.stats_fn) {
1454 if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1455 fatal(
"Failed to open statistics store");
1457 if (!stats_open_mem(&stream->stats, pass))
1458 fatal(
"Failed to open statistics store");
1461 if (global->passes == 1) {
1468 default: fatal(
"Failed to set pass");
1473 stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1476 stream->cx_time = 0;
1478 stream->frames_out = 0;
1481 static void initialize_encoder(
struct stream_state *stream,
1482 struct AvxEncoderConfig *global) {
1492 ctx_exit_on_error(&stream->encoder,
"Failed to initialize encoder");
1494 for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1495 int ctrl = stream->config.arg_ctrls[i][0];
1496 int value = stream->config.arg_ctrls[i][1];
1498 fprintf(stderr,
"Error: Tried to set control %d = %d\n", ctrl, value);
1500 ctx_exit_on_error(&stream->encoder,
"Failed to control codec");
1503 for (i = 0; i < stream->config.arg_key_val_cnt; i++) {
1504 const char *name = stream->config.arg_key_vals[i][0];
1505 const char *val = stream->config.arg_key_vals[i][1];
1507 fprintf(stderr,
"Error: Tried to set option %s = %s\n", name, val);
1509 ctx_exit_on_error(&stream->encoder,
"Failed to set codec option");
1512 #if CONFIG_TUNE_VMAF
1513 if (stream->config.vmaf_model_path) {
1515 stream->config.vmaf_model_path);
1518 if (stream->config.partition_info_path) {
1521 stream->config.partition_info_path);
1524 if (stream->config.film_grain_filename) {
1526 stream->config.film_grain_filename);
1529 stream->config.color_range);
1531 #if CONFIG_AV1_DECODER
1532 if (global->test_decode != TEST_DECODE_OFF) {
1534 get_short_name_by_aom_encoder(global->codec));
1538 if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
1540 stream->config.cfg.large_scale_tile);
1541 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_mode");
1544 stream->config.cfg.save_as_annexb);
1545 ctx_exit_on_error(&stream->decoder,
"Failed to set is_annexb");
1549 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_row");
1553 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_col");
1564 static void convert_image_to_monochrome(
const struct aom_image *img,
1566 *monochrome_img = *img;
1579 monochrome_img->
sz = 0;
1586 static void encode_frame(
struct stream_state *stream,
1587 struct AvxEncoderConfig *global,
struct aom_image *img,
1588 unsigned int frames_in) {
1591 struct aom_usec_timer timer;
1594 (cfg->
g_timebase.
den * (int64_t)(frames_in - 1) * global->framerate.den) /
1597 (cfg->
g_timebase.
den * (int64_t)(frames_in)*global->framerate.den) /
1605 fprintf(stderr,
"%s can only scale 4:2:0 inputs\n", exec_name);
1622 stream->img->stride[
AOM_PLANE_V] / 2, stream->img->d_w,
1623 stream->img->d_h, kFilterBox);
1626 stream->encoder.err = 1;
1627 ctx_exit_on_error(&stream->encoder,
1628 "Stream %d: Failed to encode frame.\n"
1629 "libyuv is required for scaling but is currently "
1631 "Be sure to specify -DCONFIG_LIBYUV=1 when running "
1637 if (img && (img->
d_w != cfg->
g_w || img->
d_h != cfg->
g_h)) {
1639 fprintf(stderr,
"%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1653 stream->img->d_w, stream->img->d_h, kFilterBox);
1656 stream->encoder.err = 1;
1657 ctx_exit_on_error(&stream->encoder,
1658 "Stream %d: Failed to encode frame.\n"
1659 "Scaling disabled in this configuration. \n"
1660 "To enable, configure with --enable-libyuv\n",
1667 convert_image_to_monochrome(img, &monochrome_img);
1668 img = &monochrome_img;
1671 aom_usec_timer_start(&timer);
1673 (uint32_t)(next_frame_start - frame_start), 0);
1674 aom_usec_timer_mark(&timer);
1675 stream->cx_time += aom_usec_timer_elapsed(&timer);
1676 ctx_exit_on_error(&stream->encoder,
"Stream %d: Failed to encode frame",
1680 static void update_quantizer_histogram(
struct stream_state *stream) {
1686 ctx_exit_on_error(&stream->encoder,
"Failed to read quantizer");
1687 stream->counts[q]++;
1691 static void get_cx_data(
struct stream_state *stream,
1692 struct AvxEncoderConfig *global,
int *got_data) {
1699 static size_t fsize = 0;
1700 static FileOffset ivf_header_pos = 0;
1702 switch (pkt->
kind) {
1704 ++stream->frames_out;
1706 fprintf(stderr,
" %6luF", (
unsigned long)pkt->
data.
frame.sz);
1708 update_rate_histogram(stream->rate_hist, cfg, pkt);
1710 if (stream->config.write_webm) {
1711 if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
1712 fatal(
"WebM writer failed.");
1716 if (!stream->config.write_webm) {
1717 if (stream->config.write_ivf) {
1718 if (pkt->
data.
frame.partition_id <= 0) {
1719 ivf_header_pos = ftello(stream->file);
1722 ivf_write_frame_header(stream->file, pkt->
data.
frame.pts, fsize);
1726 const FileOffset currpos = ftello(stream->file);
1727 fseeko(stream->file, ivf_header_pos, SEEK_SET);
1728 ivf_write_frame_size(stream->file, fsize);
1729 fseeko(stream->file, currpos, SEEK_SET);
1739 #if CONFIG_AV1_DECODER
1740 if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
1743 if (stream->decoder.err) {
1744 warn_or_exit_on_error(&stream->decoder,
1745 global->test_decode == TEST_DECODE_FATAL,
1746 "Failed to decode frame %d in stream %d",
1747 stream->frames_out + 1, stream->index);
1748 stream->mismatch_seen = stream->frames_out + 1;
1754 stream->frames_out++;
1761 if (global->show_psnr >= 1) {
1764 stream->psnr_sse_total[0] += pkt->
data.
psnr.sse[0];
1765 stream->psnr_samples_total[0] += pkt->
data.
psnr.samples[0];
1766 for (i = 0; i < 4; i++) {
1768 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr[i]);
1769 stream->psnr_totals[0][i] += pkt->
data.
psnr.psnr[i];
1771 stream->psnr_count[0]++;
1773 #if CONFIG_AV1_HIGHBITDEPTH
1774 if (stream->config.cfg.g_input_bit_depth <
1775 (
unsigned int)stream->config.cfg.g_bit_depth) {
1776 stream->psnr_sse_total[1] += pkt->
data.
psnr.sse_hbd[0];
1777 stream->psnr_samples_total[1] += pkt->
data.
psnr.samples_hbd[0];
1778 for (i = 0; i < 4; i++) {
1780 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr_hbd[i]);
1781 stream->psnr_totals[1][i] += pkt->
data.
psnr.psnr_hbd[i];
1783 stream->psnr_count[1]++;
1794 static void show_psnr(
struct stream_state *stream,
double peak, int64_t bps) {
1798 if (!stream->psnr_count[0])
return;
1800 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1801 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[0], peak,
1802 (
double)stream->psnr_sse_total[0]);
1803 fprintf(stderr,
" %.3f", ovpsnr);
1805 for (i = 0; i < 4; i++) {
1806 fprintf(stderr,
" %.3f", stream->psnr_totals[0][i] / stream->psnr_count[0]);
1809 fprintf(stderr,
" %7" PRId64
" bps", bps);
1811 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1812 fprintf(stderr,
"\n");
1815 #if CONFIG_AV1_HIGHBITDEPTH
1816 static void show_psnr_hbd(
struct stream_state *stream,
double peak,
1821 if (!stream->psnr_count[1])
return;
1823 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1824 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[1], peak,
1825 (
double)stream->psnr_sse_total[1]);
1826 fprintf(stderr,
" %.3f", ovpsnr);
1828 for (i = 0; i < 4; i++) {
1829 fprintf(stderr,
" %.3f", stream->psnr_totals[1][i] / stream->psnr_count[1]);
1832 fprintf(stderr,
" %7" PRId64
" bps", bps);
1834 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1835 fprintf(stderr,
"\n");
1839 static float usec_to_fps(uint64_t usec,
unsigned int frames) {
1840 return (
float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
1843 static void test_decode(
struct stream_state *stream,
1844 enum TestDecodeFatality fatal) {
1847 if (stream->mismatch_seen)
return;
1860 enc_img.
d_w, enc_img.
d_h, 16);
1861 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1862 enc_img = enc_hbd_img;
1867 dec_img.
d_w, dec_img.
d_h, 16);
1868 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1869 dec_img = dec_hbd_img;
1873 ctx_exit_on_error(&stream->encoder,
"Failed to get encoder reference frame");
1874 ctx_exit_on_error(&stream->decoder,
"Failed to get decoder reference frame");
1876 if (!aom_compare_img(&enc_img, &dec_img)) {
1877 int y[4], u[4], v[4];
1879 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1881 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1883 stream->decoder.err = 1;
1884 warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
1885 "Stream %d: Encode/decode mismatch on frame %d at"
1886 " Y[%d, %d] {%d/%d},"
1887 " U[%d, %d] {%d/%d},"
1888 " V[%d, %d] {%d/%d}",
1889 stream->index, stream->frames_out, y[0], y[1], y[2],
1890 y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
1891 stream->mismatch_seen = stream->frames_out;
1898 static void print_time(
const char *label, int64_t etl) {
1905 etl -= hours * 3600;
1910 fprintf(stderr,
"[%3s %2" PRId64
":%02" PRId64
":%02" PRId64
"] ", label,
1913 fprintf(stderr,
"[%3s unknown] ", label);
1917 static void clear_stream_count_state(
struct stream_state *stream) {
1919 for (
int k = 0; k < 2; k++) {
1920 stream->psnr_sse_total[k] = 0;
1921 stream->psnr_samples_total[k] = 0;
1922 for (
int i = 0; i < 4; i++) {
1923 stream->psnr_totals[k][i] = 0;
1925 stream->psnr_count[k] = 0;
1928 memset(stream->counts, 0,
sizeof(stream->counts));
1937 static int pass_need_downscale(
int global_pass,
int global_passes,
int pass) {
1938 return !global_pass && global_passes > 2 && pass == 1;
1941 int main(
int argc,
const char **argv_) {
1945 int allocated_raw_shift = 0;
1946 int do_16bit_internal = 0;
1947 int input_shift = 0;
1948 int frame_avail, got_data;
1950 struct AvxInputContext input;
1951 struct AvxEncoderConfig global;
1952 struct stream_state *streams = NULL;
1953 char **argv, **argi;
1954 uint64_t cx_time = 0;
1957 int profile_updated = 0;
1959 memset(&input, 0,
sizeof(input));
1960 memset(&raw, 0,
sizeof(raw));
1961 exec_name = argv_[0];
1964 input.framerate.numerator = 30;
1965 input.framerate.denominator = 1;
1966 input.only_i420 = 1;
1967 input.bit_depth = 0;
1973 argv = argv_dup(argc - 1, argv_ + 1);
1974 parse_global_config(&global, &argv);
1976 if (argc < 2) usage_exit();
1978 switch (global.color_type) {
1990 struct stream_state *stream = NULL;
1993 stream = new_stream(&global, stream);
1995 if (!streams) streams = stream;
1996 }
while (parse_stream_params(&global, stream, argv));
2000 for (argi = argv; *argi; argi++)
2001 if (argi[0][0] ==
'-' && argi[0][1])
2002 die(
"Error: Unrecognized option %s\n", *argi);
2004 FOREACH_STREAM(stream, streams) {
2005 check_encoder_config(global.disable_warning_prompt, &global,
2006 &stream->config.cfg);
2009 if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
2010 die(
"only support ivf output format while large-scale-tile=1\n");
2014 input.filename = argv[0];
2015 const char *orig_input_filename = input.filename;
2016 FOREACH_STREAM(stream, streams) {
2017 stream->orig_out_fn = stream->config.out_fn;
2018 stream->orig_width = stream->config.cfg.g_w;
2019 stream->orig_height = stream->config.cfg.g_h;
2020 stream->orig_write_ivf = stream->config.write_ivf;
2021 stream->orig_write_webm = stream->config.write_webm;
2024 if (!input.filename) {
2025 fprintf(stderr,
"No input file specified!\n");
2030 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC)
2031 input.only_i420 = 0;
2033 for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
2035 FOREACH_STREAM(stream, streams) { clear_stream_count_state(stream); }
2038 int frames_in = 0, seen_frames = 0;
2039 int64_t estimated_time_left = -1;
2040 int64_t average_rate = -1;
2041 int64_t lagged_count = 0;
2042 const int need_downscale =
2043 pass_need_downscale(global.pass, global.passes, pass);
2047 FOREACH_STREAM(stream, streams) {
2048 if (need_downscale) {
2049 stream->config.out_fn = stream->config.two_pass_output;
2051 stream->config.write_ivf = 1;
2052 stream->config.write_webm = 0;
2054 stream->config.out_fn = stream->orig_out_fn;
2055 stream->config.write_ivf = stream->orig_write_ivf;
2056 stream->config.write_webm = stream->orig_write_webm;
2058 stream->config.cfg.g_w = stream->orig_width;
2059 stream->config.cfg.g_h = stream->orig_height;
2065 input.filename = orig_input_filename;
2066 const char *two_pass_input = NULL;
2067 if (need_downscale) {
2068 FOREACH_STREAM(stream, streams) {
2069 if (stream->config.two_pass_input) {
2070 two_pass_input = stream->config.two_pass_input;
2071 input.filename = two_pass_input;
2077 open_input_file(&input, global.csp);
2082 if (!input.width || !input.height) {
2083 if (two_pass_input) {
2084 FOREACH_STREAM(stream, streams) {
2085 if (stream->config.two_pass_width && stream->config.two_pass_height) {
2086 input.width = stream->config.two_pass_width;
2087 input.height = stream->config.two_pass_height;
2092 FOREACH_STREAM(stream, streams) {
2093 if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
2094 input.width = stream->config.cfg.g_w;
2095 input.height = stream->config.cfg.g_h;
2103 if (!input.width || !input.height) {
2104 if (two_pass_input) {
2106 "Specify downscaled stream dimensions with --two-pass-width "
2107 " and --two-pass-height");
2110 "Specify stream dimensions with --width (-w) "
2111 " and --height (-h)");
2115 if (need_downscale) {
2116 FOREACH_STREAM(stream, streams) {
2117 if (stream->config.two_pass_width && stream->config.two_pass_height) {
2118 stream->config.cfg.g_w = stream->config.two_pass_width;
2119 stream->config.cfg.g_h = stream->config.two_pass_height;
2120 }
else if (two_pass_input) {
2121 stream->config.cfg.g_w = input.width;
2122 stream->config.cfg.g_h = input.height;
2123 }
else if (stream->orig_width && stream->orig_height) {
2124 stream->config.cfg.g_w = (stream->orig_width + 1) / 2;
2125 stream->config.cfg.g_h = (stream->orig_height + 1) / 2;
2127 stream->config.cfg.g_w = (input.width + 1) / 2;
2128 stream->config.cfg.g_h = (input.height + 1) / 2;
2138 if (!input.bit_depth) {
2139 FOREACH_STREAM(stream, streams) {
2140 if (stream->config.cfg.g_input_bit_depth)
2141 input.bit_depth = stream->config.cfg.g_input_bit_depth;
2143 input.bit_depth = stream->config.cfg.g_input_bit_depth =
2144 (int)stream->config.cfg.g_bit_depth;
2148 FOREACH_STREAM(stream, streams) {
2149 stream->config.cfg.g_input_bit_depth = input.bit_depth;
2153 FOREACH_STREAM(stream, streams) {
2157 switch (stream->config.cfg.g_profile) {
2161 if (!stream->config.cfg.monochrome) {
2162 stream->config.cfg.g_profile = 1;
2163 profile_updated = 1;
2165 }
else if (input.bit_depth == 12 ||
2168 !stream->config.cfg.monochrome)) {
2169 stream->config.cfg.g_profile = 2;
2170 profile_updated = 1;
2176 stream->config.cfg.g_profile = 2;
2177 profile_updated = 1;
2178 }
else if (input.bit_depth < 12 &&
2181 stream->config.cfg.g_profile = 0;
2182 profile_updated = 1;
2188 stream->config.cfg.g_profile = 1;
2189 profile_updated = 1;
2190 }
else if (input.bit_depth < 12 &&
2193 stream->config.cfg.g_profile = 0;
2194 profile_updated = 1;
2195 }
else if (input.bit_depth == 12 &&
2196 input.file_type == FILE_TYPE_Y4M) {
2201 input.y4m.dst_c_dec_h >> 1);
2204 input.y4m.dst_c_dec_v >> 1);
2205 }
else if (input.bit_depth == 12 &&
2206 input.file_type == FILE_TYPE_RAW) {
2209 stream->chroma_subsampling_x);
2212 stream->chroma_subsampling_y);
2220 if (stream->config.cfg.g_input_bit_depth >
2221 (
unsigned int)stream->config.cfg.g_bit_depth) {
2222 stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
2223 if (!global.quiet) {
2225 "Warning: automatically updating bit depth to %d to "
2226 "match input format.\n",
2227 stream->config.cfg.g_input_bit_depth);
2230 #if !CONFIG_AV1_HIGHBITDEPTH
2231 if (stream->config.cfg.g_bit_depth > 8) {
2232 fatal(
"Unsupported bit-depth with CONFIG_AV1_HIGHBITDEPTH=0\n");
2235 if (stream->config.cfg.g_bit_depth > 10) {
2236 switch (stream->config.cfg.g_profile) {
2239 stream->config.cfg.g_profile = 2;
2240 profile_updated = 1;
2245 if (stream->config.cfg.g_bit_depth > 8) {
2246 stream->config.use_16bit_internal = 1;
2248 if (profile_updated && !global.quiet) {
2250 "Warning: automatically updating to profile %d to "
2251 "match input format.\n",
2252 stream->config.cfg.g_profile);
2254 if ((global.show_psnr == 2) && (stream->config.cfg.g_input_bit_depth ==
2255 stream->config.cfg.g_bit_depth)) {
2257 "Warning: --psnr==2 and --psnr==1 will provide same "
2258 "results when input bit-depth == stream bit-depth, "
2259 "falling back to default psnr value\n");
2260 global.show_psnr = 1;
2262 if (global.show_psnr < 0 || global.show_psnr > 2) {
2264 "Warning: --psnr can take only 0,1,2 as values,"
2265 "falling back to default psnr value\n");
2266 global.show_psnr = 1;
2269 stream->config.cfg.g_limit = global.limit;
2272 FOREACH_STREAM(stream, streams) {
2273 set_stream_dimensions(stream, input.width, input.height);
2274 stream->config.color_range = input.color_range;
2276 FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
2281 if (global.pass > 0 && global.pass <= 3 && global.passes >= 2) {
2282 FOREACH_STREAM(stream, streams) {
2283 if (!stream->config.stats_fn)
2284 die(
"Stream %d: Must specify --fpf when --pass=%d"
2285 " and --passes=%d\n",
2286 stream->index, global.pass, global.passes);
2291 FOREACH_STREAM(stream, streams) {
2292 if (stream->config.write_webm) {
2293 stream->config.write_webm = 0;
2294 stream->config.write_ivf = 0;
2295 aom_tools_warn(
"aomenc compiled w/o WebM support. Writing OBU stream.");
2303 if (!global.have_framerate) {
2304 global.framerate.num = input.framerate.numerator;
2305 global.framerate.den = input.framerate.denominator;
2307 FOREACH_STREAM(stream, streams) {
2308 stream->config.cfg.g_timebase.den = global.framerate.num;
2309 stream->config.cfg.g_timebase.num = global.framerate.den;
2312 if (global.verbose && pass == 0) {
2313 FOREACH_STREAM(stream, streams) {
2314 show_stream_config(stream, &global, &input);
2318 if (pass == (global.pass ? global.pass - 1 : 0)) {
2320 if (input.file_type != FILE_TYPE_Y4M) {
2321 aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2323 FOREACH_STREAM(stream, streams) {
2325 init_rate_histogram(&stream->config.cfg, &global.framerate);
2329 FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2330 FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2331 FOREACH_STREAM(stream, streams) {
2332 char *encoder_settings = NULL;
2341 if (stream->config.write_webm && !stream->webm_ctx.debug) {
2342 encoder_settings = extract_encoder_settings(
2344 if (encoder_settings == NULL) {
2347 "Warning: unable to extract encoder settings. Continuing...\n");
2351 open_output_file(stream, &global, &input.pixel_aspect_ratio,
2353 free(encoder_settings);
2356 if (strcmp(get_short_name_by_aom_encoder(global.codec),
"av1") == 0) {
2360 FOREACH_STREAM(stream, streams) {
2361 if (stream->config.use_16bit_internal) {
2362 do_16bit_internal = 1;
2364 input_shift = (int)stream->config.cfg.g_bit_depth -
2365 stream->config.cfg.g_input_bit_depth;
2372 while (frame_avail || got_data) {
2373 struct aom_usec_timer timer;
2375 if (!global.limit || frames_in < global.limit) {
2376 frame_avail = read_frame(&input, &raw);
2378 if (frame_avail) frames_in++;
2380 frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2382 if (!global.quiet) {
2383 float fps = usec_to_fps(cx_time, seen_frames);
2384 fprintf(stderr,
"\rPass %d/%d ", pass + 1, global.passes);
2386 if (stream_cnt == 1)
2387 fprintf(stderr,
"frame %4d/%-4d %7" PRId64
"B ", frames_in,
2388 streams->frames_out, (int64_t)streams->nbytes);
2390 fprintf(stderr,
"frame %4d ", frames_in);
2392 fprintf(stderr,
"%7" PRId64
" %s %.2f %s ",
2393 cx_time > 9999999 ? cx_time / 1000 : cx_time,
2394 cx_time > 9999999 ?
"ms" :
"us", fps >= 1.0 ? fps : fps * 60,
2395 fps >= 1.0 ?
"fps" :
"fpm");
2396 print_time(
"ETA", estimated_time_left);
2408 if (frames_in > global.skip_frames) {
2410 if (input_shift || (do_16bit_internal && input.bit_depth == 8)) {
2411 assert(do_16bit_internal);
2414 if (!allocated_raw_shift) {
2416 input.width, input.height, 32);
2417 allocated_raw_shift = 1;
2419 aom_img_upshift(&raw_shift, &raw, input_shift);
2420 frame_to_encode = &raw_shift;
2422 frame_to_encode = &raw;
2424 aom_usec_timer_start(&timer);
2425 if (do_16bit_internal) {
2427 FOREACH_STREAM(stream, streams) {
2428 if (stream->config.use_16bit_internal)
2429 encode_frame(stream, &global,
2430 frame_avail ? frame_to_encode : NULL, frames_in);
2436 FOREACH_STREAM(stream, streams) {
2437 encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2441 aom_usec_timer_mark(&timer);
2442 cx_time += aom_usec_timer_elapsed(&timer);
2444 FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2447 FOREACH_STREAM(stream, streams) {
2448 get_cx_data(stream, &global, &got_data);
2451 if (!got_data && input.length && streams != NULL &&
2452 !streams->frames_out) {
2453 lagged_count = global.limit ? seen_frames : ftello(input.file);
2454 }
else if (input.length) {
2459 const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2461 rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2462 remaining = 1000 * (global.limit - global.skip_frames -
2463 seen_frames + lagged_count);
2465 const int64_t input_pos = ftello(input.file);
2466 const int64_t input_pos_lagged = input_pos - lagged_count;
2467 const int64_t input_limit = input.length;
2469 rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2470 remaining = input_limit - input_pos + lagged_count;
2474 (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2475 estimated_time_left = average_rate ? remaining / average_rate : -1;
2478 if (got_data && global.test_decode != TEST_DECODE_OFF) {
2479 FOREACH_STREAM(stream, streams) {
2480 test_decode(stream, global.test_decode);
2486 if (!global.quiet) fprintf(stderr,
"\033[K");
2489 if (stream_cnt > 1) fprintf(stderr,
"\n");
2491 if (!global.quiet) {
2492 FOREACH_STREAM(stream, streams) {
2494 seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2495 const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2497 "\rPass %d/%d frame %4d/%-4d %7" PRId64
"B %7" PRId64
2500 " %7" PRId64
" %s (%.2f fps)\033[K\n",
2501 pass + 1, global.passes, frames_in, stream->frames_out,
2502 (int64_t)stream->nbytes, bpf, bps,
2503 stream->cx_time > 9999999 ? stream->cx_time / 1000
2505 stream->cx_time > 9999999 ?
"ms" :
"us",
2506 usec_to_fps(stream->cx_time, seen_frames));
2512 if (global.show_psnr >= 1) {
2513 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) {
2514 FOREACH_STREAM(stream, streams) {
2516 if (global.show_psnr == 1) {
2517 if (stream->psnr_count[0] && seen_frames && global.framerate.den) {
2518 bps = (int64_t)stream->nbytes * 8 *
2519 (int64_t)global.framerate.num / global.framerate.den /
2522 show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2525 if (global.show_psnr == 2) {
2526 #if CONFIG_AV1_HIGHBITDEPTH
2527 if (stream->config.cfg.g_input_bit_depth <
2528 (
unsigned int)stream->config.cfg.g_bit_depth)
2529 show_psnr_hbd(stream, (1 << stream->config.cfg.g_bit_depth) - 1,
2535 FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2541 if (global.test_decode != TEST_DECODE_OFF) {
2545 close_input_file(&input);
2547 if (global.test_decode == TEST_DECODE_FATAL) {
2548 FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2550 FOREACH_STREAM(stream, streams) {
2551 close_output_file(stream, get_fourcc_by_aom_encoder(global.codec));
2554 FOREACH_STREAM(stream, streams) {
2555 stats_close(&stream->stats, global.passes - 1);
2558 if (global.pass)
break;
2561 if (global.show_q_hist_buckets) {
2562 FOREACH_STREAM(stream, streams) {
2563 show_q_histogram(stream->counts, global.show_q_hist_buckets);
2567 if (global.show_rate_hist_buckets) {
2568 FOREACH_STREAM(stream, streams) {
2569 show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2570 global.show_rate_hist_buckets);
2573 FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2575 #if CONFIG_INTERNAL_STATS
2579 if (!(global.pass == 1 && global.passes == 2)) {
2580 FOREACH_STREAM(stream, streams) {
2581 FILE *f = fopen(
"opsnr.stt",
"a");
2582 if (stream->mismatch_seen) {
2583 fprintf(f,
"First mismatch occurred in frame %d\n",
2584 stream->mismatch_seen);
2586 fprintf(f,
"No mismatch detected in recon buffers\n");
2597 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:845
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition: aom_encoder.h:858
#define FIXED_QP_OFFSET_COUNT
Number of fixed QP offsets.
Definition: aom_encoder.h:885
#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:567
@ AV1E_SET_ENABLE_INTERINTER_WEDGE
Codec control function to turn on / off interinter wedge compound, int parameter.
Definition: aomcx.h:999
@ AV1E_SET_ENABLE_DIAGONAL_INTRA
Codec control function to turn on / off D45 to D203 intra mode usage, int parameter.
Definition: aomcx.h:1337
@ AV1E_SET_MAX_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:588
@ AV1E_SET_ROW_MT
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition: aomcx.h:355
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition: aomcx.h:1059
@ AOME_SET_SHARPNESS
Codec control function to set the sharpness parameter, unsigned int parameter.
Definition: aomcx.h:235
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition: aomcx.h:402
@ AOME_GET_LAST_QUANTIZER_64
Codec control function to get last quantizer chosen by the encoder, int* parameter.
Definition: aomcx.h:257
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition: aomcx.h:462
@ AV1E_SET_REDUCED_REFERENCE_SET
Control to use reduced set of single and compound references, int parameter.
Definition: aomcx.h:1213
@ AV1E_SET_GF_MIN_PYRAMID_HEIGHT
Control to select minimum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1309
@ AV1E_SET_ENABLE_PAETH_INTRA
Codec control function to turn on / off Paeth intra mode usage, int parameter.
Definition: aomcx.h:1067
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition: aomcx.h:491
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition: aomcx.h:500
@ AV1E_SET_CHROMA_SUBSAMPLING_X
Sets the chroma subsampling x value, unsigned int parameter.
Definition: aomcx.h:1176
@ AV1E_SET_COLOR_RANGE
Codec control function to set color range bit, int parameter.
Definition: aomcx.h:600
@ AV1E_SET_ENABLE_RESTORATION
Codec control function to encode with Loop Restoration Filter, unsigned int parameter.
Definition: aomcx.h:669
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition: aomcx.h:1106
@ AV1E_SET_MIN_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:581
@ AOME_SET_ARNR_MAXFRAMES
Codec control function to set the max no of frames to create arf, unsigned int parameter.
Definition: aomcx.h:262
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition: aomcx.h:1243
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition: aomcx.h:1192
@ AV1E_SET_TRANSFER_CHARACTERISTICS
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:546
@ AV1E_SET_MTU
Codec control function to set an MTU size for a tile group, unsigned int parameter.
Definition: aomcx.h:789
@ AV1E_SET_DISABLE_TRELLIS_QUANT
Codec control function to encode without trellis quantization, unsigned int parameter.
Definition: aomcx.h:696
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition: aomcx.h:1102
@ AV1E_SET_ENABLE_AB_PARTITIONS
Codec control function to enable/disable AB partitions, int parameter.
Definition: aomcx.h:807
@ AV1E_SET_ENABLE_INTERINTRA_COMP
Codec control function to turn on / off interintra compound for a sequence, int parameter.
Definition: aomcx.h:975
@ 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:1162
@ AV1E_SET_ENABLE_CHROMA_DELTAQ
Codec control function to turn on / off delta quantization in chroma planes for a sequence,...
Definition: aomcx.h:951
@ AV1E_SET_ENABLE_DUAL_FILTER
Codec control function to turn on / off dual interpolation filter for a sequence, int parameter.
Definition: aomcx.h:943
@ AV1E_SET_FRAME_PARALLEL_DECODING
Codec control function to enable frame parallel decoding feature, unsigned int parameter.
Definition: aomcx.h:425
@ AV1E_SET_MIN_PARTITION_SIZE
Codec control function to set min partition size, int parameter.
Definition: aomcx.h:826
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition: aomcx.h:1027
@ AV1E_SET_FORCE_VIDEO_MODE
Codec control function to force video mode, unsigned int parameter.
Definition: aomcx.h:676
@ AV1E_SET_CHROMA_SUBSAMPLING_Y
Sets the chroma subsampling y value, unsigned int parameter.
Definition: aomcx.h:1179
@ AV1E_SET_ENABLE_INTRA_EDGE_FILTER
Codec control function to turn on / off intra edge filter at sequence level, int parameter.
Definition: aomcx.h:845
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition: aomcx.h:1223
@ AV1E_SET_ENABLE_DIRECTIONAL_INTRA
Codec control function to turn on / off directional intra mode usage, int parameter.
Definition: aomcx.h:1366
@ AV1E_SET_MAX_INTER_BITRATE_PCT
Codec control function to set max data rate for inter frames, unsigned int parameter.
Definition: aomcx.h:319
@ AV1E_SET_DENOISE_NOISE_LEVEL
Sets the noise level, int parameter.
Definition: aomcx.h:1170
@ AV1E_SET_INTRA_DCT_ONLY
Control to use dct only for intra modes, int parameter.
Definition: aomcx.h:1185
@ AV1E_SET_TILE_ROWS
Codec control function to set number of tile rows, unsigned int parameter.
Definition: aomcx.h:392
@ AV1E_SET_ENABLE_REF_FRAME_MVS
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level,...
Definition: aomcx.h:924
@ 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:959
@ 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:1314
@ AV1E_SET_GF_MAX_PYRAMID_HEIGHT
Control to select maximum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1202
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition: aomcx.h:659
@ AV1E_SET_ENABLE_FLIP_IDTX
Codec control function to turn on / off flip and identity transforms, int parameter.
Definition: aomcx.h:889
@ AV1E_SET_FRAME_PERIODIC_BOOST
Codec control function to enable/disable periodic Q boost, unsigned int parameter.
Definition: aomcx.h:474
@ AV1E_SET_DV_COST_UPD_FREQ
Control to set frequency of the cost updates for intrabc motion vectors, unsigned int parameter.
Definition: aomcx.h:1347
@ AV1E_SET_ENABLE_RECT_TX
Codec control function to turn on / off rectangular transforms, int parameter.
Definition: aomcx.h:901
@ 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:913
@ 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:1155
@ AV1E_SET_SUPERBLOCK_SIZE
Codec control function to set intended superblock size, unsigned int parameter.
Definition: aomcx.h:641
@ 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:1251
@ AV1E_SET_ENABLE_INTERINTRA_WEDGE
Codec control function to turn on / off interintra wedge compound, int parameter.
Definition: aomcx.h:1007
@ AV1E_SET_NOISE_SENSITIVITY
Codec control function to set noise sensitivity, unsigned int parameter.
Definition: aomcx.h:482
@ AV1E_SET_ENABLE_DIFF_WTD_COMP
Codec control function to turn on / off difference weighted compound, int parameter.
Definition: aomcx.h:991
@ AV1E_SET_QUANT_B_ADAPT
Control to use adaptive quantize_b, int parameter.
Definition: aomcx.h:1195
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition: aomcx.h:1048
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition: aomcx.h:1098
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition: aomcx.h:1077
@ AV1E_SET_ENABLE_KEYFRAME_FILTERING
Codec control function to enable temporal filtering on key frame, unsigned int parameter.
Definition: aomcx.h:411
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition: aomcx.h:778
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition: aomcx.h:300
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition: aomcx.h:436
@ AV1E_SET_ENABLE_SMOOTH_INTERINTRA
Codec control function to turn on / off smooth inter-intra mode for a sequence, int parameter.
Definition: aomcx.h:983
@ AOME_SET_STATIC_THRESHOLD
Codec control function to set the threshold for MBs treated static, unsigned int parameter.
Definition: aomcx.h:240
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition: aomcx.h:686
@ AV1E_SET_PARTITION_INFO_PATH
Codec control to set the path for partition stats read and write. const char * parameter.
Definition: aomcx.h:1352
@ AV1E_SET_MAX_PARTITION_SIZE
Codec control function to set max partition size, int parameter.
Definition: aomcx.h:837
@ AV1E_SET_ENABLE_1TO4_PARTITIONS
Codec control function to enable/disable 1:4 and 4:1 partitions, int parameter.
Definition: aomcx.h:815
@ AV1E_SET_DELTALF_MODE
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled,...
Definition: aomcx.h:1128
@ AV1E_SET_ENABLE_TX64
Codec control function to turn on / off 64-length transforms, int parameter.
Definition: aomcx.h:865
@ AOME_SET_TUNING
Codec control function to set visual tuning, aom_tune_metric (int) parameter.
Definition: aomcx.h:276
@ 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:626
@ 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:574
@ AV1E_SET_REDUCED_TX_TYPE_SET
Control to use a reduced tx type set, int parameter.
Definition: aomcx.h:1182
@ AV1E_SET_INTER_DCT_ONLY
Control to use dct only for inter modes, int parameter.
Definition: aomcx.h:1188
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition: aomcx.h:222
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition: aomcx.h:374
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition: aomcx.h:854
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition: aomcx.h:1120
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition: aomcx.h:1017
@ AV1E_SET_FILM_GRAIN_TABLE
Codec control function to set the path to the film grain parameters, const char* parameter.
Definition: aomcx.h:1167
@ AV1E_SET_QM_MAX
Codec control function to set the max quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:732
@ AV1E_SET_MAX_REFERENCE_FRAMES
Control to select maximum reference frames allowed per frame, int parameter.
Definition: aomcx.h:1209
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition: aomcx.h:214
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition: aomcx.h:333
@ AV1E_SET_ENABLE_ONESIDED_COMP
Codec control function to turn on / off one sided compound usage for a sequence, int parameter.
Definition: aomcx.h:967
@ AV1E_SET_DENOISE_BLOCK_SIZE
Sets the denoisers block size, unsigned int parameter.
Definition: aomcx.h:1173
@ 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:1281
@ AV1E_SET_QM_MIN
Codec control function to set the min quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:720
@ AV1E_SET_ENABLE_QM
Codec control function to encode with quantisation matrices, unsigned int parameter.
Definition: aomcx.h:707
@ AV1E_SET_ENABLE_OVERLAY
Codec control function to turn on / off overlay frames for filtered ALTREF frames,...
Definition: aomcx.h:1095
@ AV1E_SET_ENABLE_RECT_PARTITIONS
Codec control function to enable/disable rectangular partitions, int parameter.
Definition: aomcx.h:799
@ AV1E_SET_COLOR_PRIMARIES
Codec control function to set color space info, int parameter.
Definition: aomcx.h:521
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition: aomcx.h:286
@ AV1E_SET_ENABLE_TX_SIZE_SEARCH
Control to turn on / off transform size search.
Definition: aomcx.h:1373
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition: aomcx.h:1233
@ AV1E_SET_MIN_CR
Control to set minimum compression ratio, unsigned int parameter Take integer values....
Definition: aomcx.h:1258
@ AV1E_SET_LOSSLESS
Codec control function to set lossless encoding mode, unsigned int parameter.
Definition: aomcx.h:347
@ AOME_SET_ARNR_STRENGTH
Codec control function to set the filter strength for the arf, unsigned int parameter.
Definition: aomcx.h:267
@ 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.
aom_codec_err_t aom_codec_set_option(aom_codec_ctx_t *ctx, const char *name, const char *value)
Key & Value API.
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:1011
#define AOM_USAGE_ALL_INTRA
usage parameter analogous to AV1 all intra mode.
Definition: aom_encoder.h:1015
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:940
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:1013
#define AOM_CODEC_USE_HIGHBITDEPTH
Make the encoder output one partition at a time.
Definition: aom_encoder.h:71
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition: aom_encoder.h:69
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:166
@ AOM_RC_SECOND_PASS
Definition: aom_encoder.h:168
@ AOM_RC_THIRD_PASS
Definition: aom_encoder.h:169
@ AOM_RC_FIRST_PASS
Definition: aom_encoder.h:167
@ AOM_KF_DISABLED
Definition: aom_encoder.h:192
@ AOM_CODEC_PSNR_PKT
Definition: aom_encoder.h:102
@ AOM_CODEC_CX_FRAME_PKT
Definition: aom_encoder.h:99
@ AOM_CODEC_STATS_PKT
Definition: aom_encoder.h:100
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:111
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:112
double psnr[4]
Definition: aom_encoder.h:134
aom_fixed_buf_t twopass_stats
Definition: aom_encoder.h:129
aom_fixed_buf_t raw
Definition: aom_encoder.h:145
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:376
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:473
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:424
unsigned int monochrome
Monochrome mode.
Definition: aom_encoder.h:806
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:415
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: aom_encoder.h:488
size_t sz
Definition: aom_encoder.h:79
void * buf
Definition: aom_encoder.h:78
Image Descriptor.
Definition: aom_image.h:171
aom_chroma_sample_position_t csp
Definition: aom_image.h:177
unsigned int y_chroma_shift
Definition: aom_image.h:195
aom_img_fmt_t fmt
Definition: aom_image.h:172
int stride[3]
Definition: aom_image.h:203
unsigned char * img_data
Definition: aom_image.h:217
unsigned int x_chroma_shift
Definition: aom_image.h:194
unsigned int d_w
Definition: aom_image.h:186
int bps
Definition: aom_image.h:206
int monochrome
Definition: aom_image.h:176
unsigned int d_h
Definition: aom_image.h:187
unsigned char * planes[3]
Definition: aom_image.h:202
int img_data_owner
Definition: aom_image.h:218
int self_allocd
Definition: aom_image.h:219
size_t sz
Definition: aom_image.h:204
Rational Number.
Definition: aom_encoder.h:153
int num
Definition: aom_encoder.h:154
int den
Definition: aom_encoder.h:155
Encoder Config Options.
Definition: aom_encoder.h:216
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:232
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:228
unsigned int disable_trellis_quant
disable trellis quantization
Definition: aom_encoder.h:344
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition: aom_encoder.h:224