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,
217 #endif // CONFIG_DENOISE 232 const arg_def_t *main_args[] = { &g_av1_codec_arg_defs.help,
233 &g_av1_codec_arg_defs.use_cfg,
234 &g_av1_codec_arg_defs.debugmode,
235 &g_av1_codec_arg_defs.outputfile,
236 &g_av1_codec_arg_defs.codecarg,
237 &g_av1_codec_arg_defs.passes,
238 &g_av1_codec_arg_defs.pass_arg,
239 &g_av1_codec_arg_defs.fpf_name,
240 &g_av1_codec_arg_defs.limit,
241 &g_av1_codec_arg_defs.skip,
242 &g_av1_codec_arg_defs.good_dl,
243 &g_av1_codec_arg_defs.rt_dl,
244 &g_av1_codec_arg_defs.ai_dl,
245 &g_av1_codec_arg_defs.quietarg,
246 &g_av1_codec_arg_defs.verbosearg,
247 &g_av1_codec_arg_defs.psnrarg,
248 &g_av1_codec_arg_defs.use_webm,
249 &g_av1_codec_arg_defs.use_ivf,
250 &g_av1_codec_arg_defs.use_obu,
251 &g_av1_codec_arg_defs.q_hist_n,
252 &g_av1_codec_arg_defs.rate_hist_n,
253 &g_av1_codec_arg_defs.disable_warnings,
254 &g_av1_codec_arg_defs.disable_warning_prompt,
255 &g_av1_codec_arg_defs.recontest,
258 const arg_def_t *global_args[] = {
259 &g_av1_codec_arg_defs.use_yv12,
260 &g_av1_codec_arg_defs.use_i420,
261 &g_av1_codec_arg_defs.use_i422,
262 &g_av1_codec_arg_defs.use_i444,
263 &g_av1_codec_arg_defs.usage,
264 &g_av1_codec_arg_defs.threads,
265 &g_av1_codec_arg_defs.profile,
266 &g_av1_codec_arg_defs.width,
267 &g_av1_codec_arg_defs.height,
268 &g_av1_codec_arg_defs.forced_max_frame_width,
269 &g_av1_codec_arg_defs.forced_max_frame_height,
271 &g_av1_codec_arg_defs.stereo_mode,
273 &g_av1_codec_arg_defs.timebase,
274 &g_av1_codec_arg_defs.framerate,
275 &g_av1_codec_arg_defs.global_error_resilient,
276 &g_av1_codec_arg_defs.bitdeptharg,
277 &g_av1_codec_arg_defs.inbitdeptharg,
278 &g_av1_codec_arg_defs.lag_in_frames,
279 &g_av1_codec_arg_defs.large_scale_tile,
280 &g_av1_codec_arg_defs.monochrome,
281 &g_av1_codec_arg_defs.full_still_picture_hdr,
282 &g_av1_codec_arg_defs.use_16bit_internal,
283 &g_av1_codec_arg_defs.save_as_annexb,
287 const arg_def_t *rc_args[] = { &g_av1_codec_arg_defs.dropframe_thresh,
288 &g_av1_codec_arg_defs.resize_mode,
289 &g_av1_codec_arg_defs.resize_denominator,
290 &g_av1_codec_arg_defs.resize_kf_denominator,
291 &g_av1_codec_arg_defs.superres_mode,
292 &g_av1_codec_arg_defs.superres_denominator,
293 &g_av1_codec_arg_defs.superres_kf_denominator,
294 &g_av1_codec_arg_defs.superres_qthresh,
295 &g_av1_codec_arg_defs.superres_kf_qthresh,
296 &g_av1_codec_arg_defs.end_usage,
297 &g_av1_codec_arg_defs.target_bitrate,
298 &g_av1_codec_arg_defs.min_quantizer,
299 &g_av1_codec_arg_defs.max_quantizer,
300 &g_av1_codec_arg_defs.undershoot_pct,
301 &g_av1_codec_arg_defs.overshoot_pct,
302 &g_av1_codec_arg_defs.buf_sz,
303 &g_av1_codec_arg_defs.buf_initial_sz,
304 &g_av1_codec_arg_defs.buf_optimal_sz,
305 &g_av1_codec_arg_defs.bias_pct,
306 &g_av1_codec_arg_defs.minsection_pct,
307 &g_av1_codec_arg_defs.maxsection_pct,
310 const arg_def_t *kf_args[] = { &g_av1_codec_arg_defs.fwd_kf_enabled,
311 &g_av1_codec_arg_defs.kf_min_dist,
312 &g_av1_codec_arg_defs.kf_max_dist,
313 &g_av1_codec_arg_defs.kf_disabled,
314 &g_av1_codec_arg_defs.sframe_dist,
315 &g_av1_codec_arg_defs.sframe_mode,
320 const arg_def_t *av1_ctrl_args[] = {
321 &g_av1_codec_arg_defs.cpu_used_av1,
322 &g_av1_codec_arg_defs.auto_altref,
323 &g_av1_codec_arg_defs.sharpness,
324 &g_av1_codec_arg_defs.static_thresh,
325 &g_av1_codec_arg_defs.rowmtarg,
326 &g_av1_codec_arg_defs.tile_cols,
327 &g_av1_codec_arg_defs.tile_rows,
328 &g_av1_codec_arg_defs.enable_tpl_model,
329 &g_av1_codec_arg_defs.enable_keyframe_filtering,
330 &g_av1_codec_arg_defs.arnr_maxframes,
331 &g_av1_codec_arg_defs.arnr_strength,
332 &g_av1_codec_arg_defs.tune_metric,
333 &g_av1_codec_arg_defs.cq_level,
334 &g_av1_codec_arg_defs.max_intra_rate_pct,
335 &g_av1_codec_arg_defs.max_inter_rate_pct,
336 &g_av1_codec_arg_defs.gf_cbr_boost_pct,
337 &g_av1_codec_arg_defs.lossless,
338 &g_av1_codec_arg_defs.enable_cdef,
339 &g_av1_codec_arg_defs.enable_restoration,
340 &g_av1_codec_arg_defs.enable_rect_partitions,
341 &g_av1_codec_arg_defs.enable_ab_partitions,
342 &g_av1_codec_arg_defs.enable_1to4_partitions,
343 &g_av1_codec_arg_defs.min_partition_size,
344 &g_av1_codec_arg_defs.max_partition_size,
345 &g_av1_codec_arg_defs.enable_dual_filter,
346 &g_av1_codec_arg_defs.enable_chroma_deltaq,
347 &g_av1_codec_arg_defs.enable_intra_edge_filter,
348 &g_av1_codec_arg_defs.enable_order_hint,
349 &g_av1_codec_arg_defs.enable_tx64,
350 &g_av1_codec_arg_defs.enable_flip_idtx,
351 &g_av1_codec_arg_defs.enable_rect_tx,
352 &g_av1_codec_arg_defs.enable_dist_wtd_comp,
353 &g_av1_codec_arg_defs.enable_masked_comp,
354 &g_av1_codec_arg_defs.enable_onesided_comp,
355 &g_av1_codec_arg_defs.enable_interintra_comp,
356 &g_av1_codec_arg_defs.enable_smooth_interintra,
357 &g_av1_codec_arg_defs.enable_diff_wtd_comp,
358 &g_av1_codec_arg_defs.enable_interinter_wedge,
359 &g_av1_codec_arg_defs.enable_interintra_wedge,
360 &g_av1_codec_arg_defs.enable_global_motion,
361 &g_av1_codec_arg_defs.enable_warped_motion,
362 &g_av1_codec_arg_defs.enable_filter_intra,
363 &g_av1_codec_arg_defs.enable_smooth_intra,
364 &g_av1_codec_arg_defs.enable_paeth_intra,
365 &g_av1_codec_arg_defs.enable_cfl_intra,
366 &g_av1_codec_arg_defs.enable_diagonal_intra,
367 &g_av1_codec_arg_defs.force_video_mode,
368 &g_av1_codec_arg_defs.enable_obmc,
369 &g_av1_codec_arg_defs.enable_overlay,
370 &g_av1_codec_arg_defs.enable_palette,
371 &g_av1_codec_arg_defs.enable_intrabc,
372 &g_av1_codec_arg_defs.enable_angle_delta,
373 &g_av1_codec_arg_defs.disable_trellis_quant,
374 &g_av1_codec_arg_defs.enable_qm,
375 &g_av1_codec_arg_defs.qm_min,
376 &g_av1_codec_arg_defs.qm_max,
377 &g_av1_codec_arg_defs.reduced_tx_type_set,
378 &g_av1_codec_arg_defs.use_intra_dct_only,
379 &g_av1_codec_arg_defs.use_inter_dct_only,
380 &g_av1_codec_arg_defs.use_intra_default_tx_only,
381 &g_av1_codec_arg_defs.quant_b_adapt,
382 &g_av1_codec_arg_defs.coeff_cost_upd_freq,
383 &g_av1_codec_arg_defs.mode_cost_upd_freq,
384 &g_av1_codec_arg_defs.mv_cost_upd_freq,
385 &g_av1_codec_arg_defs.frame_parallel_decoding,
386 &g_av1_codec_arg_defs.error_resilient_mode,
387 &g_av1_codec_arg_defs.aq_mode,
388 &g_av1_codec_arg_defs.deltaq_mode,
389 &g_av1_codec_arg_defs.deltalf_mode,
390 &g_av1_codec_arg_defs.frame_periodic_boost,
391 &g_av1_codec_arg_defs.noise_sens,
392 &g_av1_codec_arg_defs.tune_content,
393 &g_av1_codec_arg_defs.cdf_update_mode,
394 &g_av1_codec_arg_defs.input_color_primaries,
395 &g_av1_codec_arg_defs.input_transfer_characteristics,
396 &g_av1_codec_arg_defs.input_matrix_coefficients,
397 &g_av1_codec_arg_defs.input_chroma_sample_position,
398 &g_av1_codec_arg_defs.min_gf_interval,
399 &g_av1_codec_arg_defs.max_gf_interval,
400 &g_av1_codec_arg_defs.gf_min_pyr_height,
401 &g_av1_codec_arg_defs.gf_max_pyr_height,
402 &g_av1_codec_arg_defs.superblock_size,
403 &g_av1_codec_arg_defs.num_tg,
404 &g_av1_codec_arg_defs.mtu_size,
405 &g_av1_codec_arg_defs.timing_info,
406 &g_av1_codec_arg_defs.film_grain_test,
407 &g_av1_codec_arg_defs.film_grain_table,
409 &g_av1_codec_arg_defs.denoise_noise_level,
410 &g_av1_codec_arg_defs.denoise_block_size,
411 &g_av1_codec_arg_defs.enable_dnl_denoising,
412 #endif // CONFIG_DENOISE 413 &g_av1_codec_arg_defs.max_reference_frames,
414 &g_av1_codec_arg_defs.reduced_reference_set,
415 &g_av1_codec_arg_defs.enable_ref_frame_mvs,
416 &g_av1_codec_arg_defs.target_seq_level_idx,
417 &g_av1_codec_arg_defs.set_tier_mask,
418 &g_av1_codec_arg_defs.set_min_cr,
419 &g_av1_codec_arg_defs.vbr_corpus_complexity_lap,
420 &g_av1_codec_arg_defs.input_chroma_subsampling_x,
421 &g_av1_codec_arg_defs.input_chroma_subsampling_y,
423 &g_av1_codec_arg_defs.vmaf_model_path,
428 const arg_def_t *av1_key_val_args[] = {
432 static const arg_def_t *no_args[] = { NULL };
434 static void show_help(FILE *fout,
int shorthelp) {
435 fprintf(fout,
"Usage: %s <options> -o dst_filename src_filename\n",
439 fprintf(fout,
"Use --help to see the full list of options.\n");
443 fprintf(fout,
"\nOptions:\n");
444 arg_show_usage(fout, main_args);
445 fprintf(fout,
"\nEncoder Global Options:\n");
446 arg_show_usage(fout, global_args);
447 fprintf(fout,
"\nRate Control Options:\n");
448 arg_show_usage(fout, rc_args);
449 fprintf(fout,
"\nKeyframe Placement Options:\n");
450 arg_show_usage(fout, kf_args);
451 #if CONFIG_AV1_ENCODER 452 fprintf(fout,
"\nAV1 Specific Options:\n");
453 arg_show_usage(fout, av1_ctrl_args);
454 arg_show_usage(fout, av1_key_val_args);
457 "\nStream timebase (--timebase):\n" 458 " The desired precision of timestamps in the output, expressed\n" 459 " in fractional seconds. Default is 1/1000.\n");
460 fprintf(fout,
"\nIncluded encoders:\n\n");
462 const int num_encoder = get_aom_encoder_count();
463 for (
int i = 0; i < num_encoder; ++i) {
465 const char *defstr = (i == (num_encoder - 1)) ?
"(default)" :
"";
466 fprintf(fout,
" %-6s - %s %s\n", get_short_name_by_aom_encoder(encoder),
469 fprintf(fout,
"\n ");
470 fprintf(fout,
"Use --codec to switch to a non-default encoder.\n\n");
473 void usage_exit(
void) {
474 show_help(stderr, 1);
478 #if CONFIG_AV1_ENCODER 479 #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map) 480 #define ARG_KEY_VAL_CNT_MAX NELEMENTS(av1_key_val_args) 484 typedef int stereo_format_t;
485 struct WebmOutputContext {
491 struct stream_config {
494 const char *stats_fn;
495 stereo_format_t stereo_fmt;
496 int arg_ctrls[ARG_CTRL_CNT_MAX][2];
498 const char *arg_key_vals[ARG_KEY_VAL_CNT_MAX][2];
501 const char *film_grain_filename;
504 int use_16bit_internal;
506 const char *vmaf_model_path;
511 struct stream_state {
513 struct stream_state *next;
514 struct stream_config config;
516 struct rate_hist *rate_hist;
517 struct WebmOutputContext webm_ctx;
518 uint64_t psnr_sse_total[2];
519 uint64_t psnr_samples_total[2];
520 double psnr_totals[2][4];
524 unsigned int frames_out;
531 unsigned int chroma_subsampling_x;
532 unsigned int chroma_subsampling_y;
535 static void validate_positive_rational(
const char *msg,
542 if (rat->
num < 0) die(
"Error: %s must be positive\n", msg);
544 if (!rat->
den) die(
"Error: %s has zero denominator\n", msg);
558 static void parse_global_config(
struct AvxEncoderConfig *global,
char ***argv) {
561 const int num_encoder = get_aom_encoder_count();
562 char **argv_local = (
char **)*argv;
563 if (num_encoder < 1) die(
"Error: no valid encoder available\n");
566 memset(global, 0,
sizeof(*global));
567 global->codec = get_aom_encoder_by_index(num_encoder - 1);
569 global->color_type = I420;
571 global->show_psnr = 0;
573 int cfg_included = 0;
574 init_config(&global->encoder_config);
576 for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
579 if (arg_match(&arg, &g_av1_codec_arg_defs.use_cfg, argi)) {
581 parse_cfg(arg.val, &global->encoder_config);
584 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.help, argi)) {
585 show_help(stdout, 0);
587 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.codecarg, argi)) {
588 global->codec = get_aom_encoder_by_short_name(arg.val);
590 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
591 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.passes, argi)) {
592 global->passes = arg_parse_uint(&arg);
594 if (global->passes < 1 || global->passes > 2)
595 die(
"Error: Invalid number of passes (%d)\n", global->passes);
596 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.pass_arg, argi)) {
597 global->pass = arg_parse_uint(&arg);
599 if (global->pass < 1 || global->pass > 2)
600 die(
"Error: Invalid pass selected (%d)\n", global->pass);
601 }
else if (arg_match(&arg,
602 &g_av1_codec_arg_defs.input_chroma_sample_position,
604 global->csp = arg_parse_enum(&arg);
607 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.usage, argi)) {
608 global->usage = arg_parse_uint(&arg);
609 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.good_dl, argi)) {
611 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rt_dl, argi)) {
613 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.ai_dl, argi)) {
615 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_yv12, argi)) {
616 global->color_type = YV12;
617 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i420, argi)) {
618 global->color_type = I420;
619 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i422, argi)) {
620 global->color_type = I422;
621 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i444, argi)) {
622 global->color_type = I444;
623 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.quietarg, argi)) {
625 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.verbosearg, argi)) {
627 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.limit, argi)) {
628 global->limit = arg_parse_uint(&arg);
629 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.skip, argi)) {
630 global->skip_frames = arg_parse_uint(&arg);
631 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.psnrarg, argi)) {
633 global->show_psnr = arg_parse_int(&arg);
635 global->show_psnr = 1;
636 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.recontest, argi)) {
637 global->test_decode = arg_parse_enum_or_int(&arg);
638 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.framerate, argi)) {
639 global->framerate = arg_parse_rational(&arg);
640 validate_positive_rational(arg.name, &global->framerate);
641 global->have_framerate = 1;
642 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.debugmode, argi)) {
644 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.q_hist_n, argi)) {
645 global->show_q_hist_buckets = arg_parse_uint(&arg);
646 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_hist_n, argi)) {
647 global->show_rate_hist_buckets = arg_parse_uint(&arg);
648 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warnings, argi)) {
649 global->disable_warnings = 1;
650 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warning_prompt,
652 global->disable_warning_prompt = 1;
660 if (global->pass > global->passes) {
661 warn(
"Assuming --pass=%d implies --passes=%d\n", global->pass,
663 global->passes = global->pass;
667 if (global->passes == 0) {
668 #if CONFIG_AV1_ENCODER 671 if (global->codec != NULL)
673 (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0 &&
683 warn(
"Enforcing one-pass encoding in realtime mode\n");
688 warn(
"Enforcing one-pass encoding in all intra mode\n");
693 static void open_input_file(
struct AvxInputContext *input,
696 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
697 : set_binary_mode(stdin);
699 if (!input->file) fatal(
"Failed to open input file");
701 if (!fseeko(input->file, 0, SEEK_END)) {
705 input->length = ftello(input->file);
710 input->pixel_aspect_ratio.numerator = 1;
711 input->pixel_aspect_ratio.denominator = 1;
716 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
717 input->detect.position = 0;
719 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
720 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
721 input->only_i420) >= 0) {
722 input->file_type = FILE_TYPE_Y4M;
723 input->width = input->y4m.pic_w;
724 input->height = input->y4m.pic_h;
725 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
726 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
727 input->framerate.numerator = input->y4m.fps_n;
728 input->framerate.denominator = input->y4m.fps_d;
729 input->fmt = input->y4m.aom_fmt;
730 input->bit_depth = input->y4m.bit_depth;
731 input->color_range = input->y4m.color_range;
733 fatal(
"Unsupported Y4M stream.");
734 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
735 fatal(
"IVF is not supported as input.");
737 input->file_type = FILE_TYPE_RAW;
741 static void close_input_file(
struct AvxInputContext *input) {
743 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
746 static struct stream_state *new_stream(
struct AvxEncoderConfig *global,
747 struct stream_state *prev) {
748 struct stream_state *stream;
750 stream = calloc(1,
sizeof(*stream));
751 if (stream == NULL) {
752 fatal(
"Failed to allocate new stream.");
756 memcpy(stream, prev,
sizeof(*stream));
770 stream->config.cfg.g_timebase.den = 1000;
775 stream->config.cfg.g_w = 0;
776 stream->config.cfg.g_h = 0;
779 stream->config.write_webm = 1;
780 stream->config.write_ivf = 0;
783 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
784 stream->webm_ctx.last_pts_ns = -1;
785 stream->webm_ctx.writer = NULL;
786 stream->webm_ctx.segment = NULL;
790 stream->webm_ctx.debug = global->debug;
791 memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
792 sizeof(stream->config.cfg.encoder_cfg));
796 stream->config.out_fn = NULL;
802 static void set_config_arg_ctrls(
struct stream_config *config,
int key,
803 const struct arg *arg) {
806 config->film_grain_filename = arg->val;
813 j = config->arg_ctrl_cnt;
814 assert(j < ARG_CTRL_CNT_MAX);
815 config->arg_ctrls[j][0] = key;
816 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
817 ++config->arg_ctrl_cnt;
824 for (j = 0; j < config->arg_ctrl_cnt; j++)
825 if (config->arg_ctrls[j][0] == key)
break;
828 assert(j < ARG_CTRL_CNT_MAX);
829 config->arg_ctrls[j][0] = key;
830 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
833 warn(
"auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
834 config->arg_ctrls[j][1] = 1;
837 if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
840 static void set_config_arg_key_vals(
struct stream_config *config,
841 const char *name,
const struct arg *arg) {
843 const char *val = arg->val;
846 if (strcmp(name,
"target-seq-level-idx") == 0) {
847 j = config->arg_key_val_cnt;
848 assert(j < ARG_KEY_VAL_CNT_MAX);
849 config->arg_key_vals[j][0] = name;
850 config->arg_key_vals[j][1] = val;
851 ++config->arg_key_val_cnt;
858 for (j = 0; j < config->arg_key_val_cnt; j++)
859 if (strcmp(name, config->arg_key_vals[j][0]) == 0)
break;
862 assert(j < ARG_KEY_VAL_CNT_MAX);
863 config->arg_key_vals[j][0] = name;
864 config->arg_key_vals[j][1] = val;
866 if (strcmp(name, g_av1_codec_arg_defs.auto_altref.long_name) == 0) {
867 int auto_altref = arg_parse_int(arg);
868 if (auto_altref > 1) {
869 warn(
"auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
870 config->arg_key_vals[j][1] =
"1";
874 if (j == config->arg_key_val_cnt) config->arg_key_val_cnt++;
877 static int parse_stream_params(
struct AvxEncoderConfig *global,
878 struct stream_state *stream,
char **argv) {
881 static const arg_def_t **ctrl_args = no_args;
882 static const arg_def_t **key_val_args = no_args;
883 static const int *ctrl_args_map = NULL;
884 struct stream_config *config = &stream->config;
885 int eos_mark_found = 0;
890 #if CONFIG_AV1_ENCODER 891 }
else if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
894 ctrl_args = av1_ctrl_args;
895 ctrl_args_map = av1_arg_ctrl_map;
896 key_val_args = av1_key_val_args;
900 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
906 if (eos_mark_found) {
909 }
else if (!strcmp(*argj,
"--")) {
914 if (arg_match(&arg, &g_av1_codec_arg_defs.outputfile, argi)) {
915 config->out_fn = arg.val;
917 const size_t out_fn_len = strlen(config->out_fn);
918 if (out_fn_len >= 4 &&
919 !strcmp(config->out_fn + out_fn_len - 4,
".ivf")) {
920 config->write_webm = 0;
921 config->write_ivf = 1;
922 }
else if (out_fn_len >= 4 &&
923 !strcmp(config->out_fn + out_fn_len - 4,
".obu")) {
924 config->write_webm = 0;
925 config->write_ivf = 0;
928 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fpf_name, argi)) {
929 config->stats_fn = arg.val;
930 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_webm, argi)) {
932 config->write_webm = 1;
935 die(
"Error: --webm specified but webm is disabled.");
937 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_ivf, argi)) {
938 config->write_webm = 0;
939 config->write_ivf = 1;
940 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_obu, argi)) {
941 config->write_webm = 0;
942 config->write_ivf = 0;
943 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.threads, argi)) {
944 config->cfg.g_threads = arg_parse_uint(&arg);
945 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.profile, argi)) {
946 config->cfg.g_profile = arg_parse_uint(&arg);
947 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.width, argi)) {
948 config->cfg.g_w = arg_parse_uint(&arg);
949 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.height, argi)) {
950 config->cfg.g_h = arg_parse_uint(&arg);
951 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_width,
953 config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
954 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_height,
956 config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
957 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bitdeptharg, argi)) {
958 config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
959 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.inbitdeptharg, argi)) {
960 config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
961 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_x,
963 stream->chroma_subsampling_x = arg_parse_uint(&arg);
964 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_y,
966 stream->chroma_subsampling_y = arg_parse_uint(&arg);
968 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.stereo_mode, argi)) {
969 config->stereo_fmt = arg_parse_enum_or_int(&arg);
971 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.timebase, argi)) {
972 config->cfg.g_timebase = arg_parse_rational(&arg);
973 validate_positive_rational(arg.name, &config->cfg.g_timebase);
974 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.global_error_resilient,
976 config->cfg.g_error_resilient = arg_parse_uint(&arg);
977 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.lag_in_frames, argi)) {
978 config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
979 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.large_scale_tile, argi)) {
980 config->cfg.large_scale_tile = arg_parse_uint(&arg);
981 if (config->cfg.large_scale_tile) {
982 global->codec = get_aom_encoder_by_short_name(
"av1");
984 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.monochrome, argi)) {
985 config->cfg.monochrome = 1;
986 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.full_still_picture_hdr,
988 config->cfg.full_still_picture_hdr = 1;
989 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_16bit_internal,
991 config->use_16bit_internal = CONFIG_AV1_HIGHBITDEPTH;
992 if (!config->use_16bit_internal) {
993 warn(
"%s option ignored with CONFIG_AV1_HIGHBITDEPTH=0.\n", arg.name);
995 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.dropframe_thresh, argi)) {
996 config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
997 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_mode, argi)) {
998 config->cfg.rc_resize_mode = arg_parse_uint(&arg);
999 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_denominator,
1001 config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
1002 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_kf_denominator,
1004 config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
1005 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_mode, argi)) {
1006 config->cfg.rc_superres_mode = arg_parse_uint(&arg);
1007 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_denominator,
1009 config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
1010 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_denominator,
1012 config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
1013 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_qthresh, argi)) {
1014 config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
1015 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_qthresh,
1017 config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
1018 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.end_usage, argi)) {
1019 config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
1020 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.target_bitrate, argi)) {
1021 config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
1022 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.min_quantizer, argi)) {
1023 config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
1024 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.max_quantizer, argi)) {
1025 config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
1026 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.undershoot_pct, argi)) {
1027 config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
1028 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.overshoot_pct, argi)) {
1029 config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
1030 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_sz, argi)) {
1031 config->cfg.rc_buf_sz = arg_parse_uint(&arg);
1032 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_initial_sz, argi)) {
1033 config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
1034 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_optimal_sz, argi)) {
1035 config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
1036 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.bias_pct, argi)) {
1037 config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
1038 if (global->passes < 2)
1039 warn(
"option %s ignored in one-pass mode.\n", arg.name);
1040 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.minsection_pct, argi)) {
1041 config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
1043 if (global->passes < 2)
1044 warn(
"option %s ignored in one-pass mode.\n", arg.name);
1045 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.maxsection_pct, argi)) {
1046 config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
1048 if (global->passes < 2)
1049 warn(
"option %s ignored in one-pass mode.\n", arg.name);
1050 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fwd_kf_enabled, argi)) {
1051 config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
1052 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_min_dist, argi)) {
1053 config->cfg.kf_min_dist = arg_parse_uint(&arg);
1054 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_max_dist, argi)) {
1055 config->cfg.kf_max_dist = arg_parse_uint(&arg);
1056 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_disabled, argi)) {
1058 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_dist, argi)) {
1059 config->cfg.sframe_dist = arg_parse_uint(&arg);
1060 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_mode, argi)) {
1061 config->cfg.sframe_mode = arg_parse_uint(&arg);
1062 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.save_as_annexb, argi)) {
1063 config->cfg.save_as_annexb = arg_parse_uint(&arg);
1064 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_width, argi)) {
1065 config->cfg.tile_width_count =
1067 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_height, argi)) {
1068 config->cfg.tile_height_count =
1070 #if CONFIG_TUNE_VMAF 1071 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argi)) {
1072 config->vmaf_model_path = arg.val;
1074 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.use_fixed_qp_offsets,
1076 config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg);
1077 }
else if (arg_match(&arg, &g_av1_codec_arg_defs.fixed_qp_offsets, argi)) {
1078 const int fixed_qp_offset_count = arg_parse_list(
1081 die(
"Option --fixed_qp_offsets requires %d comma-separated values, but " 1082 "only %d values were provided.\n",
1085 config->cfg.use_fixed_qp_offsets = 1;
1087 arg_match(&arg, &g_av1_codec_arg_defs.enable_restoration,
1089 if (arg_parse_uint(&arg) == 1) {
1090 warn(
"non-zero %s option ignored in realtime mode.\n", arg.name);
1095 if (ctrl_args_map) {
1096 for (i = 0; ctrl_args[i]; i++) {
1097 if (arg_match(&arg, ctrl_args[i], argi)) {
1099 set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1106 for (i = 0; key_val_args[i]; i++) {
1107 if (arg_match(&arg, key_val_args[i], argi)) {
1109 set_config_arg_key_vals(config, key_val_args[i]->long_name, &arg);
1117 config->use_16bit_internal |= config->cfg.g_bit_depth >
AOM_BITS_8;
1120 warn(
"non-zero lag-in-frames option ignored in realtime mode.\n");
1121 config->cfg.g_lag_in_frames = 0;
1125 if (config->cfg.g_lag_in_frames != 0) {
1126 warn(
"non-zero lag-in-frames option ignored in all intra mode.\n");
1127 config->cfg.g_lag_in_frames = 0;
1129 if (config->cfg.kf_max_dist != 0) {
1131 "non-zero max key frame distance option ignored in all intra " 1133 config->cfg.kf_max_dist = 0;
1136 return eos_mark_found;
1139 #define FOREACH_STREAM(iterator, list) \ 1140 for (struct stream_state *iterator = list; iterator; \ 1141 iterator = iterator->next) 1143 static void validate_stream_config(
const struct stream_state *stream,
1144 const struct AvxEncoderConfig *global) {
1145 const struct stream_state *streami;
1148 if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1150 "Stream %d: Specify stream dimensions with --width (-w) " 1151 " and --height (-h)",
1157 assert(stream->config.cfg.g_input_bit_depth <=
1158 (
unsigned int)stream->config.cfg.g_bit_depth);
1160 for (streami = stream; streami; streami = streami->next) {
1162 if (!streami->config.out_fn)
1163 fatal(
"Stream %d: Output file is required (specify with -o)",
1167 if (streami != stream) {
1168 const char *a = stream->config.out_fn;
1169 const char *b = streami->config.out_fn;
1170 if (!strcmp(a, b) && strcmp(a,
"/dev/null") && strcmp(a,
":nul"))
1171 fatal(
"Stream %d: duplicate output file (from stream %d)",
1172 streami->index, stream->index);
1176 if (streami != stream) {
1177 const char *a = stream->config.stats_fn;
1178 const char *b = streami->config.stats_fn;
1179 if (a && b && !strcmp(a, b))
1180 fatal(
"Stream %d: duplicate stats file (from stream %d)",
1181 streami->index, stream->index);
1186 static void set_stream_dimensions(
struct stream_state *stream,
unsigned int w,
1188 if (!stream->config.cfg.g_w) {
1189 if (!stream->config.cfg.g_h)
1190 stream->config.cfg.g_w = w;
1192 stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1194 if (!stream->config.cfg.g_h) {
1195 stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1199 static const char *file_type_to_string(
enum VideoFileType t) {
1201 case FILE_TYPE_RAW:
return "RAW";
1202 case FILE_TYPE_Y4M:
return "Y4M";
1203 default:
return "Other";
1207 static const char *image_format_to_string(
aom_img_fmt_t f) {
1217 default:
return "Other";
1221 static void show_stream_config(
struct stream_state *stream,
1222 struct AvxEncoderConfig *global,
1223 struct AvxInputContext *input) {
1224 #define SHOW(field) \ 1225 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field) 1227 if (stream->index == 0) {
1229 fprintf(stderr,
"Source file: %s File Type: %s Format: %s\n",
1230 input->filename, file_type_to_string(input->file_type),
1231 image_format_to_string(input->fmt));
1233 if (stream->next || stream->index)
1234 fprintf(stderr,
"\nStream Index: %d\n", stream->index);
1235 fprintf(stderr,
"Destination file: %s\n", stream->config.out_fn);
1236 fprintf(stderr,
"Coding path: %s\n",
1237 stream->config.use_16bit_internal ?
"HBD" :
"LBD");
1238 fprintf(stderr,
"Encoder parameters:\n");
1246 SHOW(g_input_bit_depth);
1247 SHOW(g_timebase.num);
1248 SHOW(g_timebase.den);
1249 SHOW(g_error_resilient);
1251 SHOW(g_lag_in_frames);
1252 SHOW(large_scale_tile);
1253 SHOW(rc_dropframe_thresh);
1254 SHOW(rc_resize_mode);
1255 SHOW(rc_resize_denominator);
1256 SHOW(rc_resize_kf_denominator);
1257 SHOW(rc_superres_mode);
1258 SHOW(rc_superres_denominator);
1259 SHOW(rc_superres_kf_denominator);
1260 SHOW(rc_superres_qthresh);
1261 SHOW(rc_superres_kf_qthresh);
1263 SHOW(rc_target_bitrate);
1264 SHOW(rc_min_quantizer);
1265 SHOW(rc_max_quantizer);
1266 SHOW(rc_undershoot_pct);
1267 SHOW(rc_overshoot_pct);
1269 SHOW(rc_buf_initial_sz);
1270 SHOW(rc_buf_optimal_sz);
1271 SHOW(rc_2pass_vbr_bias_pct);
1272 SHOW(rc_2pass_vbr_minsection_pct);
1273 SHOW(rc_2pass_vbr_maxsection_pct);
1274 SHOW(fwd_kf_enabled);
1279 #define SHOW_PARAMS(field) \ 1280 fprintf(stderr, " %-28s = %d\n", #field, \ 1281 stream->config.cfg.encoder_cfg.field) 1282 if (global->encoder_config.init_by_cfg_file) {
1283 SHOW_PARAMS(super_block_size);
1284 SHOW_PARAMS(max_partition_size);
1285 SHOW_PARAMS(min_partition_size);
1286 SHOW_PARAMS(disable_ab_partition_type);
1287 SHOW_PARAMS(disable_rect_partition_type);
1288 SHOW_PARAMS(disable_1to4_partition_type);
1289 SHOW_PARAMS(disable_flip_idtx);
1290 SHOW_PARAMS(disable_cdef);
1291 SHOW_PARAMS(disable_lr);
1292 SHOW_PARAMS(disable_obmc);
1293 SHOW_PARAMS(disable_warp_motion);
1294 SHOW_PARAMS(disable_global_motion);
1295 SHOW_PARAMS(disable_dist_wtd_comp);
1296 SHOW_PARAMS(disable_diff_wtd_comp);
1297 SHOW_PARAMS(disable_inter_intra_comp);
1298 SHOW_PARAMS(disable_masked_comp);
1299 SHOW_PARAMS(disable_one_sided_comp);
1300 SHOW_PARAMS(disable_palette);
1301 SHOW_PARAMS(disable_intrabc);
1302 SHOW_PARAMS(disable_cfl);
1303 SHOW_PARAMS(disable_smooth_intra);
1304 SHOW_PARAMS(disable_filter_intra);
1305 SHOW_PARAMS(disable_dual_filter);
1306 SHOW_PARAMS(disable_intra_angle_delta);
1307 SHOW_PARAMS(disable_intra_edge_filter);
1308 SHOW_PARAMS(disable_tx_64x64);
1309 SHOW_PARAMS(disable_smooth_inter_intra);
1310 SHOW_PARAMS(disable_inter_inter_wedge);
1311 SHOW_PARAMS(disable_inter_intra_wedge);
1312 SHOW_PARAMS(disable_paeth_intra);
1313 SHOW_PARAMS(disable_trellis_quant);
1314 SHOW_PARAMS(disable_ref_frame_mv);
1315 SHOW_PARAMS(reduced_reference_set);
1316 SHOW_PARAMS(reduced_tx_type_set);
1320 static void open_output_file(
struct stream_state *stream,
1321 struct AvxEncoderConfig *global,
1322 const struct AvxRational *pixel_aspect_ratio,
1323 const char *encoder_settings) {
1324 const char *fn = stream->config.out_fn;
1329 stream->file = strcmp(fn,
"-") ? fopen(fn,
"wb") : set_binary_mode(stdout);
1331 if (!stream->file) fatal(
"Failed to open output file");
1333 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1334 fatal(
"WebM output to pipes not supported.");
1337 if (stream->config.write_webm) {
1338 stream->webm_ctx.stream = stream->file;
1339 if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1340 stream->config.stereo_fmt,
1341 get_fourcc_by_aom_encoder(global->codec),
1342 pixel_aspect_ratio, encoder_settings) != 0) {
1343 fatal(
"WebM writer initialization failed.");
1347 (void)pixel_aspect_ratio;
1348 (void)encoder_settings;
1351 if (!stream->config.write_webm && stream->config.write_ivf) {
1352 ivf_write_file_header(stream->file, cfg,
1353 get_fourcc_by_aom_encoder(global->codec), 0);
1357 static void close_output_file(
struct stream_state *stream,
1358 unsigned int fourcc) {
1364 if (stream->config.write_webm) {
1365 if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1366 fatal(
"WebM writer finalization failed.");
1371 if (!stream->config.write_webm && stream->config.write_ivf) {
1372 if (!fseek(stream->file, 0, SEEK_SET))
1373 ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1374 stream->frames_out);
1377 fclose(stream->file);
1380 static void setup_pass(
struct stream_state *stream,
1381 struct AvxEncoderConfig *global,
int pass) {
1382 if (stream->config.stats_fn) {
1383 if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1384 fatal(
"Failed to open statistics store");
1386 if (!stats_open_mem(&stream->stats, pass))
1387 fatal(
"Failed to open statistics store");
1390 stream->config.cfg.g_pass = global->passes == 2
1394 stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1397 stream->cx_time = 0;
1399 stream->frames_out = 0;
1402 static void initialize_encoder(
struct stream_state *stream,
1403 struct AvxEncoderConfig *global) {
1413 ctx_exit_on_error(&stream->encoder,
"Failed to initialize encoder");
1415 for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1416 int ctrl = stream->config.arg_ctrls[i][0];
1417 int value = stream->config.arg_ctrls[i][1];
1419 fprintf(stderr,
"Error: Tried to set control %d = %d\n", ctrl, value);
1421 ctx_exit_on_error(&stream->encoder,
"Failed to control codec");
1424 for (i = 0; i < stream->config.arg_key_val_cnt; i++) {
1425 const char *name = stream->config.arg_key_vals[i][0];
1426 const char *val = stream->config.arg_key_vals[i][1];
1428 fprintf(stderr,
"Error: Tried to set option %s = %s\n", name, val);
1430 ctx_exit_on_error(&stream->encoder,
"Failed to set codec option");
1433 #if CONFIG_TUNE_VMAF 1434 if (stream->config.vmaf_model_path) {
1436 stream->config.vmaf_model_path);
1440 if (stream->config.film_grain_filename) {
1442 stream->config.film_grain_filename);
1445 stream->config.color_range);
1447 #if CONFIG_AV1_DECODER 1448 if (global->test_decode != TEST_DECODE_OFF) {
1450 get_short_name_by_aom_encoder(global->codec));
1454 if (strcmp(get_short_name_by_aom_encoder(global->codec),
"av1") == 0) {
1456 stream->config.cfg.large_scale_tile);
1457 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_mode");
1460 stream->config.cfg.save_as_annexb);
1461 ctx_exit_on_error(&stream->decoder,
"Failed to set is_annexb");
1465 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_row");
1469 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_col");
1475 static void encode_frame(
struct stream_state *stream,
1476 struct AvxEncoderConfig *global,
struct aom_image *img,
1477 unsigned int frames_in) {
1480 struct aom_usec_timer timer;
1483 (cfg->
g_timebase.
den * (int64_t)(frames_in - 1) * global->framerate.den) /
1486 (cfg->
g_timebase.
den * (int64_t)(frames_in)*global->framerate.den) /
1494 fprintf(stderr,
"%s can only scale 4:2:0 inputs\n", exec_name);
1511 stream->img->stride[
AOM_PLANE_V] / 2, stream->img->d_w,
1512 stream->img->d_h, kFilterBox);
1515 stream->encoder.err = 1;
1516 ctx_exit_on_error(&stream->encoder,
1517 "Stream %d: Failed to encode frame.\n" 1518 "libyuv is required for scaling but is currently " 1520 "Be sure to specify -DCONFIG_LIBYUV=1 when running " 1526 if (img && (img->
d_w != cfg->
g_w || img->
d_h != cfg->
g_h)) {
1528 fprintf(stderr,
"%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1542 stream->img->d_w, stream->img->d_h, kFilterBox);
1545 stream->encoder.err = 1;
1546 ctx_exit_on_error(&stream->encoder,
1547 "Stream %d: Failed to encode frame.\n" 1548 "Scaling disabled in this configuration. \n" 1549 "To enable, configure with --enable-libyuv\n",
1554 aom_usec_timer_start(&timer);
1556 (uint32_t)(next_frame_start - frame_start), 0);
1557 aom_usec_timer_mark(&timer);
1558 stream->cx_time += aom_usec_timer_elapsed(&timer);
1559 ctx_exit_on_error(&stream->encoder,
"Stream %d: Failed to encode frame",
1563 static void update_quantizer_histogram(
struct stream_state *stream) {
1569 ctx_exit_on_error(&stream->encoder,
"Failed to read quantizer");
1570 stream->counts[q]++;
1574 static void get_cx_data(
struct stream_state *stream,
1575 struct AvxEncoderConfig *global,
int *got_data) {
1582 static size_t fsize = 0;
1583 static FileOffset ivf_header_pos = 0;
1585 switch (pkt->
kind) {
1587 ++stream->frames_out;
1589 fprintf(stderr,
" %6luF", (
unsigned long)pkt->
data.
frame.sz);
1591 update_rate_histogram(stream->rate_hist, cfg, pkt);
1593 if (stream->config.write_webm) {
1594 if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
1595 fatal(
"WebM writer failed.");
1599 if (!stream->config.write_webm) {
1600 if (stream->config.write_ivf) {
1601 if (pkt->
data.
frame.partition_id <= 0) {
1602 ivf_header_pos = ftello(stream->file);
1605 ivf_write_frame_header(stream->file, pkt->
data.
frame.pts, fsize);
1609 const FileOffset currpos = ftello(stream->file);
1610 fseeko(stream->file, ivf_header_pos, SEEK_SET);
1611 ivf_write_frame_size(stream->file, fsize);
1612 fseeko(stream->file, currpos, SEEK_SET);
1622 #if CONFIG_AV1_DECODER 1623 if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
1626 if (stream->decoder.err) {
1627 warn_or_exit_on_error(&stream->decoder,
1628 global->test_decode == TEST_DECODE_FATAL,
1629 "Failed to decode frame %d in stream %d",
1630 stream->frames_out + 1, stream->index);
1631 stream->mismatch_seen = stream->frames_out + 1;
1637 stream->frames_out++;
1644 if (global->show_psnr >= 1) {
1647 stream->psnr_sse_total[0] += pkt->
data.
psnr.sse[0];
1648 stream->psnr_samples_total[0] += pkt->
data.
psnr.samples[0];
1649 for (i = 0; i < 4; i++) {
1651 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr[i]);
1652 stream->psnr_totals[0][i] += pkt->
data.
psnr.psnr[i];
1654 stream->psnr_count[0]++;
1656 #if CONFIG_AV1_HIGHBITDEPTH 1657 if (stream->config.cfg.g_input_bit_depth <
1658 (
unsigned int)stream->config.cfg.g_bit_depth) {
1659 stream->psnr_sse_total[1] += pkt->
data.
psnr.sse_hbd[0];
1660 stream->psnr_samples_total[1] += pkt->
data.
psnr.samples_hbd[0];
1661 for (i = 0; i < 4; i++) {
1663 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr_hbd[i]);
1664 stream->psnr_totals[1][i] += pkt->
data.
psnr.psnr_hbd[i];
1666 stream->psnr_count[1]++;
1677 static void show_psnr(
struct stream_state *stream,
double peak, int64_t bps) {
1681 if (!stream->psnr_count[0])
return;
1683 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1684 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[0], peak,
1685 (
double)stream->psnr_sse_total[0]);
1686 fprintf(stderr,
" %.3f", ovpsnr);
1688 for (i = 0; i < 4; i++) {
1689 fprintf(stderr,
" %.3f", stream->psnr_totals[0][i] / stream->psnr_count[0]);
1692 fprintf(stderr,
" %7" PRId64
" bps", bps);
1694 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1695 fprintf(stderr,
"\n");
1698 #if CONFIG_AV1_HIGHBITDEPTH 1699 static void show_psnr_hbd(
struct stream_state *stream,
double peak,
1704 if (!stream->psnr_count[1])
return;
1706 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1707 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total[1], peak,
1708 (
double)stream->psnr_sse_total[1]);
1709 fprintf(stderr,
" %.3f", ovpsnr);
1711 for (i = 0; i < 4; i++) {
1712 fprintf(stderr,
" %.3f", stream->psnr_totals[1][i] / stream->psnr_count[1]);
1715 fprintf(stderr,
" %7" PRId64
" bps", bps);
1717 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
1718 fprintf(stderr,
"\n");
1722 static float usec_to_fps(uint64_t usec,
unsigned int frames) {
1723 return (
float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
1726 static void test_decode(
struct stream_state *stream,
1727 enum TestDecodeFatality fatal) {
1730 if (stream->mismatch_seen)
return;
1743 enc_img.
d_w, enc_img.
d_h, 16);
1744 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1745 enc_img = enc_hbd_img;
1750 dec_img.
d_w, dec_img.
d_h, 16);
1751 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1752 dec_img = dec_hbd_img;
1756 ctx_exit_on_error(&stream->encoder,
"Failed to get encoder reference frame");
1757 ctx_exit_on_error(&stream->decoder,
"Failed to get decoder reference frame");
1759 if (!aom_compare_img(&enc_img, &dec_img)) {
1760 int y[4], u[4], v[4];
1762 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1764 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1766 stream->decoder.err = 1;
1767 warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
1768 "Stream %d: Encode/decode mismatch on frame %d at" 1769 " Y[%d, %d] {%d/%d}," 1770 " U[%d, %d] {%d/%d}," 1771 " V[%d, %d] {%d/%d}",
1772 stream->index, stream->frames_out, y[0], y[1], y[2],
1773 y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
1774 stream->mismatch_seen = stream->frames_out;
1781 static void print_time(
const char *label, int64_t etl) {
1788 etl -= hours * 3600;
1793 fprintf(stderr,
"[%3s %2" PRId64
":%02" PRId64
":%02" PRId64
"] ", label,
1796 fprintf(stderr,
"[%3s unknown] ", label);
1800 int main(
int argc,
const char **argv_) {
1804 int allocated_raw_shift = 0;
1805 int do_16bit_internal = 0;
1806 int input_shift = 0;
1807 int frame_avail, got_data;
1809 struct AvxInputContext input;
1810 struct AvxEncoderConfig global;
1811 struct stream_state *streams = NULL;
1812 char **argv, **argi;
1813 uint64_t cx_time = 0;
1816 int profile_updated = 0;
1818 memset(&input, 0,
sizeof(input));
1819 memset(&raw, 0,
sizeof(raw));
1820 exec_name = argv_[0];
1823 input.framerate.numerator = 30;
1824 input.framerate.denominator = 1;
1825 input.only_i420 = 1;
1826 input.bit_depth = 0;
1832 argv = argv_dup(argc - 1, argv_ + 1);
1833 parse_global_config(&global, &argv);
1835 if (argc < 2) usage_exit();
1837 switch (global.color_type) {
1849 struct stream_state *stream = NULL;
1852 stream = new_stream(&global, stream);
1854 if (!streams) streams = stream;
1855 }
while (parse_stream_params(&global, stream, argv));
1859 for (argi = argv; *argi; argi++)
1860 if (argi[0][0] ==
'-' && argi[0][1])
1861 die(
"Error: Unrecognized option %s\n", *argi);
1863 FOREACH_STREAM(stream, streams) {
1864 check_encoder_config(global.disable_warning_prompt, &global,
1865 &stream->config.cfg);
1868 if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
1869 die(
"only support ivf output format while large-scale-tile=1\n");
1873 input.filename = argv[0];
1875 if (!input.filename) {
1876 fprintf(stderr,
"No input file specified!\n");
1881 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC)
1882 input.only_i420 = 0;
1884 for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
1885 int frames_in = 0, seen_frames = 0;
1886 int64_t estimated_time_left = -1;
1887 int64_t average_rate = -1;
1888 int64_t lagged_count = 0;
1890 open_input_file(&input, global.csp);
1895 if (!input.width || !input.height) {
1896 FOREACH_STREAM(stream, streams) {
1897 if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
1898 input.width = stream->config.cfg.g_w;
1899 input.height = stream->config.cfg.g_h;
1906 if (!input.width || !input.height)
1908 "Specify stream dimensions with --width (-w) " 1909 " and --height (-h)");
1916 if (!input.bit_depth) {
1917 FOREACH_STREAM(stream, streams) {
1918 if (stream->config.cfg.g_input_bit_depth)
1919 input.bit_depth = stream->config.cfg.g_input_bit_depth;
1921 input.bit_depth = stream->config.cfg.g_input_bit_depth =
1922 (int)stream->config.cfg.g_bit_depth;
1926 FOREACH_STREAM(stream, streams) {
1927 stream->config.cfg.g_input_bit_depth = input.bit_depth;
1931 FOREACH_STREAM(stream, streams) {
1935 switch (stream->config.cfg.g_profile) {
1939 if (!stream->config.cfg.monochrome) {
1940 stream->config.cfg.g_profile = 1;
1941 profile_updated = 1;
1945 stream->config.cfg.g_profile = 2;
1946 profile_updated = 1;
1952 stream->config.cfg.g_profile = 2;
1953 profile_updated = 1;
1954 }
else if (input.bit_depth < 12 &&
1957 stream->config.cfg.g_profile = 0;
1958 profile_updated = 1;
1964 stream->config.cfg.g_profile = 1;
1965 profile_updated = 1;
1966 }
else if (input.bit_depth < 12 &&
1969 stream->config.cfg.g_profile = 0;
1970 profile_updated = 1;
1971 }
else if (input.bit_depth == 12 &&
1972 input.file_type == FILE_TYPE_Y4M) {
1977 input.y4m.dst_c_dec_h >> 1);
1980 input.y4m.dst_c_dec_v >> 1);
1981 }
else if (input.bit_depth == 12 &&
1982 input.file_type == FILE_TYPE_RAW) {
1985 stream->chroma_subsampling_x);
1988 stream->chroma_subsampling_y);
1996 if (stream->config.cfg.g_input_bit_depth >
1997 (
unsigned int)stream->config.cfg.g_bit_depth) {
1998 stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
1999 if (!global.quiet) {
2001 "Warning: automatically updating bit depth to %d to " 2002 "match input format.\n",
2003 stream->config.cfg.g_input_bit_depth);
2006 #if !CONFIG_AV1_HIGHBITDEPTH 2007 if (stream->config.cfg.g_bit_depth > 8) {
2008 fatal(
"Unsupported bit-depth with CONFIG_AV1_HIGHBITDEPTH=0\n");
2010 #endif // CONFIG_AV1_HIGHBITDEPTH 2011 if (stream->config.cfg.g_bit_depth > 10) {
2012 switch (stream->config.cfg.g_profile) {
2015 stream->config.cfg.g_profile = 2;
2016 profile_updated = 1;
2021 if (stream->config.cfg.g_bit_depth > 8) {
2022 stream->config.use_16bit_internal = 1;
2024 if (profile_updated && !global.quiet) {
2026 "Warning: automatically updating to profile %d to " 2027 "match input format.\n",
2028 stream->config.cfg.g_profile);
2030 if ((global.show_psnr == 2) && (stream->config.cfg.g_input_bit_depth ==
2031 stream->config.cfg.g_bit_depth)) {
2033 "Warning: --psnr==2 and --psnr==1 will provide same " 2034 "results when input bit-depth == stream bit-depth, " 2035 "falling back to default psnr value\n");
2036 global.show_psnr = 1;
2038 if (global.show_psnr < 0 || global.show_psnr > 2) {
2040 "Warning: --psnr can take only 0,1,2 as values," 2041 "falling back to default psnr value\n");
2042 global.show_psnr = 1;
2045 stream->config.cfg.g_limit = global.limit;
2048 FOREACH_STREAM(stream, streams) {
2049 set_stream_dimensions(stream, input.width, input.height);
2050 stream->config.color_range = input.color_range;
2052 FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
2057 if (global.pass && global.passes == 2) {
2058 FOREACH_STREAM(stream, streams) {
2059 if (!stream->config.stats_fn)
2060 die(
"Stream %d: Must specify --fpf when --pass=%d" 2061 " and --passes=2\n",
2062 stream->index, global.pass);
2067 FOREACH_STREAM(stream, streams) {
2068 if (stream->config.write_webm) {
2069 stream->config.write_webm = 0;
2070 stream->config.write_ivf = 0;
2071 warn(
"aomenc compiled w/o WebM support. Writing OBU stream.");
2079 if (!global.have_framerate) {
2080 global.framerate.num = input.framerate.numerator;
2081 global.framerate.den = input.framerate.denominator;
2083 FOREACH_STREAM(stream, streams) {
2084 stream->config.cfg.g_timebase.den = global.framerate.num;
2085 stream->config.cfg.g_timebase.num = global.framerate.den;
2088 if (global.verbose && pass == 0) {
2089 FOREACH_STREAM(stream, streams) {
2090 show_stream_config(stream, &global, &input);
2094 if (pass == (global.pass ? global.pass - 1 : 0)) {
2096 if (input.file_type != FILE_TYPE_Y4M) {
2097 aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2099 FOREACH_STREAM(stream, streams) {
2101 init_rate_histogram(&stream->config.cfg, &global.framerate);
2105 FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2106 FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2107 FOREACH_STREAM(stream, streams) {
2108 char *encoder_settings = NULL;
2117 if (stream->config.write_webm && !stream->webm_ctx.debug) {
2118 encoder_settings = extract_encoder_settings(
2120 if (encoder_settings == NULL) {
2123 "Warning: unable to extract encoder settings. Continuing...\n");
2127 open_output_file(stream, &global, &input.pixel_aspect_ratio,
2129 free(encoder_settings);
2132 if (strcmp(get_short_name_by_aom_encoder(global.codec),
"av1") == 0) {
2136 FOREACH_STREAM(stream, streams) {
2137 if (stream->config.use_16bit_internal) {
2138 do_16bit_internal = 1;
2140 input_shift = (int)stream->config.cfg.g_bit_depth -
2141 stream->config.cfg.g_input_bit_depth;
2148 while (frame_avail || got_data) {
2149 struct aom_usec_timer timer;
2151 if (!global.limit || frames_in < global.limit) {
2152 frame_avail = read_frame(&input, &raw);
2154 if (frame_avail) frames_in++;
2156 frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2158 if (!global.quiet) {
2159 float fps = usec_to_fps(cx_time, seen_frames);
2160 fprintf(stderr,
"\rPass %d/%d ", pass + 1, global.passes);
2162 if (stream_cnt == 1)
2163 fprintf(stderr,
"frame %4d/%-4d %7" PRId64
"B ", frames_in,
2164 streams->frames_out, (int64_t)streams->nbytes);
2166 fprintf(stderr,
"frame %4d ", frames_in);
2168 fprintf(stderr,
"%7" PRId64
" %s %.2f %s ",
2169 cx_time > 9999999 ? cx_time / 1000 : cx_time,
2170 cx_time > 9999999 ?
"ms" :
"us", fps >= 1.0 ? fps : fps * 60,
2171 fps >= 1.0 ?
"fps" :
"fpm");
2172 print_time(
"ETA", estimated_time_left);
2179 if (frames_in > global.skip_frames) {
2181 if (input_shift || (do_16bit_internal && input.bit_depth == 8)) {
2182 assert(do_16bit_internal);
2185 if (!allocated_raw_shift) {
2187 input.width, input.height, 32);
2188 allocated_raw_shift = 1;
2190 aom_img_upshift(&raw_shift, &raw, input_shift);
2191 frame_to_encode = &raw_shift;
2193 frame_to_encode = &raw;
2195 aom_usec_timer_start(&timer);
2196 if (do_16bit_internal) {
2198 FOREACH_STREAM(stream, streams) {
2199 if (stream->config.use_16bit_internal)
2200 encode_frame(stream, &global,
2201 frame_avail ? frame_to_encode : NULL, frames_in);
2207 FOREACH_STREAM(stream, streams) {
2208 encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2212 aom_usec_timer_mark(&timer);
2213 cx_time += aom_usec_timer_elapsed(&timer);
2215 FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2218 FOREACH_STREAM(stream, streams) {
2219 get_cx_data(stream, &global, &got_data);
2222 if (!got_data && input.length && streams != NULL &&
2223 !streams->frames_out) {
2224 lagged_count = global.limit ? seen_frames : ftello(input.file);
2225 }
else if (input.length) {
2230 const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2232 rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2233 remaining = 1000 * (global.limit - global.skip_frames -
2234 seen_frames + lagged_count);
2236 const int64_t input_pos = ftello(input.file);
2237 const int64_t input_pos_lagged = input_pos - lagged_count;
2238 const int64_t input_limit = input.length;
2240 rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2241 remaining = input_limit - input_pos + lagged_count;
2245 (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2246 estimated_time_left = average_rate ? remaining / average_rate : -1;
2249 if (got_data && global.test_decode != TEST_DECODE_OFF) {
2250 FOREACH_STREAM(stream, streams) {
2251 test_decode(stream, global.test_decode);
2257 if (!global.quiet) fprintf(stderr,
"\033[K");
2260 if (stream_cnt > 1) fprintf(stderr,
"\n");
2262 if (!global.quiet) {
2263 FOREACH_STREAM(stream, streams) {
2265 seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2266 const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2268 "\rPass %d/%d frame %4d/%-4d %7" PRId64
"B %7" PRId64
2271 " %7" PRId64
" %s (%.2f fps)\033[K\n",
2272 pass + 1, global.passes, frames_in, stream->frames_out,
2273 (int64_t)stream->nbytes, bpf, bps,
2274 stream->cx_time > 9999999 ? stream->cx_time / 1000
2276 stream->cx_time > 9999999 ?
"ms" :
"us",
2277 usec_to_fps(stream->cx_time, seen_frames));
2281 if (global.show_psnr >= 1) {
2282 if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) {
2283 FOREACH_STREAM(stream, streams) {
2285 if (global.show_psnr == 1) {
2286 if (stream->psnr_count[0] && seen_frames && global.framerate.den) {
2287 bps = (int64_t)stream->nbytes * 8 *
2288 (int64_t)global.framerate.num / global.framerate.den /
2291 show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2294 if (global.show_psnr == 2) {
2295 #if CONFIG_AV1_HIGHBITDEPTH 2296 if (stream->config.cfg.g_input_bit_depth <
2297 (
unsigned int)stream->config.cfg.g_bit_depth)
2298 show_psnr_hbd(stream, (1 << stream->config.cfg.g_bit_depth) - 1,
2304 FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2310 if (global.test_decode != TEST_DECODE_OFF) {
2314 close_input_file(&input);
2316 if (global.test_decode == TEST_DECODE_FATAL) {
2317 FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2319 FOREACH_STREAM(stream, streams) {
2320 close_output_file(stream, get_fourcc_by_aom_encoder(global.codec));
2323 FOREACH_STREAM(stream, streams) {
2324 stats_close(&stream->stats, global.passes - 1);
2327 if (global.pass)
break;
2330 if (global.show_q_hist_buckets) {
2331 FOREACH_STREAM(stream, streams) {
2332 show_q_histogram(stream->counts, global.show_q_hist_buckets);
2336 if (global.show_rate_hist_buckets) {
2337 FOREACH_STREAM(stream, streams) {
2338 show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2339 global.show_rate_hist_buckets);
2342 FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2344 #if CONFIG_INTERNAL_STATS 2348 if (!(global.pass == 1 && global.passes == 2)) {
2349 FOREACH_STREAM(stream, streams) {
2350 FILE *f = fopen(
"opsnr.stt",
"a");
2351 if (stream->mismatch_seen) {
2352 fprintf(f,
"First mismatch occurred in frame %d\n",
2353 stream->mismatch_seen);
2355 fprintf(f,
"No mismatch detected in recon buffers\n");
2366 return res ? EXIT_FAILURE : EXIT_SUCCESS;
#define AOM_PLANE_U
Definition: aom_image.h:200
void * buf
Definition: aom_encoder.h:77
Control to use dct only for intra modes, int parameter.
Definition: aomcx.h:1178
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition: aomcx.h:295
unsigned int d_h
Definition: aom_image.h:187
#define AOM_PLANE_V
Definition: aom_image.h:201
Codec control function to turn on / off Paeth intra mode usage, int parameter.
Definition: aomcx.h:1062
Codec control function to set an MTU size for a tile group, unsigned int parameter.
Definition: aomcx.h:784
Codec control function to encode with CDEF, unsigned int parameter.
Definition: aomcx.h:654
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:223
Definition: aom_encoder.h:161
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:406
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition: aom_codec.h:520
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition: aomcx.h:849
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_codec.h:235
Describes the encoder algorithm interface to applications.
Definition: aom_image.h:133
Codec control function to set max partition size, int parameter.
Definition: aomcx.h:832
Codec control function to set noise sensitivity, unsigned int parameter.
Definition: aomcx.h:477
Codec control function to encode with quantisation matrices, unsigned int parameter.
Definition: aomcx.h:702
Codec control function to signal picture timing info in the bitstream, aom_timing_info_type_t paramet...
Definition: aomcx.h:1148
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition: aom_encoder.h:931
Encoder configuration structure.
Definition: aom_encoder.h:367
Codec control function to turn on / off interintra wedge compound, int parameter. ...
Definition: aomcx.h:1002
Control to use default tx type only for intra modes, int parameter.
Definition: aomcx.h:1185
aom_codec_err_t err
Definition: aom_codec.h:301
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
Codec control function to set chroma 4:2:0 sample position info, aom_chroma_sample_position_t paramet...
Definition: aomcx.h:569
Codec control function to turn on / off rectangular transforms, int parameter.
Definition: aomcx.h:896
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition: aom_encoder.h:68
Codec control function to set min partition size, int parameter.
Definition: aomcx.h:821
unsigned char * planes[3]
Definition: aom_image.h:202
Codec control function to encode without trellis quantization, unsigned int parameter.
Definition: aomcx.h:691
Codec control function to set the max no of frames to create arf, unsigned int parameter.
Definition: aomcx.h:257
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.
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition: aomcx.h:281
Control to set target sequence level index for a certain operating point(OP), int parameter Possible ...
Definition: aomcx.h:621
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter...
Definition: aomdx.h:345
Control to set average complexity of the corpus in the case of single pass vbr based on LAP...
Definition: aomcx.h:1307
Definition: aom_image.h:50
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
Rational Number.
Definition: aom_encoder.h:152
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition: aom_encoder.h:215
Codec context structure.
Definition: aom_codec.h:298
Codec control function to turn on/off intra block copy mode, int parameter.
Definition: aomcx.h:1097
Codec control function to turn on / off warped motion usage at sequence level, int parameter...
Definition: aomcx.h:1022
Codec control function to turn on / off interinter wedge compound, int parameter. ...
Definition: aomcx.h:994
Codec control function to set the min quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:715
Codec control function to enable frame parallel decoding feature, unsigned int parameter.
Definition: aomcx.h:420
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
Control to use dct only for inter modes, int parameter.
Definition: aomcx.h:1181
Codec control function to enable/disable rectangular partitions, int parameter.
Definition: aomcx.h:794
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:562
Codec control function to set color range bit, int parameter.
Definition: aomcx.h:595
Describes the decoder algorithm interface to applications.
#define AOM_USAGE_GOOD_QUALITY
usage parameter analogous to AV1 GOOD QUALITY mode.
Definition: aom_encoder.h:1002
Codec control function to enable/disable AB partitions, int parameter.
Definition: aomcx.h:802
Codec control function to add film grain parameters (one of several preset types) info in the bitstre...
Definition: aomcx.h:1155
Codec control function to set max data rate for inter frames, unsigned int parameter.
Definition: aomcx.h:314
Definition: aom_image.h:49
Control to select maximum height for the GF group pyramid structure, unsigned int parameter...
Definition: aomcx.h:1195
Control to set minimum compression ratio, unsigned int parameter Take integer values. If non-zero, encoder will try to keep the compression ratio of each frame to be higher than the given value divided by 100. E.g. 850 means minimum compression ratio of 8.5.
Definition: aomcx.h:1251
Image Descriptor.
Definition: aom_image.h:171
double psnr[4]
Definition: aom_encoder.h:133
Codec control function to set number of tile columns. unsigned int parameter.
Definition: aomcx.h:369
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_fixed_buf_t raw
Definition: aom_encoder.h:144
Definition: aom_image.h:54
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.
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
Control to select maximum reference frames allowed per frame, int parameter.
Definition: aomcx.h:1202
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.
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:219
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition: aom_encoder.h:1004
Sets the denoisers block size, unsigned int parameter.
Definition: aomcx.h:1166
Definition: aom_codec.h:319
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition: aom_codec.h:254
Codec control function to set loop filter sharpness, unsigned int parameter.
Definition: aomcx.h:230
Sets the noise level, int parameter.
Definition: aomcx.h:1163
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition: aom_decoder.h:129
Codec control function to turn on / off smooth inter-intra mode for a sequence, int parameter...
Definition: aomcx.h:978
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:464
Definition: aom_encoder.h:101
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
Definition: aom_encoder.h:99
Encoder Config Options.
Definition: aom_encoder.h:207
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
Codec control function to enable temporal filtering on key frame, unsigned int parameter.
Definition: aomcx.h:406
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled...
Definition: aomcx.h:1121
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter...
Definition: aomcx.h:576
Definition: aom_image.h:53
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition: aomcx.h:1072
Codec control function to turn on / off flip and identity transforms, int parameter.
Definition: aomcx.h:884
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:111
Codec control function to enable error_resilient_mode, int parameter.
Definition: aomcx.h:431
Codec control function to encode with Loop Restoration Filter, unsigned int parameter.
Definition: aomcx.h:664
Codec control function to set visual tuning, aom_tune_metric (int) parameter.
Definition: aomcx.h:271
Definition: aom_image.h:52
Codec control function to set the path to the film grain parameters, const char* parameter.
Definition: aomcx.h:1160
void aom_img_free(aom_image_t *img)
Close an image descriptor.
#define FIXED_QP_OFFSET_COUNT
Number of fixed QP offsets.
Definition: aom_encoder.h:876
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition: aomcx.h:1012
Codec control function to turn on / off masked compound usage (wedge and diff-wtd compound modes) for...
Definition: aomcx.h:954
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter...
Definition: aomcx.h:583
unsigned int disable_trellis_quant
disable trellis quantization
Definition: aom_encoder.h:335
Sets the chroma subsampling y value, unsigned int parameter.
Definition: aomcx.h:1172
Codec control function to turn on / off filter intra usage at sequence level, int parameter...
Definition: aomcx.h:1043
struct aom_codec_cx_pkt::@1::@2 frame
Definition: aom_encoder.h:159
Definition: aom_encoder.h:98
Codec control function to turn on / off interintra compound for a sequence, int parameter.
Definition: aomcx.h:970
Sets the chroma subsampling x value, unsigned int parameter.
Definition: aomcx.h:1169
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level, int parameter.
Definition: aomcx.h:919
Initialization Configurations.
Definition: aom_decoder.h:91
Codec control function to get last quantizer chosen by the encoder, int* parameter.
Definition: aomcx.h:252
#define MAX_TILE_WIDTHS
Maximum number of tile widths in tile widths array.
Definition: aom_encoder.h:836
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition: aom_encoder.h:849
#define AOM_CODEC_USE_HIGHBITDEPTH
Make the encoder output one partition at a time.
Definition: aom_encoder.h:70
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition: aomcx.h:1236
Control to set bit mask that specifies which tier each of the 32 possible operating points conforms t...
Definition: aomcx.h:1244
Codec control function to set lossless encoding mode, unsigned int parameter.
Definition: aomcx.h:342
Codec control function to turn on/off palette mode, int parameter.
Definition: aomcx.h:1093
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition: aomcx.h:1226
Codec control function to get a pointer to the new frame.
Definition: aom.h:70
Codec control function to set encoder internal speed settings, int parameter.
Definition: aomcx.h:213
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter...
Definition: aomcx.h:397
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition: aomcx.h:350
Codec control function to turn on / off dual interpolation filter for a sequence, int parameter...
Definition: aomcx.h:938
const char * aom_codec_version_str(void)
Return the version information (as a string)
#define AOM_USAGE_ALL_INTRA
usage parameter analogous to AV1 all intra mode.
Definition: aom_encoder.h:1006
Codec control function to set the delta q mode, unsigned int parameter.
Definition: aomcx.h:1113
Codec control function to force video mode, unsigned int parameter.
Definition: aomcx.h:671
Codec control function to turn on / off dist-wtd compound mode at sequence level, int parameter...
Definition: aomcx.h:908
Codec control function to turn on / off 64-length transforms, int parameter.
Definition: aomcx.h:860
Codec control function to turn on / off one sided compound usage for a sequence, int parameter...
Definition: aomcx.h:962
aom_codec_err_t aom_codec_set_option(aom_codec_ctx_t *ctx, const char *name, const char *value)
Key & Value API.
Codec control function to set the filter strength for the arf, unsigned int parameter.
Definition: aomcx.h:262
Control to use adaptive quantize_b, int parameter.
Definition: aomcx.h:1188
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition: aomcx.h:221
Codec control function to turn on / off intra edge filter at sequence level, int parameter.
Definition: aomcx.h:840
Codec control function to set the range of tile decoding, int parameter.
Definition: aomdx.h:301
Control to use a reduced tx type set, int parameter.
Definition: aomcx.h:1175
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:288
Codec control function to set the tile coding mode, int parameter.
Definition: aomdx.h:309
Codec control function to set the path to the VMAF model used when tuning the encoder for VMAF...
Definition: aomcx.h:1274
Codec control function to turn on / off difference weighted compound, int parameter.
Definition: aomcx.h:986
enum aom_color_range aom_color_range_t
List of supported color range.
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition: aomcx.h:1054
Codec control function to turn on / off overlay frames for filtered ALTREF frames, int parameter.
Definition: aomcx.h:1090
Codec control function to set number of tile rows, unsigned int parameter.
Definition: aomcx.h:387
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:155
const char * aom_codec_error(aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
Definition: aom_image.h:51
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition: aomcx.h:1216
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
Provides definitions for using AOM or AV1 within the aom Decoder interface.
int stride[3]
Definition: aom_image.h:203
aom_fixed_buf_t twopass_stats
Definition: aom_encoder.h:128
int den
Definition: aom_encoder.h:154
Codec control function to set content type, aom_tune_content parameter.
Definition: aomcx.h:486
Codec control function to set the max quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:727
Codec control function to set color space info, int parameter.
Definition: aomcx.h:516
Codec control function to set adaptive quantization mode, unsigned int parameter. ...
Definition: aomcx.h:457
Encoder output packet.
Definition: aom_encoder.h:110
Control to select minimum height for the GF group pyramid structure, unsigned int parameter...
Definition: aomcx.h:1302
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition: aomcx.h:681
int num
Definition: aom_encoder.h:153
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition: aomcx.h:328
Definition: aom_image.h:45
Codec control function to turn on / off D45 to D203 intra mode usage, int parameter.
Definition: aomcx.h:1328
Codec control function to enable/disable 1:4 and 4:1 partitions, int parameter.
Definition: aomcx.h:810
Codec control function to set CDF update mode, unsigned int parameter.
Definition: aomcx.h:495
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:541
const char * aom_codec_error_detail(aom_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
Codec control function to turn on/off intra angle delta, int parameter.
Definition: aomcx.h:1101
union aom_codec_cx_pkt::@1 data
Codec control function to set the threshold for MBs treated static, unsigned int parameter.
Definition: aomcx.h:235
size_t sz
Definition: aom_encoder.h:78
Codec control function to set intended superblock size, unsigned int parameter.
Definition: aomcx.h:636
unsigned int d_w
Definition: aom_image.h:186
Codec control function to enable/disable periodic Q boost, unsigned int parameter.
Definition: aomcx.h:469
Definition: aom_encoder.h:160
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition: aomcx.h:773
Definition: aom_encoder.h:183
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: aom_encoder.h:479
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:415
Definition: aom_image.h:43
aom_img_fmt_t fmt
Definition: aom_image.h:172
Codec control function to turn on / off delta quantization in chroma planes for a sequence...
Definition: aomcx.h:946
#define AOM_PLANE_Y
Definition: aom_image.h:199
Control to use reduced set of single and compound references, int parameter.
Definition: aomcx.h:1206