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) {
126 static const arg_def_t help =
127 ARG_DEF(NULL,
"help", 0,
"Show usage options and exit");
128 static const arg_def_t debugmode =
129 ARG_DEF(
"D",
"debug", 0,
"Debug mode (makes output deterministic)");
130 static const arg_def_t outputfile =
131 ARG_DEF(
"o",
"output", 1,
"Output filename");
132 static const arg_def_t use_yv12 =
133 ARG_DEF(NULL,
"yv12", 0,
"Input file is YV12 ");
134 static const arg_def_t use_i420 =
135 ARG_DEF(NULL,
"i420", 0,
"Input file is I420 (default)");
136 static const arg_def_t use_i422 =
137 ARG_DEF(NULL,
"i422", 0,
"Input file is I422");
138 static const arg_def_t use_i444 =
139 ARG_DEF(NULL,
"i444", 0,
"Input file is I444");
140 static const arg_def_t codecarg = ARG_DEF(NULL,
"codec", 1,
"Codec to use");
141 static const arg_def_t passes =
142 ARG_DEF(
"p",
"passes", 1,
"Number of passes (1/2)");
143 static const arg_def_t pass_arg =
144 ARG_DEF(NULL,
"pass", 1,
"Pass to execute (1/2)");
145 static const arg_def_t fpf_name =
146 ARG_DEF(NULL,
"fpf", 1,
"First pass statistics file name");
147 static const arg_def_t limit =
148 ARG_DEF(NULL,
"limit", 1,
"Stop encoding after n input frames");
149 static const arg_def_t skip =
150 ARG_DEF(NULL,
"skip", 1,
"Skip the first n input frames");
151 static const arg_def_t good_dl =
152 ARG_DEF(NULL,
"good", 0,
"Use Good Quality Deadline");
153 static const arg_def_t rt_dl =
154 ARG_DEF(NULL,
"rt", 0,
"Use Realtime Quality Deadline");
155 static const arg_def_t quietarg =
156 ARG_DEF(
"q",
"quiet", 0,
"Do not print encode progress");
157 static const arg_def_t verbosearg =
158 ARG_DEF(
"v",
"verbose", 0,
"Show encoder parameters");
159 static const arg_def_t psnrarg =
160 ARG_DEF(NULL,
"psnr", 0,
"Show PSNR in status line");
161 static const arg_def_t use_cfg = ARG_DEF(
"c",
"cfg", 1,
"Config file to use");
163 static const struct arg_enum_list test_decode_enum[] = {
164 {
"off", TEST_DECODE_OFF },
165 {
"fatal", TEST_DECODE_FATAL },
166 {
"warn", TEST_DECODE_WARN },
169 static const arg_def_t recontest = ARG_DEF_ENUM(
170 NULL,
"test-decode", 1,
"Test encode/decode mismatch", test_decode_enum);
171 static const arg_def_t framerate =
172 ARG_DEF(NULL,
"fps", 1,
"Stream frame rate (rate/scale)");
173 static const arg_def_t use_webm =
174 ARG_DEF(NULL,
"webm", 0,
"Output WebM (default when WebM IO is enabled)");
175 static const arg_def_t use_ivf = ARG_DEF(NULL,
"ivf", 0,
"Output IVF");
176 static const arg_def_t use_obu = ARG_DEF(NULL,
"obu", 0,
"Output OBU");
177 static const arg_def_t q_hist_n =
178 ARG_DEF(NULL,
"q-hist", 1,
"Show quantizer histogram (n-buckets)");
179 static const arg_def_t rate_hist_n =
180 ARG_DEF(NULL,
"rate-hist", 1,
"Show rate histogram (n-buckets)");
181 static const arg_def_t disable_warnings =
182 ARG_DEF(NULL,
"disable-warnings", 0,
183 "Disable warnings about potentially incorrect encode settings.");
184 static const arg_def_t disable_warning_prompt =
185 ARG_DEF(
"y",
"disable-warning-prompt", 0,
186 "Display warnings, but do not prompt user to continue.");
187 static const struct arg_enum_list bitdepth_enum[] = {
191 static const arg_def_t bitdeptharg = ARG_DEF_ENUM(
193 "Bit depth for codec (8 for version <=1, 10 or 12 for version 2)",
195 static const arg_def_t inbitdeptharg =
196 ARG_DEF(NULL,
"input-bit-depth", 1,
"Bit depth of input");
198 static const arg_def_t input_chroma_subsampling_x = ARG_DEF(
199 NULL,
"input-chroma-subsampling-x", 1,
"chroma subsampling x value.");
200 static const arg_def_t input_chroma_subsampling_y = ARG_DEF(
201 NULL,
"input-chroma-subsampling-y", 1,
"chroma subsampling y value.");
203 static const arg_def_t *main_args[] = { &help,
224 &disable_warning_prompt,
228 static const arg_def_t usage =
229 ARG_DEF(
"u",
"usage", 1,
"Usage profile number to use");
230 static const arg_def_t threads =
231 ARG_DEF(
"t",
"threads", 1,
"Max number of threads to use");
232 static const arg_def_t profile =
233 ARG_DEF(NULL,
"profile", 1,
"Bitstream profile number to use");
234 static const arg_def_t width = ARG_DEF(
"w",
"width", 1,
"Frame width");
235 static const arg_def_t height = ARG_DEF(
"h",
"height", 1,
"Frame height");
236 static const arg_def_t forced_max_frame_width = ARG_DEF(
237 NULL,
"forced_max_frame_width", 1,
"Maximum frame width value to force");
238 static const arg_def_t forced_max_frame_height = ARG_DEF(
239 NULL,
"forced_max_frame_height", 1,
"Maximum frame height value to force");
241 static const struct arg_enum_list stereo_mode_enum[] = {
242 {
"mono", STEREO_FORMAT_MONO },
243 {
"left-right", STEREO_FORMAT_LEFT_RIGHT },
244 {
"bottom-top", STEREO_FORMAT_BOTTOM_TOP },
245 {
"top-bottom", STEREO_FORMAT_TOP_BOTTOM },
246 {
"right-left", STEREO_FORMAT_RIGHT_LEFT },
249 static const arg_def_t stereo_mode = ARG_DEF_ENUM(
250 NULL,
"stereo-mode", 1,
"Stereo 3D video format", stereo_mode_enum);
252 static const arg_def_t timebase = ARG_DEF(
253 NULL,
"timebase", 1,
"Output timestamp precision (fractional seconds)");
254 static const arg_def_t global_error_resilient =
255 ARG_DEF(NULL,
"global-error-resilient", 1,
256 "Enable global error resiliency features");
257 static const arg_def_t lag_in_frames =
258 ARG_DEF(NULL,
"lag-in-frames", 1,
"Max number of frames to lag");
259 static const arg_def_t large_scale_tile = ARG_DEF(
260 NULL,
"large-scale-tile", 1,
261 "Large scale tile coding (0: off (default), 1: on (ivf output only))");
262 static const arg_def_t monochrome =
263 ARG_DEF(NULL,
"monochrome", 0,
"Monochrome video (no chroma planes)");
264 static const arg_def_t full_still_picture_hdr = ARG_DEF(
265 NULL,
"full-still-picture-hdr", 0,
"Use full header for still picture");
267 static const arg_def_t *global_args[] = { &use_yv12,
276 &forced_max_frame_width,
277 &forced_max_frame_height,
283 &global_error_resilient,
288 &full_still_picture_hdr,
291 static const arg_def_t dropframe_thresh =
292 ARG_DEF(NULL,
"drop-frame", 1,
"Temporal resampling threshold (buf %)");
293 static const arg_def_t resize_mode =
294 ARG_DEF(NULL,
"resize-mode", 1,
"Frame resize mode");
295 static const arg_def_t resize_denominator =
296 ARG_DEF(NULL,
"resize-denominator", 1,
"Frame resize denominator");
297 static const arg_def_t resize_kf_denominator = ARG_DEF(
298 NULL,
"resize-kf-denominator", 1,
"Frame resize keyframe denominator");
299 static const arg_def_t superres_mode =
300 ARG_DEF(NULL,
"superres-mode", 1,
"Frame super-resolution mode");
301 static const arg_def_t superres_denominator = ARG_DEF(
302 NULL,
"superres-denominator", 1,
"Frame super-resolution denominator");
303 static const arg_def_t superres_kf_denominator =
304 ARG_DEF(NULL,
"superres-kf-denominator", 1,
305 "Frame super-resolution keyframe denominator");
306 static const arg_def_t superres_qthresh = ARG_DEF(
307 NULL,
"superres-qthresh", 1,
"Frame super-resolution qindex threshold");
308 static const arg_def_t superres_kf_qthresh =
309 ARG_DEF(NULL,
"superres-kf-qthresh", 1,
310 "Frame super-resolution keyframe qindex threshold");
311 static const struct arg_enum_list end_usage_enum[] = { {
"vbr",
AOM_VBR },
316 static const arg_def_t end_usage =
317 ARG_DEF_ENUM(NULL,
"end-usage", 1,
"Rate control mode", end_usage_enum);
318 static const arg_def_t target_bitrate =
319 ARG_DEF(NULL,
"target-bitrate", 1,
"Bitrate (kbps)");
320 static const arg_def_t min_quantizer =
321 ARG_DEF(NULL,
"min-q", 1,
"Minimum (best) quantizer");
322 static const arg_def_t max_quantizer =
323 ARG_DEF(NULL,
"max-q", 1,
"Maximum (worst) quantizer");
324 static const arg_def_t undershoot_pct =
325 ARG_DEF(NULL,
"undershoot-pct", 1,
"Datarate undershoot (min) target (%)");
326 static const arg_def_t overshoot_pct =
327 ARG_DEF(NULL,
"overshoot-pct", 1,
"Datarate overshoot (max) target (%)");
328 static const arg_def_t buf_sz =
329 ARG_DEF(NULL,
"buf-sz", 1,
"Client buffer size (ms)");
330 static const arg_def_t buf_initial_sz =
331 ARG_DEF(NULL,
"buf-initial-sz", 1,
"Client initial buffer size (ms)");
332 static const arg_def_t buf_optimal_sz =
333 ARG_DEF(NULL,
"buf-optimal-sz", 1,
"Client optimal buffer size (ms)");
334 static const arg_def_t *rc_args[] = { &dropframe_thresh,
337 &resize_kf_denominator,
339 &superres_denominator,
340 &superres_kf_denominator,
342 &superres_kf_qthresh,
354 static const arg_def_t bias_pct =
355 ARG_DEF(NULL,
"bias-pct", 1,
"CBR/VBR bias (0=CBR, 100=VBR)");
356 static const arg_def_t minsection_pct =
357 ARG_DEF(NULL,
"minsection-pct", 1,
"GOP min bitrate (% of target)");
358 static const arg_def_t maxsection_pct =
359 ARG_DEF(NULL,
"maxsection-pct", 1,
"GOP max bitrate (% of target)");
360 static const arg_def_t *rc_twopass_args[] = { &bias_pct, &minsection_pct,
361 &maxsection_pct, NULL };
362 static const arg_def_t fwd_kf_enabled =
363 ARG_DEF(NULL,
"enable-fwd-kf", 1,
"Enable forward reference keyframes");
364 static const arg_def_t kf_min_dist =
365 ARG_DEF(NULL,
"kf-min-dist", 1,
"Minimum keyframe interval (frames)");
366 static const arg_def_t kf_max_dist =
367 ARG_DEF(NULL,
"kf-max-dist", 1,
"Maximum keyframe interval (frames)");
368 static const arg_def_t kf_disabled =
369 ARG_DEF(NULL,
"disable-kf", 0,
"Disable keyframe placement");
370 static const arg_def_t *kf_args[] = { &fwd_kf_enabled, &kf_min_dist,
371 &kf_max_dist, &kf_disabled, NULL };
372 static const arg_def_t sframe_dist =
373 ARG_DEF(NULL,
"sframe-dist", 1,
"S-Frame interval (frames)");
374 static const arg_def_t sframe_mode =
375 ARG_DEF(NULL,
"sframe-mode", 1,
"S-Frame insertion mode (1..2)");
376 static const arg_def_t save_as_annexb =
377 ARG_DEF(NULL,
"annexb", 1,
"Save as Annex-B");
378 static const arg_def_t noise_sens =
379 ARG_DEF(NULL,
"noise-sensitivity", 1,
"Noise sensitivity (frames to blur)");
380 static const arg_def_t sharpness =
381 ARG_DEF(NULL,
"sharpness", 1,
"Loop filter sharpness (0..7)");
382 static const arg_def_t static_thresh =
383 ARG_DEF(NULL,
"static-thresh", 1,
"Motion detection threshold");
384 static const arg_def_t auto_altref =
385 ARG_DEF(NULL,
"auto-alt-ref", 1,
"Enable automatic alt reference frames");
386 static const arg_def_t arnr_maxframes =
387 ARG_DEF(NULL,
"arnr-maxframes", 1,
"AltRef max frames (0..15)");
388 static const arg_def_t arnr_strength =
389 ARG_DEF(NULL,
"arnr-strength", 1,
"AltRef filter strength (0..6)");
390 static const struct arg_enum_list tuning_enum[] = {
391 {
"psnr", AOM_TUNE_PSNR },
392 {
"ssim", AOM_TUNE_SSIM },
393 {
"vmaf_with_preprocessing", AOM_TUNE_VMAF_WITH_PREPROCESSING },
394 {
"vmaf_without_preprocessing", AOM_TUNE_VMAF_WITHOUT_PREPROCESSING },
395 {
"vmaf", AOM_TUNE_VMAF_MAX_GAIN },
398 static const arg_def_t tune_metric =
399 ARG_DEF_ENUM(NULL,
"tune", 1,
"Distortion metric tuned with", tuning_enum);
400 static const arg_def_t cq_level =
401 ARG_DEF(NULL,
"cq-level", 1,
"Constant/Constrained Quality level");
402 static const arg_def_t max_intra_rate_pct =
403 ARG_DEF(NULL,
"max-intra-rate", 1,
"Max I-frame bitrate (pct)");
405 #if CONFIG_AV1_ENCODER
406 static const arg_def_t cpu_used_av1 =
407 ARG_DEF(NULL,
"cpu-used", 1,
408 "Speed setting (0..6 in good mode, 6..8 in realtime mode)");
409 static const arg_def_t rowmtarg =
410 ARG_DEF(NULL,
"row-mt", 1,
411 "Enable row based multi-threading (0: off, 1: on (default))");
412 static const arg_def_t tile_cols =
413 ARG_DEF(NULL,
"tile-columns", 1,
"Number of tile columns to use, log2");
414 static const arg_def_t tile_rows =
415 ARG_DEF(NULL,
"tile-rows", 1,
"Number of tile rows to use, log2");
416 static const arg_def_t enable_tpl_model =
417 ARG_DEF(NULL,
"enable-tpl-model", 1,
418 "RDO based on frame temporal dependency "
419 "(0: off, 1: backward source based). "
420 "This is required for deltaq mode.");
421 static const arg_def_t enable_keyframe_filtering =
422 ARG_DEF(NULL,
"enable-keyframe-filtering", 1,
423 "Apply temporal filtering on key frame "
424 "(0: false, 1: true (default)");
425 static const arg_def_t tile_width =
426 ARG_DEF(NULL,
"tile-width", 1,
"Tile widths (comma separated)");
427 static const arg_def_t tile_height =
428 ARG_DEF(NULL,
"tile-height", 1,
"Tile heights (command separated)");
429 static const arg_def_t lossless =
430 ARG_DEF(NULL,
"lossless", 1,
"Lossless mode (0: false (default), 1: true)");
431 static const arg_def_t enable_cdef =
432 ARG_DEF(NULL,
"enable-cdef", 1,
433 "Enable the constrained directional enhancement filter (0: false, "
434 "1: true (default))");
435 static const arg_def_t enable_restoration = ARG_DEF(
436 NULL,
"enable-restoration", 1,
437 "Enable the loop restoration filter (0: false (default in Realtime mode), "
438 "1: true (default in Non-realtime mode))");
439 static const arg_def_t enable_rect_partitions =
440 ARG_DEF(NULL,
"enable-rect-partitions", 1,
441 "Enable rectangular partitions "
442 "(0: false, 1: true (default))");
443 static const arg_def_t enable_ab_partitions =
444 ARG_DEF(NULL,
"enable-ab-partitions", 1,
445 "Enable ab partitions (0: false, 1: true (default))");
446 static const arg_def_t enable_1to4_partitions =
447 ARG_DEF(NULL,
"enable-1to4-partitions", 1,
448 "Enable 1:4 and 4:1 partitions "
449 "(0: false, 1: true (default))");
450 static const arg_def_t min_partition_size =
451 ARG_DEF(NULL,
"min-partition-size", 4,
452 "Set min partition size "
453 "(4:4x4, 8:8x8, 16:16x16, 32:32x32, 64:64x64, 128:128x128). "
454 "On frame with 4k+ resolutions or higher speed settings, the min "
455 "partition size will have a minimum of 8.");
456 static const arg_def_t max_partition_size =
457 ARG_DEF(NULL,
"max-partition-size", 128,
458 "Set max partition size "
459 "(4:4x4, 8:8x8, 16:16x16, 32:32x32, 64:64x64, 128:128x128)");
460 static const arg_def_t enable_dual_filter =
461 ARG_DEF(NULL,
"enable-dual-filter", 1,
462 "Enable dual filter "
463 "(0: false, 1: true (default))");
464 static const arg_def_t enable_chroma_deltaq =
465 ARG_DEF(NULL,
"enable-chroma-deltaq", 1,
466 "Enable chroma delta quant "
467 "(0: false (default), 1: true)");
468 static const arg_def_t enable_intra_edge_filter =
469 ARG_DEF(NULL,
"enable-intra-edge-filter", 1,
470 "Enable intra edge filtering "
471 "(0: false, 1: true (default))");
472 static const arg_def_t enable_order_hint =
473 ARG_DEF(NULL,
"enable-order-hint", 1,
475 "(0: false, 1: true (default))");
476 static const arg_def_t enable_tx64 =
477 ARG_DEF(NULL,
"enable-tx64", 1,
478 "Enable 64-pt transform (0: false, 1: true (default))");
479 static const arg_def_t enable_flip_idtx =
480 ARG_DEF(NULL,
"enable-flip-idtx", 1,
481 "Enable extended transform type (0: false, 1: true (default)) "
482 "including FLIPADST_DCT, DCT_FLIPADST, FLIPADST_FLIPADST, "
483 "ADST_FLIPADST, FLIPADST_ADST, IDTX, V_DCT, H_DCT, V_ADST, "
484 "H_ADST, V_FLIPADST, H_FLIPADST");
485 static const arg_def_t enable_dist_wtd_comp =
486 ARG_DEF(NULL,
"enable-dist-wtd-comp", 1,
487 "Enable distance-weighted compound "
488 "(0: false, 1: true (default))");
489 static const arg_def_t enable_masked_comp =
490 ARG_DEF(NULL,
"enable-masked-comp", 1,
491 "Enable masked (wedge/diff-wtd) compound "
492 "(0: false, 1: true (default))");
493 static const arg_def_t enable_onesided_comp =
494 ARG_DEF(NULL,
"enable-onesided-comp", 1,
495 "Enable one sided compound "
496 "(0: false, 1: true (default))");
497 static const arg_def_t enable_interintra_comp =
498 ARG_DEF(NULL,
"enable-interintra-comp", 1,
499 "Enable interintra compound "
500 "(0: false, 1: true (default))");
501 static const arg_def_t enable_smooth_interintra =
502 ARG_DEF(NULL,
"enable-smooth-interintra", 1,
503 "Enable smooth interintra mode "
504 "(0: false, 1: true (default))");
505 static const arg_def_t enable_diff_wtd_comp =
506 ARG_DEF(NULL,
"enable-diff-wtd-comp", 1,
507 "Enable difference-weighted compound "
508 "(0: false, 1: true (default))");
509 static const arg_def_t enable_interinter_wedge =
510 ARG_DEF(NULL,
"enable-interinter-wedge", 1,
511 "Enable interinter wedge compound "
512 "(0: false, 1: true (default))");
513 static const arg_def_t enable_interintra_wedge =
514 ARG_DEF(NULL,
"enable-interintra-wedge", 1,
515 "Enable interintra wedge compound "
516 "(0: false, 1: true (default))");
517 static const arg_def_t enable_global_motion =
518 ARG_DEF(NULL,
"enable-global-motion", 1,
519 "Enable global motion "
520 "(0: false, 1: true (default))");
521 static const arg_def_t enable_warped_motion =
522 ARG_DEF(NULL,
"enable-warped-motion", 1,
523 "Enable local warped motion "
524 "(0: false, 1: true (default))");
525 static const arg_def_t enable_filter_intra =
526 ARG_DEF(NULL,
"enable-filter-intra", 1,
527 "Enable filter intra prediction mode "
528 "(0: false, 1: true (default))");
529 static const arg_def_t enable_smooth_intra =
530 ARG_DEF(NULL,
"enable-smooth-intra", 1,
531 "Enable smooth intra prediction modes "
532 "(0: false, 1: true (default))");
533 static const arg_def_t enable_paeth_intra =
534 ARG_DEF(NULL,
"enable-paeth-intra", 1,
535 "Enable Paeth intra prediction mode (0: false, 1: true (default))");
536 static const arg_def_t enable_cfl_intra =
537 ARG_DEF(NULL,
"enable-cfl-intra", 1,
538 "Enable chroma from luma intra prediction mode "
539 "(0: false, 1: true (default))");
540 static const arg_def_t force_video_mode =
541 ARG_DEF(NULL,
"force-video-mode", 1,
542 "Force video mode (0: false, 1: true (default))");
543 static const arg_def_t enable_obmc = ARG_DEF(
544 NULL,
"enable-obmc", 1,
"Enable OBMC (0: false, 1: true (default))");
545 static const arg_def_t enable_overlay =
546 ARG_DEF(NULL,
"enable-overlay", 1,
547 "Enable coding overlay frames (0: false, 1: true (default))");
548 static const arg_def_t enable_palette =
549 ARG_DEF(NULL,
"enable-palette", 1,
550 "Enable palette prediction mode (0: false, 1: true (default))");
551 static const arg_def_t enable_intrabc =
552 ARG_DEF(NULL,
"enable-intrabc", 1,
553 "Enable intra block copy prediction mode "
554 "(0: false, 1: true (default))");
555 static const arg_def_t enable_angle_delta =
556 ARG_DEF(NULL,
"enable-angle-delta", 1,
557 "Enable intra angle delta (0: false, 1: true (default))");
558 static const arg_def_t disable_trellis_quant =
559 ARG_DEF(NULL,
"disable-trellis-quant", 1,
560 "Disable trellis optimization of quantized coefficients (0: false "
561 "1: true 2: true for rd search 3: true for estimate yrd serch "
563 static const arg_def_t enable_qm =
564 ARG_DEF(NULL,
"enable-qm", 1,
565 "Enable quantisation matrices (0: false (default), 1: true)");
566 static const arg_def_t qm_min = ARG_DEF(
567 NULL,
"qm-min", 1,
"Min quant matrix flatness (0..15), default is 8");
568 static const arg_def_t qm_max = ARG_DEF(
569 NULL,
"qm-max", 1,
"Max quant matrix flatness (0..15), default is 15");
570 static const arg_def_t reduced_tx_type_set = ARG_DEF(
571 NULL,
"reduced-tx-type-set", 1,
"Use reduced set of transform types");
572 static const arg_def_t use_intra_dct_only =
573 ARG_DEF(NULL,
"use-intra-dct-only", 1,
"Use DCT only for INTRA modes");
574 static const arg_def_t use_inter_dct_only =
575 ARG_DEF(NULL,
"use-inter-dct-only", 1,
"Use DCT only for INTER modes");
576 static const arg_def_t use_intra_default_tx_only =
577 ARG_DEF(NULL,
"use-intra-default-tx-only", 1,
578 "Use Default-transform only for INTRA modes");
579 static const arg_def_t quant_b_adapt =
580 ARG_DEF(NULL,
"quant-b-adapt", 1,
"Use adaptive quantize_b");
581 static const arg_def_t coeff_cost_upd_freq =
582 ARG_DEF(NULL,
"coeff-cost-upd-freq", 1,
583 "Update freq for coeff costs"
584 "0: SB, 1: SB Row per Tile, 2: Tile");
585 static const arg_def_t mode_cost_upd_freq =
586 ARG_DEF(NULL,
"mode-cost-upd-freq", 1,
587 "Update freq for mode costs"
588 "0: SB, 1: SB Row per Tile, 2: Tile");
589 static const arg_def_t mv_cost_upd_freq =
590 ARG_DEF(NULL,
"mv-cost-upd-freq", 1,
591 "Update freq for mv costs"
592 "0: SB, 1: SB Row per Tile, 2: Tile, 3: Off");
593 static const arg_def_t num_tg = ARG_DEF(
594 NULL,
"num-tile-groups", 1,
"Maximum number of tile groups, default is 1");
595 static const arg_def_t mtu_size =
596 ARG_DEF(NULL,
"mtu-size", 1,
597 "MTU size for a tile group, default is 0 (no MTU targeting), "
598 "overrides maximum number of tile groups");
599 static const struct arg_enum_list timing_info_enum[] = {
600 {
"unspecified", AOM_TIMING_UNSPECIFIED },
601 {
"constant", AOM_TIMING_EQUAL },
602 {
"model", AOM_TIMING_DEC_MODEL },
605 static const arg_def_t timing_info =
606 ARG_DEF_ENUM(NULL,
"timing-info", 1,
607 "Signal timing info in the bitstream (model unly works for no "
608 "hidden frames, no super-res yet):",
611 static const arg_def_t vmaf_model_path =
612 ARG_DEF(NULL,
"vmaf-model-path", 1,
"Path to the VMAF model file");
614 static const arg_def_t film_grain_test =
615 ARG_DEF(NULL,
"film-grain-test", 1,
616 "Film grain test vectors (0: none (default), 1: test-1 2: test-2, "
618 static const arg_def_t film_grain_table =
619 ARG_DEF(NULL,
"film-grain-table", 1,
620 "Path to file containing film grain parameters");
622 static const arg_def_t denoise_noise_level =
623 ARG_DEF(NULL,
"denoise-noise-level", 1,
624 "Amount of noise (from 0 = don't denoise, to 50)");
625 static const arg_def_t denoise_block_size =
626 ARG_DEF(NULL,
"denoise-block-size", 1,
"Denoise block size (default = 32)");
628 static const arg_def_t enable_ref_frame_mvs =
629 ARG_DEF(NULL,
"enable-ref-frame-mvs", 1,
630 "Enable temporal mv prediction (default is 1)");
631 static const arg_def_t frame_parallel_decoding =
632 ARG_DEF(NULL,
"frame-parallel", 1,
633 "Enable frame parallel decodability features "
634 "(0: false (default), 1: true)");
635 static const arg_def_t error_resilient_mode =
636 ARG_DEF(NULL,
"error-resilient", 1,
637 "Enable error resilient features "
638 "(0: false (default), 1: true)");
639 static const arg_def_t aq_mode = ARG_DEF(
641 "Adaptive quantization mode (0: off (default), 1: variance 2: complexity, "
642 "3: cyclic refresh)");
643 static const arg_def_t deltaq_mode =
644 ARG_DEF(NULL,
"deltaq-mode", 1,
645 "Delta qindex mode (0: off, 1: deltaq objective (default), "
646 "2: deltaq perceptual). "
647 "Currently this requires enable-tpl-model as a prerequisite.");
648 static const arg_def_t deltalf_mode = ARG_DEF(
649 NULL,
"delta-lf-mode", 1,
"Enable delta-lf-mode (0: off (default), 1: on)");
650 static const arg_def_t frame_periodic_boost =
651 ARG_DEF(NULL,
"frame-boost", 1,
652 "Enable frame periodic boost (0: off (default), 1: on)");
653 static const arg_def_t gf_cbr_boost_pct = ARG_DEF(
654 NULL,
"gf-cbr-boost", 1,
"Boost for Golden Frame in CBR mode (pct)");
655 static const arg_def_t max_inter_rate_pct =
656 ARG_DEF(NULL,
"max-inter-rate", 1,
"Max P-frame bitrate (pct)");
657 static const arg_def_t min_gf_interval = ARG_DEF(
658 NULL,
"min-gf-interval", 1,
659 "min gf/arf frame interval (default 0, indicating in-built behavior)");
660 static const arg_def_t max_gf_interval = ARG_DEF(
661 NULL,
"max-gf-interval", 1,
662 "max gf/arf frame interval (default 0, indicating in-built behavior)");
663 static const arg_def_t gf_min_pyr_height =
664 ARG_DEF(NULL,
"gf-min-pyr-height", 1,
665 "Min height for GF group pyramid structure (0 (default) to 5)");
666 static const arg_def_t gf_max_pyr_height =
667 ARG_DEF(NULL,
"gf-max-pyr-height", 1,
668 "maximum height for GF group pyramid structure (0 to 5 (default))");
669 static const arg_def_t max_reference_frames = ARG_DEF(
670 NULL,
"max-reference-frames", 1,
671 "maximum number of reference frames allowed per frame (3 to 7 (default))");
672 static const arg_def_t reduced_reference_set =
673 ARG_DEF(NULL,
"reduced-reference-set", 1,
674 "Use reduced set of single and compound references (0: off "
675 "(default), 1: on)");
676 static const arg_def_t target_seq_level_idx =
677 ARG_DEF(NULL,
"target-seq-level-idx", 1,
678 "Target sequence level index. "
679 "Possible values are in the form of \"ABxy\"(pad leading zeros if "
680 "less than 4 digits). "
681 "AB: Operating point(OP) index; "
682 "xy: Target level index for the OP. "
683 "E.g. \"0\" means target level index 0 for the 0th OP; "
684 "\"1021\" means target level index 21 for the 10th OP.");
685 static const arg_def_t set_min_cr =
686 ARG_DEF(NULL,
"min-cr", 1,
687 "Set minimum compression ratio. Take integer values. Default is 0. "
688 "If non-zero, encoder will try to keep the compression ratio of "
689 "each frame to be higher than the given value divided by 100.");
691 static const struct arg_enum_list color_primaries_enum[] = {
707 static const arg_def_t input_color_primaries = ARG_DEF_ENUM(
708 NULL,
"color-primaries", 1,
709 "Color primaries (CICP) of input content:", color_primaries_enum);
711 static const struct arg_enum_list transfer_characteristics_enum[] = {
732 static const arg_def_t input_transfer_characteristics =
733 ARG_DEF_ENUM(NULL,
"transfer-characteristics", 1,
734 "Transfer characteristics (CICP) of input content:",
735 transfer_characteristics_enum);
737 static const struct arg_enum_list matrix_coefficients_enum[] = {
755 static const arg_def_t input_matrix_coefficients = ARG_DEF_ENUM(
756 NULL,
"matrix-coefficients", 1,
757 "Matrix coefficients (CICP) of input content:", matrix_coefficients_enum);
759 static const struct arg_enum_list chroma_sample_position_enum[] = {
766 static const arg_def_t input_chroma_sample_position =
767 ARG_DEF_ENUM(NULL,
"chroma-sample-position", 1,
768 "The chroma sample position when chroma 4:2:0 is signaled:",
769 chroma_sample_position_enum);
771 static const struct arg_enum_list tune_content_enum[] = {
772 {
"default", AOM_CONTENT_DEFAULT },
773 {
"screen", AOM_CONTENT_SCREEN },
777 static const arg_def_t tune_content = ARG_DEF_ENUM(
778 NULL,
"tune-content", 1,
"Tune content type", tune_content_enum);
780 static const arg_def_t cdf_update_mode =
781 ARG_DEF(NULL,
"cdf-update-mode", 1,
782 "CDF update mode for entropy coding "
783 "(0: no CDF update; 1: update CDF on all frames(default); "
784 "2: selectively update CDF on some frames");
786 static const struct arg_enum_list superblock_size_enum[] = {
792 static const arg_def_t superblock_size = ARG_DEF_ENUM(
793 NULL,
"sb-size", 1,
"Superblock size to use", superblock_size_enum);
795 static const arg_def_t set_tier_mask =
796 ARG_DEF(NULL,
"set-tier-mask", 1,
797 "Set bit mask to specify which tier each of the 32 possible "
798 "operating points conforms to. "
799 "Bit value 0(defualt): Main Tier; 1: High Tier.");
801 static const arg_def_t use_fixed_qp_offsets =
802 ARG_DEF(NULL,
"use-fixed-qp-offsets", 1,
803 "Enable fixed QP offsets for frames at different levels of the "
804 "pyramid. Selected automatically from --cq-level if "
805 "--fixed-qp-offsets is not provided. If this option is not "
806 "specified (default), offsets are adaptively chosen by the "
809 static const arg_def_t fixed_qp_offsets =
810 ARG_DEF(NULL,
"fixed-qp-offsets", 1,
811 "Set fixed QP offsets for frames at different levels of the "
812 "pyramid. Comma-separated list of 5 offsets for keyframe, ALTREF, "
813 "and 3 levels of internal alt-refs. If this option is not "
814 "specified (default), offsets are adaptively chosen by the "
817 static const arg_def_t *av1_args[] = { &cpu_used_av1,
825 &enable_keyframe_filtering,
836 &enable_rect_partitions,
837 &enable_ab_partitions,
838 &enable_1to4_partitions,
842 &enable_chroma_deltaq,
843 &enable_intra_edge_filter,
847 &enable_dist_wtd_comp,
849 &enable_onesided_comp,
850 &enable_interintra_comp,
851 &enable_smooth_interintra,
852 &enable_diff_wtd_comp,
853 &enable_interinter_wedge,
854 &enable_interintra_wedge,
855 &enable_global_motion,
856 &enable_warped_motion,
857 &enable_filter_intra,
858 &enable_smooth_intra,
867 &disable_trellis_quant,
871 &reduced_tx_type_set,
874 &use_intra_default_tx_only,
876 &coeff_cost_upd_freq,
879 &frame_parallel_decoding,
880 &error_resilient_mode,
884 &frame_periodic_boost,
888 &input_color_primaries,
889 &input_transfer_characteristics,
890 &input_matrix_coefficients,
891 &input_chroma_sample_position,
903 &denoise_noise_level,
906 &max_reference_frames,
907 &reduced_reference_set,
908 &enable_ref_frame_mvs,
909 &target_seq_level_idx,
914 &input_chroma_subsampling_x,
915 &input_chroma_subsampling_y,
1018 #if CONFIG_TUNE_VMAF
1024 static const arg_def_t *no_args[] = { NULL };
1026 static void show_help(FILE *fout,
int shorthelp) {
1027 fprintf(fout,
"Usage: %s <options> -o dst_filename src_filename \n",
1031 fprintf(fout,
"Use --help to see the full list of options.\n");
1035 fprintf(fout,
"\nOptions:\n");
1036 arg_show_usage(fout, main_args);
1037 fprintf(fout,
"\nEncoder Global Options:\n");
1038 arg_show_usage(fout, global_args);
1039 fprintf(fout,
"\nRate Control Options:\n");
1040 arg_show_usage(fout, rc_args);
1041 fprintf(fout,
"\nTwopass Rate Control Options:\n");
1042 arg_show_usage(fout, rc_twopass_args);
1043 fprintf(fout,
"\nKeyframe Placement Options:\n");
1044 arg_show_usage(fout, kf_args);
1045 #if CONFIG_AV1_ENCODER
1046 fprintf(fout,
"\nAV1 Specific Options:\n");
1047 arg_show_usage(fout, av1_args);
1050 "\nStream timebase (--timebase):\n"
1051 " The desired precision of timestamps in the output, expressed\n"
1052 " in fractional seconds. Default is 1/1000.\n");
1053 fprintf(fout,
"\nIncluded encoders:\n\n");
1055 const int num_encoder = get_aom_encoder_count();
1056 for (
int i = 0; i < num_encoder; ++i) {
1057 const AvxInterface *
const encoder = get_aom_encoder_by_index(i);
1058 const char *defstr = (i == (num_encoder - 1)) ?
"(default)" :
"";
1059 fprintf(fout,
" %-6s - %s %s\n", encoder->name,
1062 fprintf(fout,
"\n ");
1063 fprintf(fout,
"Use --codec to switch to a non-default encoder.\n\n");
1066 void usage_exit(
void) {
1067 show_help(stderr, 1);
1071 #if CONFIG_AV1_ENCODER
1072 #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
1076 typedef int stereo_format_t;
1077 struct WebmOutputContext {
1083 struct stream_config {
1086 const char *stats_fn;
1087 stereo_format_t stereo_fmt;
1088 int arg_ctrls[ARG_CTRL_CNT_MAX][2];
1091 const char *film_grain_filename;
1094 int use_16bit_internal;
1095 #if CONFIG_TUNE_VMAF
1096 const char *vmaf_model_path;
1100 struct stream_state {
1102 struct stream_state *next;
1103 struct stream_config config;
1105 struct rate_hist *rate_hist;
1106 struct WebmOutputContext webm_ctx;
1107 uint64_t psnr_sse_total;
1108 uint64_t psnr_samples_total;
1109 double psnr_totals[4];
1113 unsigned int frames_out;
1120 unsigned int chroma_subsampling_x;
1121 unsigned int chroma_subsampling_y;
1124 static void validate_positive_rational(
const char *msg,
1131 if (rat->
num < 0) die(
"Error: %s must be positive\n", msg);
1133 if (!rat->
den) die(
"Error: %s has zero denominator\n", msg);
1147 static void parse_global_config(
struct AvxEncoderConfig *global,
char ***argv) {
1148 char **argi, **argj;
1150 const int num_encoder = get_aom_encoder_count();
1151 char **argv_local = (
char **)*argv;
1152 if (num_encoder < 1) die(
"Error: no valid encoder available\n");
1155 memset(global, 0,
sizeof(*global));
1156 global->codec = get_aom_encoder_by_index(num_encoder - 1);
1158 global->color_type = I420;
1161 int cfg_included = 0;
1162 init_config(&global->encoder_config);
1164 for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
1167 if (arg_match(&arg, &use_cfg, argi)) {
1168 if (cfg_included)
continue;
1169 parse_cfg(arg.val, &global->encoder_config);
1173 if (arg_match(&arg, &help, argi)) {
1174 show_help(stdout, 0);
1176 }
else if (arg_match(&arg, &codecarg, argi)) {
1177 global->codec = get_aom_encoder_by_name(arg.val);
1179 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
1180 }
else if (arg_match(&arg, &passes, argi)) {
1181 global->passes = arg_parse_uint(&arg);
1183 if (global->passes < 1 || global->passes > 2)
1184 die(
"Error: Invalid number of passes (%d)\n", global->passes);
1185 }
else if (arg_match(&arg, &pass_arg, argi)) {
1186 global->pass = arg_parse_uint(&arg);
1188 if (global->pass < 1 || global->pass > 2)
1189 die(
"Error: Invalid pass selected (%d)\n", global->pass);
1190 }
else if (arg_match(&arg, &input_chroma_sample_position, argi)) {
1191 global->csp = arg_parse_enum(&arg);
1194 }
else if (arg_match(&arg, &usage, argi))
1195 global->usage = arg_parse_uint(&arg);
1196 else if (arg_match(&arg, &good_dl, argi))
1198 else if (arg_match(&arg, &rt_dl, argi))
1200 else if (arg_match(&arg, &use_yv12, argi))
1201 global->color_type = YV12;
1202 else if (arg_match(&arg, &use_i420, argi))
1203 global->color_type = I420;
1204 else if (arg_match(&arg, &use_i422, argi))
1205 global->color_type = I422;
1206 else if (arg_match(&arg, &use_i444, argi))
1207 global->color_type = I444;
1208 else if (arg_match(&arg, &quietarg, argi))
1210 else if (arg_match(&arg, &verbosearg, argi))
1211 global->verbose = 1;
1212 else if (arg_match(&arg, &limit, argi))
1213 global->limit = arg_parse_uint(&arg);
1214 else if (arg_match(&arg, &skip, argi))
1215 global->skip_frames = arg_parse_uint(&arg);
1216 else if (arg_match(&arg, &psnrarg, argi))
1217 global->show_psnr = 1;
1218 else if (arg_match(&arg, &recontest, argi))
1219 global->test_decode = arg_parse_enum_or_int(&arg);
1220 else if (arg_match(&arg, &framerate, argi)) {
1221 global->framerate = arg_parse_rational(&arg);
1222 validate_positive_rational(arg.name, &global->framerate);
1223 global->have_framerate = 1;
1224 }
else if (arg_match(&arg, &debugmode, argi))
1226 else if (arg_match(&arg, &q_hist_n, argi))
1227 global->show_q_hist_buckets = arg_parse_uint(&arg);
1228 else if (arg_match(&arg, &rate_hist_n, argi))
1229 global->show_rate_hist_buckets = arg_parse_uint(&arg);
1230 else if (arg_match(&arg, &disable_warnings, argi))
1231 global->disable_warnings = 1;
1232 else if (arg_match(&arg, &disable_warning_prompt, argi))
1233 global->disable_warning_prompt = 1;
1240 if (global->pass > global->passes) {
1241 warn(
"Assuming --pass=%d implies --passes=%d\n", global->pass,
1243 global->passes = global->pass;
1247 if (global->passes == 0) {
1248 #if CONFIG_AV1_ENCODER
1251 if (global->codec != NULL && global->codec->name != NULL)
1252 global->passes = (strcmp(global->codec->name,
"av1") == 0 &&
1262 warn(
"Enforcing one-pass encoding in realtime mode\n");
1267 static void open_input_file(
struct AvxInputContext *input,
1270 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
1271 : set_binary_mode(stdin);
1273 if (!input->file) fatal(
"Failed to open input file");
1275 if (!fseeko(input->file, 0, SEEK_END)) {
1279 input->length = ftello(input->file);
1280 rewind(input->file);
1284 input->pixel_aspect_ratio.numerator = 1;
1285 input->pixel_aspect_ratio.denominator = 1;
1290 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
1291 input->detect.position = 0;
1293 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
1294 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
1295 input->only_i420) >= 0) {
1296 input->file_type = FILE_TYPE_Y4M;
1297 input->width = input->y4m.pic_w;
1298 input->height = input->y4m.pic_h;
1299 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
1300 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
1301 input->framerate.numerator = input->y4m.fps_n;
1302 input->framerate.denominator = input->y4m.fps_d;
1303 input->fmt = input->y4m.aom_fmt;
1304 input->bit_depth = input->y4m.bit_depth;
1306 fatal(
"Unsupported Y4M stream.");
1307 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
1308 fatal(
"IVF is not supported as input.");
1310 input->file_type = FILE_TYPE_RAW;
1314 static void close_input_file(
struct AvxInputContext *input) {
1315 fclose(input->file);
1316 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
1319 static struct stream_state *new_stream(
struct AvxEncoderConfig *global,
1320 struct stream_state *prev) {
1321 struct stream_state *stream;
1323 stream = calloc(1,
sizeof(*stream));
1324 if (stream == NULL) {
1325 fatal(
"Failed to allocate new stream.");
1329 memcpy(stream, prev,
sizeof(*stream));
1331 prev->next = stream;
1337 &stream->config.cfg, global->usage);
1343 stream->config.cfg.g_timebase.den = 1000;
1348 stream->config.cfg.g_w = 0;
1349 stream->config.cfg.g_h = 0;
1352 stream->config.write_webm = 1;
1353 stream->config.write_ivf = 0;
1356 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
1357 stream->webm_ctx.last_pts_ns = -1;
1358 stream->webm_ctx.writer = NULL;
1359 stream->webm_ctx.segment = NULL;
1363 stream->webm_ctx.debug = global->debug;
1364 memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
1365 sizeof(stream->config.cfg.encoder_cfg));
1369 stream->config.out_fn = NULL;
1371 stream->next = NULL;
1375 static void set_config_arg_ctrls(
struct stream_config *config,
int key,
1376 const struct arg *arg) {
1379 config->film_grain_filename = arg->val;
1386 j = config->arg_ctrl_cnt;
1387 assert(j < (
int)ARG_CTRL_CNT_MAX);
1388 config->arg_ctrls[j][0] = key;
1389 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
1390 ++config->arg_ctrl_cnt;
1397 for (j = 0; j < config->arg_ctrl_cnt; j++)
1398 if (config->arg_ctrls[j][0] == key)
break;
1401 assert(j < (
int)ARG_CTRL_CNT_MAX);
1402 config->arg_ctrls[j][0] = key;
1403 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
1406 warn(
"auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
1407 config->arg_ctrls[j][1] = 1;
1409 if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
1412 static int parse_stream_params(
struct AvxEncoderConfig *global,
1413 struct stream_state *stream,
char **argv) {
1414 char **argi, **argj;
1416 static const arg_def_t **ctrl_args = no_args;
1417 static const int *ctrl_args_map = NULL;
1418 struct stream_config *config = &stream->config;
1419 int eos_mark_found = 0;
1420 int webm_forced = 0;
1424 #if CONFIG_AV1_ENCODER
1425 }
else if (strcmp(global->codec->name,
"av1") == 0) {
1428 ctrl_args = av1_args;
1429 ctrl_args_map = av1_arg_ctrl_map;
1433 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
1439 if (eos_mark_found) {
1442 }
else if (!strcmp(*argj,
"--")) {
1447 if (arg_match(&arg, &outputfile, argi)) {
1448 config->out_fn = arg.val;
1450 const size_t out_fn_len = strlen(config->out_fn);
1451 if (out_fn_len >= 4 &&
1452 !strcmp(config->out_fn + out_fn_len - 4,
".ivf")) {
1453 config->write_webm = 0;
1454 config->write_ivf = 1;
1455 }
else if (out_fn_len >= 4 &&
1456 !strcmp(config->out_fn + out_fn_len - 4,
".obu")) {
1457 config->write_webm = 0;
1458 config->write_ivf = 0;
1461 }
else if (arg_match(&arg, &fpf_name, argi)) {
1462 config->stats_fn = arg.val;
1463 }
else if (arg_match(&arg, &use_webm, argi)) {
1465 config->write_webm = 1;
1468 die(
"Error: --webm specified but webm is disabled.");
1470 }
else if (arg_match(&arg, &use_ivf, argi)) {
1471 config->write_webm = 0;
1472 config->write_ivf = 1;
1473 }
else if (arg_match(&arg, &use_obu, argi)) {
1474 config->write_webm = 0;
1475 config->write_ivf = 0;
1476 }
else if (arg_match(&arg, &threads, argi)) {
1477 config->cfg.g_threads = arg_parse_uint(&arg);
1478 }
else if (arg_match(&arg, &profile, argi)) {
1479 config->cfg.g_profile = arg_parse_uint(&arg);
1480 }
else if (arg_match(&arg, &width, argi)) {
1481 config->cfg.g_w = arg_parse_uint(&arg);
1482 }
else if (arg_match(&arg, &height, argi)) {
1483 config->cfg.g_h = arg_parse_uint(&arg);
1484 }
else if (arg_match(&arg, &forced_max_frame_width, argi)) {
1485 config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
1486 }
else if (arg_match(&arg, &forced_max_frame_height, argi)) {
1487 config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
1488 }
else if (arg_match(&arg, &bitdeptharg, argi)) {
1489 config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
1490 }
else if (arg_match(&arg, &inbitdeptharg, argi)) {
1491 config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
1492 }
else if (arg_match(&arg, &input_chroma_subsampling_x, argi)) {
1493 stream->chroma_subsampling_x = arg_parse_uint(&arg);
1494 }
else if (arg_match(&arg, &input_chroma_subsampling_y, argi)) {
1495 stream->chroma_subsampling_y = arg_parse_uint(&arg);
1497 }
else if (arg_match(&arg, &stereo_mode, argi)) {
1498 config->stereo_fmt = arg_parse_enum_or_int(&arg);
1500 }
else if (arg_match(&arg, &timebase, argi)) {
1501 config->cfg.g_timebase = arg_parse_rational(&arg);
1502 validate_positive_rational(arg.name, &config->cfg.g_timebase);
1503 }
else if (arg_match(&arg, &global_error_resilient, argi)) {
1504 config->cfg.g_error_resilient = arg_parse_uint(&arg);
1505 }
else if (arg_match(&arg, &lag_in_frames, argi)) {
1506 config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
1508 config->cfg.rc_end_usage ==
AOM_CBR &&
1509 config->cfg.g_lag_in_frames != 0) {
1510 warn(
"non-zero %s option ignored in realtime CBR mode.\n", arg.name);
1511 config->cfg.g_lag_in_frames = 0;
1513 }
else if (arg_match(&arg, &large_scale_tile, argi)) {
1514 config->cfg.large_scale_tile = arg_parse_uint(&arg);
1515 if (config->cfg.large_scale_tile) global->codec = get_aom_lst_encoder();
1516 }
else if (arg_match(&arg, &monochrome, argi)) {
1517 config->cfg.monochrome = 1;
1518 }
else if (arg_match(&arg, &full_still_picture_hdr, argi)) {
1519 config->cfg.full_still_picture_hdr = 1;
1520 }
else if (arg_match(&arg, &dropframe_thresh, argi)) {
1521 config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
1522 }
else if (arg_match(&arg, &resize_mode, argi)) {
1523 config->cfg.rc_resize_mode = arg_parse_uint(&arg);
1524 }
else if (arg_match(&arg, &resize_denominator, argi)) {
1525 config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
1526 }
else if (arg_match(&arg, &resize_kf_denominator, argi)) {
1527 config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
1528 }
else if (arg_match(&arg, &superres_mode, argi)) {
1529 config->cfg.rc_superres_mode = arg_parse_uint(&arg);
1530 }
else if (arg_match(&arg, &superres_denominator, argi)) {
1531 config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
1532 }
else if (arg_match(&arg, &superres_kf_denominator, argi)) {
1533 config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
1534 }
else if (arg_match(&arg, &superres_qthresh, argi)) {
1535 config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
1536 }
else if (arg_match(&arg, &superres_kf_qthresh, argi)) {
1537 config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
1538 }
else if (arg_match(&arg, &end_usage, argi)) {
1539 config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
1540 }
else if (arg_match(&arg, &target_bitrate, argi)) {
1541 config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
1542 }
else if (arg_match(&arg, &min_quantizer, argi)) {
1543 config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
1544 }
else if (arg_match(&arg, &max_quantizer, argi)) {
1545 config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
1546 }
else if (arg_match(&arg, &undershoot_pct, argi)) {
1547 config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
1548 }
else if (arg_match(&arg, &overshoot_pct, argi)) {
1549 config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
1550 }
else if (arg_match(&arg, &buf_sz, argi)) {
1551 config->cfg.rc_buf_sz = arg_parse_uint(&arg);
1552 }
else if (arg_match(&arg, &buf_initial_sz, argi)) {
1553 config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
1554 }
else if (arg_match(&arg, &buf_optimal_sz, argi)) {
1555 config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
1556 }
else if (arg_match(&arg, &bias_pct, argi)) {
1557 config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
1558 if (global->passes < 2)
1559 warn(
"option %s ignored in one-pass mode.\n", arg.name);
1560 }
else if (arg_match(&arg, &minsection_pct, argi)) {
1561 config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
1563 if (global->passes < 2)
1564 warn(
"option %s ignored in one-pass mode.\n", arg.name);
1565 }
else if (arg_match(&arg, &maxsection_pct, argi)) {
1566 config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
1568 if (global->passes < 2)
1569 warn(
"option %s ignored in one-pass mode.\n", arg.name);
1570 }
else if (arg_match(&arg, &fwd_kf_enabled, argi)) {
1571 config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
1572 }
else if (arg_match(&arg, &kf_min_dist, argi)) {
1573 config->cfg.kf_min_dist = arg_parse_uint(&arg);
1574 }
else if (arg_match(&arg, &kf_max_dist, argi)) {
1575 config->cfg.kf_max_dist = arg_parse_uint(&arg);
1576 }
else if (arg_match(&arg, &kf_disabled, argi)) {
1578 }
else if (arg_match(&arg, &sframe_dist, argi)) {
1579 config->cfg.sframe_dist = arg_parse_uint(&arg);
1580 }
else if (arg_match(&arg, &sframe_mode, argi)) {
1581 config->cfg.sframe_mode = arg_parse_uint(&arg);
1582 }
else if (arg_match(&arg, &save_as_annexb, argi)) {
1583 config->cfg.save_as_annexb = arg_parse_uint(&arg);
1584 }
else if (arg_match(&arg, &tile_width, argi)) {
1585 config->cfg.tile_width_count =
1587 }
else if (arg_match(&arg, &tile_height, argi)) {
1588 config->cfg.tile_height_count =
1590 #if CONFIG_TUNE_VMAF
1591 }
else if (arg_match(&arg, &vmaf_model_path, argi)) {
1592 config->vmaf_model_path = arg.val;
1594 }
else if (arg_match(&arg, &use_fixed_qp_offsets, argi)) {
1595 config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg);
1596 }
else if (arg_match(&arg, &fixed_qp_offsets, argi)) {
1597 const int fixed_qp_offset_count = arg_parse_list(
1600 die(
"Option --fixed_qp_offsets requires %d comma-separated values, but "
1601 "only %d values were provided.\n",
1604 config->cfg.use_fixed_qp_offsets = 1;
1606 arg_match(&arg, &enable_restoration, argi)) {
1607 if (arg_parse_uint(&arg) == 1) {
1608 warn(
"non-zero %s option ignored in realtime mode.\n", arg.name);
1612 for (i = 0; ctrl_args[i]; i++) {
1613 if (arg_match(&arg, ctrl_args[i], argi)) {
1615 if (ctrl_args_map) {
1616 set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1623 config->use_16bit_internal =
1624 config->cfg.g_bit_depth >
AOM_BITS_8 || FORCE_HIGHBITDEPTH_DECODING;
1625 return eos_mark_found;
1628 #define FOREACH_STREAM(iterator, list) \
1629 for (struct stream_state *iterator = list; iterator; \
1630 iterator = iterator->next)
1632 static void validate_stream_config(
const struct stream_state *stream,
1633 const struct AvxEncoderConfig *global) {
1634 const struct stream_state *streami;
1637 if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1639 "Stream %d: Specify stream dimensions with --width (-w) "
1640 " and --height (-h)",
1646 assert(stream->config.cfg.g_input_bit_depth <=
1647 (
unsigned int)stream->config.cfg.g_bit_depth);
1649 for (streami = stream; streami; streami = streami->next) {
1651 if (!streami->config.out_fn)
1652 fatal(
"Stream %d: Output file is required (specify with -o)",
1656 if (streami != stream) {
1657 const char *a = stream->config.out_fn;
1658 const char *b = streami->config.out_fn;
1659 if (!strcmp(a, b) && strcmp(a,
"/dev/null") && strcmp(a,
":nul"))
1660 fatal(
"Stream %d: duplicate output file (from stream %d)",
1661 streami->index, stream->index);
1665 if (streami != stream) {
1666 const char *a = stream->config.stats_fn;
1667 const char *b = streami->config.stats_fn;
1668 if (a && b && !strcmp(a, b))
1669 fatal(
"Stream %d: duplicate stats file (from stream %d)",
1670 streami->index, stream->index);
1675 static void set_stream_dimensions(
struct stream_state *stream,
unsigned int w,
1677 if (!stream->config.cfg.g_w) {
1678 if (!stream->config.cfg.g_h)
1679 stream->config.cfg.g_w = w;
1681 stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1683 if (!stream->config.cfg.g_h) {
1684 stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1688 static const char *file_type_to_string(
enum VideoFileType t) {
1690 case FILE_TYPE_RAW:
return "RAW";
1691 case FILE_TYPE_Y4M:
return "Y4M";
1692 default:
return "Other";
1696 static const char *image_format_to_string(
aom_img_fmt_t f) {
1706 default:
return "Other";
1710 static void show_stream_config(
struct stream_state *stream,
1711 struct AvxEncoderConfig *global,
1712 struct AvxInputContext *input) {
1713 #define SHOW(field) \
1714 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1716 if (stream->index == 0) {
1717 fprintf(stderr,
"Codec: %s\n",
1719 fprintf(stderr,
"Source file: %s File Type: %s Format: %s\n",
1720 input->filename, file_type_to_string(input->file_type),
1721 image_format_to_string(input->fmt));
1723 if (stream->next || stream->index)
1724 fprintf(stderr,
"\nStream Index: %d\n", stream->index);
1725 fprintf(stderr,
"Destination file: %s\n", stream->config.out_fn);
1726 fprintf(stderr,
"Coding path: %s\n",
1727 stream->config.use_16bit_internal ?
"HBD" :
"LBD");
1728 fprintf(stderr,
"Encoder parameters:\n");
1736 SHOW(g_input_bit_depth);
1737 SHOW(g_timebase.num);
1738 SHOW(g_timebase.den);
1739 SHOW(g_error_resilient);
1741 SHOW(g_lag_in_frames);
1742 SHOW(large_scale_tile);
1743 SHOW(rc_dropframe_thresh);
1744 SHOW(rc_resize_mode);
1745 SHOW(rc_resize_denominator);
1746 SHOW(rc_resize_kf_denominator);
1747 SHOW(rc_superres_mode);
1748 SHOW(rc_superres_denominator);
1749 SHOW(rc_superres_kf_denominator);
1750 SHOW(rc_superres_qthresh);
1751 SHOW(rc_superres_kf_qthresh);
1753 SHOW(rc_target_bitrate);
1754 SHOW(rc_min_quantizer);
1755 SHOW(rc_max_quantizer);
1756 SHOW(rc_undershoot_pct);
1757 SHOW(rc_overshoot_pct);
1759 SHOW(rc_buf_initial_sz);
1760 SHOW(rc_buf_optimal_sz);
1761 SHOW(rc_2pass_vbr_bias_pct);
1762 SHOW(rc_2pass_vbr_minsection_pct);
1763 SHOW(rc_2pass_vbr_maxsection_pct);
1764 SHOW(fwd_kf_enabled);
1769 #define SHOW_PARAMS(field) \
1770 fprintf(stderr, " %-28s = %d\n", #field, \
1771 stream->config.cfg.encoder_cfg.field)
1772 SHOW_PARAMS(super_block_size);
1773 SHOW_PARAMS(max_partition_size);
1774 SHOW_PARAMS(min_partition_size);
1775 SHOW_PARAMS(disable_ab_partition_type);
1776 SHOW_PARAMS(disable_rect_partition_type);
1777 SHOW_PARAMS(disable_1to4_partition_type);
1778 SHOW_PARAMS(disable_flip_idtx);
1779 SHOW_PARAMS(disable_cdef);
1780 SHOW_PARAMS(disable_lr);
1781 SHOW_PARAMS(disable_obmc);
1782 SHOW_PARAMS(disable_warp_motion);
1783 SHOW_PARAMS(disable_global_motion);
1784 SHOW_PARAMS(disable_dist_wtd_comp);
1785 SHOW_PARAMS(disable_diff_wtd_comp);
1786 SHOW_PARAMS(disable_inter_intra_comp);
1787 SHOW_PARAMS(disable_masked_comp);
1788 SHOW_PARAMS(disable_one_sided_comp);
1789 SHOW_PARAMS(disable_palette);
1790 SHOW_PARAMS(disable_intrabc);
1791 SHOW_PARAMS(disable_cfl);
1792 SHOW_PARAMS(disable_smooth_intra);
1793 SHOW_PARAMS(disable_filter_intra);
1794 SHOW_PARAMS(disable_dual_filter);
1795 SHOW_PARAMS(disable_intra_angle_delta);
1796 SHOW_PARAMS(disable_intra_edge_filter);
1797 SHOW_PARAMS(disable_tx_64x64);
1798 SHOW_PARAMS(disable_smooth_inter_intra);
1799 SHOW_PARAMS(disable_inter_inter_wedge);
1800 SHOW_PARAMS(disable_inter_intra_wedge);
1801 SHOW_PARAMS(disable_paeth_intra);
1802 SHOW_PARAMS(disable_trellis_quant);
1803 SHOW_PARAMS(disable_ref_frame_mv);
1804 SHOW_PARAMS(reduced_reference_set);
1805 SHOW_PARAMS(reduced_tx_type_set);
1808 static void open_output_file(
struct stream_state *stream,
1809 struct AvxEncoderConfig *global,
1810 const struct AvxRational *pixel_aspect_ratio) {
1811 const char *fn = stream->config.out_fn;
1816 stream->file = strcmp(fn,
"-") ? fopen(fn,
"wb") : set_binary_mode(stdout);
1818 if (!stream->file) fatal(
"Failed to open output file");
1820 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1821 fatal(
"WebM output to pipes not supported.");
1824 if (stream->config.write_webm) {
1825 stream->webm_ctx.stream = stream->file;
1826 if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1827 stream->config.stereo_fmt, global->codec->fourcc,
1828 pixel_aspect_ratio) != 0) {
1829 fatal(
"WebM writer initialization failed.");
1833 (void)pixel_aspect_ratio;
1836 if (!stream->config.write_webm && stream->config.write_ivf) {
1837 ivf_write_file_header(stream->file, cfg, global->codec->fourcc, 0);
1841 static void close_output_file(
struct stream_state *stream,
1842 unsigned int fourcc) {
1848 if (stream->config.write_webm) {
1849 if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1850 fatal(
"WebM writer finalization failed.");
1855 if (!stream->config.write_webm && stream->config.write_ivf) {
1856 if (!fseek(stream->file, 0, SEEK_SET))
1857 ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1858 stream->frames_out);
1861 fclose(stream->file);
1864 static void setup_pass(
struct stream_state *stream,
1865 struct AvxEncoderConfig *global,
int pass) {
1866 if (stream->config.stats_fn) {
1867 if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1868 fatal(
"Failed to open statistics store");
1870 if (!stats_open_mem(&stream->stats, pass))
1871 fatal(
"Failed to open statistics store");
1874 stream->config.cfg.g_pass = global->passes == 2
1878 stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1881 stream->cx_time = 0;
1883 stream->frames_out = 0;
1886 static void initialize_encoder(
struct stream_state *stream,
1887 struct AvxEncoderConfig *global) {
1896 &stream->config.cfg, flags);
1897 ctx_exit_on_error(&stream->encoder,
"Failed to initialize encoder");
1899 for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1900 int ctrl = stream->config.arg_ctrls[i][0];
1901 int value = stream->config.arg_ctrls[i][1];
1903 fprintf(stderr,
"Error: Tried to set control %d = %d\n", ctrl, value);
1905 ctx_exit_on_error(&stream->encoder,
"Failed to control codec");
1908 #if CONFIG_TUNE_VMAF
1909 if (stream->config.vmaf_model_path) {
1911 stream->config.vmaf_model_path);
1915 if (stream->config.film_grain_filename) {
1917 stream->config.film_grain_filename);
1920 #if CONFIG_AV1_DECODER
1921 if (global->test_decode != TEST_DECODE_OFF) {
1922 const AvxInterface *decoder = get_aom_decoder_by_name(global->codec->name);
1926 if (strcmp(global->codec->name,
"av1") == 0) {
1928 stream->config.cfg.large_scale_tile);
1929 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_mode");
1932 stream->config.cfg.save_as_annexb);
1933 ctx_exit_on_error(&stream->decoder,
"Failed to set is_annexb");
1937 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_row");
1941 ctx_exit_on_error(&stream->decoder,
"Failed to set decode_tile_col");
1947 static void encode_frame(
struct stream_state *stream,
1948 struct AvxEncoderConfig *global,
struct aom_image *img,
1949 unsigned int frames_in) {
1952 struct aom_usec_timer timer;
1955 (cfg->
g_timebase.
den * (int64_t)(frames_in - 1) * global->framerate.den) /
1958 (cfg->
g_timebase.
den * (int64_t)(frames_in)*global->framerate.den) /
1966 fprintf(stderr,
"%s can only scale 4:2:0 inputs\n", exec_name);
1983 stream->img->stride[
AOM_PLANE_V] / 2, stream->img->d_w,
1984 stream->img->d_h, kFilterBox);
1987 stream->encoder.err = 1;
1988 ctx_exit_on_error(&stream->encoder,
1989 "Stream %d: Failed to encode frame.\n"
1990 "libyuv is required for scaling but is currently "
1992 "Be sure to specify -DCONFIG_LIBYUV=1 when running "
1998 if (img && (img->
d_w != cfg->
g_w || img->
d_h != cfg->
g_h)) {
2000 fprintf(stderr,
"%s can only scale 4:2:0 8bpp inputs\n", exec_name);
2014 stream->img->d_w, stream->img->d_h, kFilterBox);
2017 stream->encoder.err = 1;
2018 ctx_exit_on_error(&stream->encoder,
2019 "Stream %d: Failed to encode frame.\n"
2020 "Scaling disabled in this configuration. \n"
2021 "To enable, configure with --enable-libyuv\n",
2026 aom_usec_timer_start(&timer);
2028 (uint32_t)(next_frame_start - frame_start), 0);
2029 aom_usec_timer_mark(&timer);
2030 stream->cx_time += aom_usec_timer_elapsed(&timer);
2031 ctx_exit_on_error(&stream->encoder,
"Stream %d: Failed to encode frame",
2035 static void update_quantizer_histogram(
struct stream_state *stream) {
2041 ctx_exit_on_error(&stream->encoder,
"Failed to read quantizer");
2042 stream->counts[q]++;
2046 static void get_cx_data(
struct stream_state *stream,
2047 struct AvxEncoderConfig *global,
int *got_data) {
2054 static size_t fsize = 0;
2055 static FileOffset ivf_header_pos = 0;
2057 switch (pkt->
kind) {
2059 ++stream->frames_out;
2061 fprintf(stderr,
" %6luF", (
unsigned long)pkt->
data.
frame.sz);
2063 update_rate_histogram(stream->rate_hist, cfg, pkt);
2065 if (stream->config.write_webm) {
2066 if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
2067 fatal(
"WebM writer failed.");
2071 if (!stream->config.write_webm) {
2072 if (stream->config.write_ivf) {
2073 if (pkt->
data.
frame.partition_id <= 0) {
2074 ivf_header_pos = ftello(stream->file);
2077 ivf_write_frame_header(stream->file, pkt->
data.
frame.pts, fsize);
2081 const FileOffset currpos = ftello(stream->file);
2082 fseeko(stream->file, ivf_header_pos, SEEK_SET);
2083 ivf_write_frame_size(stream->file, fsize);
2084 fseeko(stream->file, currpos, SEEK_SET);
2094 #if CONFIG_AV1_DECODER
2095 if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
2098 if (stream->decoder.err) {
2099 warn_or_exit_on_error(&stream->decoder,
2100 global->test_decode == TEST_DECODE_FATAL,
2101 "Failed to decode frame %d in stream %d",
2102 stream->frames_out + 1, stream->index);
2103 stream->mismatch_seen = stream->frames_out + 1;
2109 stream->frames_out++;
2116 if (global->show_psnr) {
2119 stream->psnr_sse_total += pkt->
data.
psnr.sse[0];
2120 stream->psnr_samples_total += pkt->
data.
psnr.samples[0];
2121 for (i = 0; i < 4; i++) {
2123 fprintf(stderr,
"%.3f ", pkt->
data.
psnr.psnr[i]);
2124 stream->psnr_totals[i] += pkt->
data.
psnr.psnr[i];
2126 stream->psnr_count++;
2135 static void show_psnr(
struct stream_state *stream,
double peak, int64_t bps) {
2139 if (!stream->psnr_count)
return;
2141 fprintf(stderr,
"Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
2142 ovpsnr = sse_to_psnr((
double)stream->psnr_samples_total, peak,
2143 (
double)stream->psnr_sse_total);
2144 fprintf(stderr,
" %.3f", ovpsnr);
2146 for (i = 0; i < 4; i++) {
2147 fprintf(stderr,
" %.3f", stream->psnr_totals[i] / stream->psnr_count);
2150 fprintf(stderr,
" %7" PRId64
" bps", bps);
2152 fprintf(stderr,
" %7" PRId64
" ms", stream->cx_time / 1000);
2153 fprintf(stderr,
"\n");
2156 static float usec_to_fps(uint64_t usec,
unsigned int frames) {
2157 return (
float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
2160 static void test_decode(
struct stream_state *stream,
2161 enum TestDecodeFatality fatal) {
2164 if (stream->mismatch_seen)
return;
2177 enc_img.
d_w, enc_img.
d_h, 16);
2178 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
2179 enc_img = enc_hbd_img;
2184 dec_img.
d_w, dec_img.
d_h, 16);
2185 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
2186 dec_img = dec_hbd_img;
2190 ctx_exit_on_error(&stream->encoder,
"Failed to get encoder reference frame");
2191 ctx_exit_on_error(&stream->decoder,
"Failed to get decoder reference frame");
2193 if (!aom_compare_img(&enc_img, &dec_img)) {
2194 int y[4], u[4], v[4];
2196 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
2198 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
2200 stream->decoder.err = 1;
2201 warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
2202 "Stream %d: Encode/decode mismatch on frame %d at"
2203 " Y[%d, %d] {%d/%d},"
2204 " U[%d, %d] {%d/%d},"
2205 " V[%d, %d] {%d/%d}",
2206 stream->index, stream->frames_out, y[0], y[1], y[2],
2207 y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
2208 stream->mismatch_seen = stream->frames_out;
2215 static void print_time(
const char *label, int64_t etl) {
2222 etl -= hours * 3600;
2227 fprintf(stderr,
"[%3s %2" PRId64
":%02" PRId64
":%02" PRId64
"] ", label,
2230 fprintf(stderr,
"[%3s unknown] ", label);
2234 int main(
int argc,
const char **argv_) {
2238 int allocated_raw_shift = 0;
2239 int use_16bit_internal = 0;
2240 int input_shift = 0;
2241 int frame_avail, got_data;
2243 struct AvxInputContext input;
2244 struct AvxEncoderConfig global;
2245 struct stream_state *streams = NULL;
2246 char **argv, **argi;
2247 uint64_t cx_time = 0;
2250 int profile_updated = 0;
2252 memset(&input, 0,
sizeof(input));
2253 exec_name = argv_[0];
2256 input.framerate.numerator = 30;
2257 input.framerate.denominator = 1;
2258 input.only_i420 = 1;
2259 input.bit_depth = 0;
2265 argv = argv_dup(argc - 1, argv_ + 1);
2266 parse_global_config(&global, &argv);
2268 if (argc < 2) usage_exit();
2270 switch (global.color_type) {
2282 struct stream_state *stream = NULL;
2285 stream = new_stream(&global, stream);
2287 if (!streams) streams = stream;
2288 }
while (parse_stream_params(&global, stream, argv));
2292 for (argi = argv; *argi; argi++)
2293 if (argi[0][0] ==
'-' && argi[0][1])
2294 die(
"Error: Unrecognized option %s\n", *argi);
2296 FOREACH_STREAM(stream, streams) {
2297 check_encoder_config(global.disable_warning_prompt, &global,
2298 &stream->config.cfg);
2301 if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
2302 die(
"only support ivf output format while large-scale-tile=1\n");
2306 input.filename = argv[0];
2308 if (!input.filename) {
2309 fprintf(stderr,
"No input file specified!\n");
2314 if (global.codec->fourcc == AV1_FOURCC) input.only_i420 = 0;
2316 for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
2317 int frames_in = 0, seen_frames = 0;
2318 int64_t estimated_time_left = -1;
2319 int64_t average_rate = -1;
2320 int64_t lagged_count = 0;
2322 open_input_file(&input, global.csp);
2327 if (!input.width || !input.height) {
2328 FOREACH_STREAM(stream, streams) {
2329 if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
2330 input.width = stream->config.cfg.g_w;
2331 input.height = stream->config.cfg.g_h;
2338 if (!input.width || !input.height)
2340 "Specify stream dimensions with --width (-w) "
2341 " and --height (-h)");
2348 if (!input.bit_depth) {
2349 FOREACH_STREAM(stream, streams) {
2350 if (stream->config.cfg.g_input_bit_depth)
2351 input.bit_depth = stream->config.cfg.g_input_bit_depth;
2353 input.bit_depth = stream->config.cfg.g_input_bit_depth =
2354 (int)stream->config.cfg.g_bit_depth;
2358 FOREACH_STREAM(stream, streams) {
2359 stream->config.cfg.g_input_bit_depth = input.bit_depth;
2363 FOREACH_STREAM(stream, streams) {
2367 switch (stream->config.cfg.g_profile) {
2371 if (!stream->config.cfg.monochrome) {
2372 stream->config.cfg.g_profile = 1;
2373 profile_updated = 1;
2377 stream->config.cfg.g_profile = 2;
2378 profile_updated = 1;
2384 stream->config.cfg.g_profile = 2;
2385 profile_updated = 1;
2386 }
else if (input.bit_depth < 12 &&
2389 stream->config.cfg.g_profile = 0;
2390 profile_updated = 1;
2396 stream->config.cfg.g_profile = 1;
2397 profile_updated = 1;
2398 }
else if (input.bit_depth < 12 &&
2401 stream->config.cfg.g_profile = 0;
2402 profile_updated = 1;
2403 }
else if (input.bit_depth == 12 &&
2404 input.file_type == FILE_TYPE_Y4M) {
2409 input.y4m.dst_c_dec_h >> 1);
2412 input.y4m.dst_c_dec_v >> 1);
2413 }
else if (input.bit_depth == 12 &&
2414 input.file_type == FILE_TYPE_RAW) {
2417 stream->chroma_subsampling_x);
2420 stream->chroma_subsampling_y);
2428 if (stream->config.cfg.g_input_bit_depth >
2429 (
unsigned int)stream->config.cfg.g_bit_depth) {
2430 stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
2431 if (!global.quiet) {
2433 "Warning: automatically updating bit depth to %d to "
2434 "match input format.\n",
2435 stream->config.cfg.g_input_bit_depth);
2438 if (stream->config.cfg.g_bit_depth > 10) {
2439 switch (stream->config.cfg.g_profile) {
2442 stream->config.cfg.g_profile = 2;
2443 profile_updated = 1;
2448 if (stream->config.cfg.g_bit_depth > 8) {
2449 stream->config.use_16bit_internal = 1;
2451 if (profile_updated && !global.quiet) {
2453 "Warning: automatically updating to profile %d to "
2454 "match input format.\n",
2455 stream->config.cfg.g_profile);
2458 stream->config.cfg.g_limit = global.limit;
2461 FOREACH_STREAM(stream, streams) {
2462 set_stream_dimensions(stream, input.width, input.height);
2464 FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
2469 if (global.pass && global.passes == 2) {
2470 FOREACH_STREAM(stream, streams) {
2471 if (!stream->config.stats_fn)
2472 die(
"Stream %d: Must specify --fpf when --pass=%d"
2473 " and --passes=2\n",
2474 stream->index, global.pass);
2479 FOREACH_STREAM(stream, streams) {
2480 if (stream->config.write_webm) {
2481 stream->config.write_webm = 0;
2482 stream->config.write_ivf = 0;
2483 warn(
"aomenc compiled w/o WebM support. Writing OBU stream.");
2491 if (!global.have_framerate) {
2492 global.framerate.num = input.framerate.numerator;
2493 global.framerate.den = input.framerate.denominator;
2495 FOREACH_STREAM(stream, streams) {
2496 stream->config.cfg.g_timebase.den = global.framerate.num;
2497 stream->config.cfg.g_timebase.num = global.framerate.den;
2500 if (global.verbose && pass == 0) {
2501 FOREACH_STREAM(stream, streams) {
2502 show_stream_config(stream, &global, &input);
2506 if (pass == (global.pass ? global.pass - 1 : 0)) {
2507 if (input.file_type == FILE_TYPE_Y4M)
2511 memset(&raw, 0,
sizeof(raw));
2513 aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2515 FOREACH_STREAM(stream, streams) {
2517 init_rate_histogram(&stream->config.cfg, &global.framerate);
2521 FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2522 FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2523 FOREACH_STREAM(stream, streams) {
2524 open_output_file(stream, &global, &input.pixel_aspect_ratio);
2527 if (strcmp(global.codec->name,
"av1") == 0 ||
2528 strcmp(global.codec->name,
"av1") == 0) {
2532 FOREACH_STREAM(stream, streams) {
2533 if (stream->config.use_16bit_internal) {
2534 use_16bit_internal = 1;
2536 input_shift = (int)stream->config.cfg.g_bit_depth -
2537 stream->config.cfg.g_input_bit_depth;
2544 while (frame_avail || got_data) {
2545 struct aom_usec_timer timer;
2547 if (!global.limit || frames_in < global.limit) {
2548 frame_avail = read_frame(&input, &raw);
2550 if (frame_avail) frames_in++;
2552 frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2554 if (!global.quiet) {
2555 float fps = usec_to_fps(cx_time, seen_frames);
2556 fprintf(stderr,
"\rPass %d/%d ", pass + 1, global.passes);
2558 if (stream_cnt == 1)
2559 fprintf(stderr,
"frame %4d/%-4d %7" PRId64
"B ", frames_in,
2560 streams->frames_out, (int64_t)streams->nbytes);
2562 fprintf(stderr,
"frame %4d ", frames_in);
2564 fprintf(stderr,
"%7" PRId64
" %s %.2f %s ",
2565 cx_time > 9999999 ? cx_time / 1000 : cx_time,
2566 cx_time > 9999999 ?
"ms" :
"us", fps >= 1.0 ? fps : fps * 60,
2567 fps >= 1.0 ?
"fps" :
"fpm");
2568 print_time(
"ETA", estimated_time_left);
2575 if (frames_in > global.skip_frames) {
2577 if (input_shift || (use_16bit_internal && input.bit_depth == 8)) {
2578 assert(use_16bit_internal);
2581 if (!allocated_raw_shift) {
2583 input.width, input.height, 32);
2584 allocated_raw_shift = 1;
2586 aom_img_upshift(&raw_shift, &raw, input_shift);
2587 frame_to_encode = &raw_shift;
2589 frame_to_encode = &raw;
2591 aom_usec_timer_start(&timer);
2592 if (use_16bit_internal) {
2594 FOREACH_STREAM(stream, streams) {
2595 if (stream->config.use_16bit_internal)
2596 encode_frame(stream, &global,
2597 frame_avail ? frame_to_encode : NULL, frames_in);
2603 FOREACH_STREAM(stream, streams) {
2604 encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2608 aom_usec_timer_mark(&timer);
2609 cx_time += aom_usec_timer_elapsed(&timer);
2611 FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2614 FOREACH_STREAM(stream, streams) {
2615 get_cx_data(stream, &global, &got_data);
2618 if (!got_data && input.length && streams != NULL &&
2619 !streams->frames_out) {
2620 lagged_count = global.limit ? seen_frames : ftello(input.file);
2621 }
else if (input.length) {
2626 const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2628 rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2629 remaining = 1000 * (global.limit - global.skip_frames -
2630 seen_frames + lagged_count);
2632 const int64_t input_pos = ftello(input.file);
2633 const int64_t input_pos_lagged = input_pos - lagged_count;
2634 const int64_t input_limit = input.length;
2636 rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2637 remaining = input_limit - input_pos + lagged_count;
2641 (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2642 estimated_time_left = average_rate ? remaining / average_rate : -1;
2645 if (got_data && global.test_decode != TEST_DECODE_OFF) {
2646 FOREACH_STREAM(stream, streams) {
2647 test_decode(stream, global.test_decode);
2653 if (!global.quiet) fprintf(stderr,
"\033[K");
2656 if (stream_cnt > 1) fprintf(stderr,
"\n");
2658 if (!global.quiet) {
2659 FOREACH_STREAM(stream, streams) {
2661 seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2662 const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2664 "\rPass %d/%d frame %4d/%-4d %7" PRId64
"B %7" PRId64
2667 " %7" PRId64
" %s (%.2f fps)\033[K\n",
2668 pass + 1, global.passes, frames_in, stream->frames_out,
2669 (int64_t)stream->nbytes, bpf, bps,
2670 stream->cx_time > 9999999 ? stream->cx_time / 1000
2672 stream->cx_time > 9999999 ?
"ms" :
"us",
2673 usec_to_fps(stream->cx_time, seen_frames));
2677 if (global.show_psnr) {
2678 if (global.codec->fourcc == AV1_FOURCC) {
2679 FOREACH_STREAM(stream, streams) {
2681 if (stream->psnr_count && seen_frames && global.framerate.den) {
2682 bps = (int64_t)stream->nbytes * 8 * (int64_t)global.framerate.num /
2683 global.framerate.den / seen_frames;
2685 show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2689 FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2695 if (global.test_decode != TEST_DECODE_OFF) {
2699 close_input_file(&input);
2701 if (global.test_decode == TEST_DECODE_FATAL) {
2702 FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2704 FOREACH_STREAM(stream, streams) {
2705 close_output_file(stream, global.codec->fourcc);
2708 FOREACH_STREAM(stream, streams) {
2709 stats_close(&stream->stats, global.passes - 1);
2712 if (global.pass)
break;
2715 if (global.show_q_hist_buckets) {
2716 FOREACH_STREAM(stream, streams) {
2717 show_q_histogram(stream->counts, global.show_q_hist_buckets);
2721 if (global.show_rate_hist_buckets) {
2722 FOREACH_STREAM(stream, streams) {
2723 show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2724 global.show_rate_hist_buckets);
2727 FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2729 #if CONFIG_INTERNAL_STATS
2733 if (!(global.pass == 1 && global.passes == 2)) {
2734 FOREACH_STREAM(stream, streams) {
2735 FILE *f = fopen(
"opsnr.stt",
"a");
2736 if (stream->mismatch_seen) {
2737 fprintf(f,
"First mismatch occurred in frame %d\n",
2738 stream->mismatch_seen);
2740 fprintf(f,
"No mismatch detected in recon buffers\n");
2751 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:846
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition: aom_encoder.h:859
#define FIXED_QP_OFFSET_COUNT
Number of fixed QP offsets.
Definition: aom_encoder.h:886
#define AOM_PLANE_U
Definition: aom_image.h:200
@ AOM_CSP_COLOCATED
Definition: aom_image.h:136
@ AOM_CSP_UNKNOWN
Definition: aom_image.h:133
@ AOM_CSP_VERTICAL
Definition: aom_image.h:134
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_PLANE_Y
Definition: aom_image.h:199
@ AOM_CICP_TC_BT_2020_10_BIT
Definition: aom_image.h:95
@ AOM_CICP_TC_BT_470_M
Definition: aom_image.h:84
@ AOM_CICP_TC_HLG
Definition: aom_image.h:99
@ AOM_CICP_TC_SMPTE_428
Definition: aom_image.h:98
@ AOM_CICP_TC_LOG_100
Definition: aom_image.h:89
@ AOM_CICP_TC_IEC_61966
Definition: aom_image.h:92
@ AOM_CICP_TC_BT_601
Definition: aom_image.h:86
@ AOM_CICP_TC_BT_470_B_G
Definition: aom_image.h:85
@ AOM_CICP_TC_LOG_100_SQRT10
Definition: aom_image.h:90
@ AOM_CICP_TC_SRGB
Definition: aom_image.h:94
@ AOM_CICP_TC_LINEAR
Definition: aom_image.h:88
@ AOM_CICP_TC_SMPTE_2084
Definition: aom_image.h:97
@ AOM_CICP_TC_SMPTE_240
Definition: aom_image.h:87
@ AOM_CICP_TC_BT_1361
Definition: aom_image.h:93
@ AOM_CICP_TC_BT_2020_12_BIT
Definition: aom_image.h:96
@ AOM_CICP_TC_BT_709
Definition: aom_image.h:81
#define AOM_PLANE_V
Definition: aom_image.h:201
@ AOM_CICP_CP_UNSPECIFIED
Definition: aom_image.h:61
@ AOM_CICP_CP_SMPTE_240
Definition: aom_image.h:66
@ AOM_CICP_CP_SMPTE_432
Definition: aom_image.h:72
@ AOM_CICP_CP_BT_601
Definition: aom_image.h:65
@ AOM_CICP_CP_SMPTE_431
Definition: aom_image.h:71
@ AOM_CICP_CP_BT_470_M
Definition: aom_image.h:63
@ AOM_CICP_CP_XYZ
Definition: aom_image.h:70
@ AOM_CICP_CP_BT_2020
Definition: aom_image.h:69
@ AOM_CICP_CP_BT_470_B_G
Definition: aom_image.h:64
@ AOM_CICP_CP_GENERIC_FILM
Definition: aom_image.h:67
@ AOM_CICP_CP_BT_709
Definition: aom_image.h:60
@ AOM_CICP_CP_EBU_3213
Definition: aom_image.h:74
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.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
@ AOM_CICP_MC_UNSPECIFIED
Definition: aom_image.h:107
@ AOM_CICP_MC_BT_601
Definition: aom_image.h:111
@ AOM_CICP_MC_IDENTITY
Definition: aom_image.h:105
@ AOM_CICP_MC_CHROMAT_NCL
Definition: aom_image.h:118
@ AOM_CICP_MC_BT_2020_CL
Definition: aom_image.h:116
@ AOM_CICP_MC_SMPTE_2085
Definition: aom_image.h:117
@ AOM_CICP_MC_ICTCP
Definition: aom_image.h:121
@ AOM_CICP_MC_SMPTE_YCGCO
Definition: aom_image.h:113
@ AOM_CICP_MC_CHROMAT_CL
Definition: aom_image.h:120
@ AOM_CICP_MC_BT_709
Definition: aom_image.h:106
@ AOM_CICP_MC_BT_2020_NCL
Definition: aom_image.h:114
@ AOM_CICP_MC_FCC
Definition: aom_image.h:109
@ AOM_CICP_MC_BT_470_B_G
Definition: aom_image.h:110
@ 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:225
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition: aomdx.h:261
@ AV1_SET_DECODE_TILE_ROW
Codec control function to set the range of tile decoding, int parameter.
Definition: aomdx.h:217
@ AV1E_SET_MATRIX_COEFFICIENTS
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:530
@ AV1E_SET_ENABLE_INTERINTER_WEDGE
Codec control function to turn on / off interinter wedge compound, int parameter.
Definition: aomcx.h:948
@ AV1E_SET_MAX_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:551
@ AV1E_SET_ROW_MT
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition: aomcx.h:324
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition: aomcx.h:1005
@ AOME_SET_SHARPNESS
Codec control function to set sharpness, unsigned int parameter.
Definition: aomcx.h:206
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition: aomcx.h:369
@ AOME_GET_LAST_QUANTIZER_64
Codec control function to get last quantizer chosen by the encoder, int* parameter.
Definition: aomcx.h:228
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition: aomcx.h:426
@ AV1E_SET_REDUCED_REFERENCE_SET
Control to use reduced set of single and compound references, int parameter.
Definition: aomcx.h:1159
@ AV1E_SET_GF_MIN_PYRAMID_HEIGHT
Control to select minimum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1258
@ AV1E_SET_ENABLE_PAETH_INTRA
Codec control function to turn on / off Paeth intra mode usage, int parameter.
Definition: aomcx.h:1013
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition: aomcx.h:454
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition: aomcx.h:463
@ AV1E_SET_CHROMA_SUBSAMPLING_X
Sets the chroma subsampling x value, unsigned int parameter.
Definition: aomcx.h:1122
@ AV1E_SET_ENABLE_RESTORATION
Codec control function to encode with Loop Restoration Filter, unsigned int parameter.
Definition: aomcx.h:630
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition: aomcx.h:1054
@ AV1E_SET_MIN_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:544
@ AOME_SET_ARNR_MAXFRAMES
Codec control function to set the max no of frames to create arf, unsigned int parameter.
Definition: aomcx.h:233
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition: aomcx.h:1192
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition: aomcx.h:1138
@ AV1E_SET_TRANSFER_CHARACTERISTICS
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:509
@ AV1E_SET_MTU
Codec control function to set an MTU size for a tile group, unsigned int parameter.
Definition: aomcx.h:748
@ AV1E_SET_DISABLE_TRELLIS_QUANT
Codec control function to encode without trellis quantization, unsigned int parameter.
Definition: aomcx.h:655
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition: aomcx.h:1050
@ AV1E_SET_ENABLE_AB_PARTITIONS
Codec control function to enable/disable AB partitions, int parameter.
Definition: aomcx.h:766
@ AV1E_SET_ENABLE_INTERINTRA_COMP
Codec control function to turn on / off interintra compound for a sequence, int parameter.
Definition: aomcx.h:924
@ 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:1108
@ AV1E_SET_ENABLE_CHROMA_DELTAQ
Codec control function to turn on / off delta quantization in chroma planes usage for a sequence,...
Definition: aomcx.h:900
@ AV1E_SET_ENABLE_DUAL_FILTER
Codec control function to turn on / off dual interpolation filter for a sequence, int parameter.
Definition: aomcx.h:892
@ AV1E_SET_FRAME_PARALLEL_DECODING
Codec control function to enable frame parallel decoding feature, unsigned int parameter.
Definition: aomcx.h:391
@ AV1E_SET_MIN_PARTITION_SIZE
Codec control function to set min partition size, int parameter.
Definition: aomcx.h:785
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition: aomcx.h:972
@ AV1E_SET_FORCE_VIDEO_MODE
Codec control function to force video mode, unsigned int parameter.
Definition: aomcx.h:637
@ AV1E_SET_CHROMA_SUBSAMPLING_Y
Sets the chroma subsampling y value, unsigned int parameter.
Definition: aomcx.h:1125
@ AV1E_SET_ENABLE_INTRA_EDGE_FILTER
Codec control function to turn on / off intra edge filter at sequence level, int parameter.
Definition: aomcx.h:804
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition: aomcx.h:1172
@ AV1E_SET_MAX_INTER_BITRATE_PCT
Codec control function to set max data rate for inter frames, unsigned int parameter.
Definition: aomcx.h:288
@ AV1E_SET_DENOISE_NOISE_LEVEL
Sets the noise level, int parameter.
Definition: aomcx.h:1116
@ AV1E_SET_INTRA_DCT_ONLY
Control to use dct only for intra modes, int parameter.
Definition: aomcx.h:1131
@ AV1E_SET_TILE_ROWS
Codec control function to set number of tile rows, unsigned int parameter.
Definition: aomcx.h:361
@ AV1E_SET_ENABLE_REF_FRAME_MVS
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level,...
Definition: aomcx.h:873
@ 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:908
@ AV1E_SET_GF_MAX_PYRAMID_HEIGHT
Control to select maximum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1148
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition: aomcx.h:622
@ AV1E_SET_ENABLE_FLIP_IDTX
Codec control function to turn on / off flip and identity transforms, int parameter.
Definition: aomcx.h:848
@ AV1E_SET_FRAME_PERIODIC_BOOST
Codec control function to enable/disable periodic Q boost, unsigned int parameter.
Definition: aomcx.h:438
@ 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:862
@ 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:1101
@ AV1E_SET_SUPERBLOCK_SIZE
Codec control function to set intended superblock size, unsigned int parameter.
Definition: aomcx.h:604
@ 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:1200
@ AV1E_SET_ENABLE_INTERINTRA_WEDGE
Codec control function to turn on / off interintra wedge compound, int parameter.
Definition: aomcx.h:956
@ AV1E_SET_NOISE_SENSITIVITY
Codec control function to set noise sensitivity, unsigned int parameter.
Definition: aomcx.h:446
@ AV1E_SET_ENABLE_DIFF_WTD_COMP
Codec control function to turn on / off difference weighted compound, int parameter.
Definition: aomcx.h:940
@ AV1E_SET_QUANT_B_ADAPT
Control to use adaptive quantize_b, int parameter.
Definition: aomcx.h:1141
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition: aomcx.h:994
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition: aomcx.h:1046
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition: aomcx.h:1023
@ AV1E_SET_ENABLE_KEYFRAME_FILTERING
Codec control function to enable temporal filtering on key frame, unsigned int parameter.
Definition: aomcx.h:377
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition: aomcx.h:737
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition: aomcx.h:269
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition: aomcx.h:402
@ AV1E_SET_ENABLE_SMOOTH_INTERINTRA
Codec control function to turn on / off smooth inter-intra mode for a sequence, int parameter.
Definition: aomcx.h:932
@ AOME_SET_STATIC_THRESHOLD
Codec control function to set the threshold for MBs treated static, unsigned int parameter.
Definition: aomcx.h:211
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition: aomcx.h:645
@ AV1E_SET_MAX_PARTITION_SIZE
Codec control function to set max partition size, int parameter.
Definition: aomcx.h:796
@ AV1E_SET_ENABLE_1TO4_PARTITIONS
Codec control function to enable/disable 1:4 and 4:1 partitions, int parameter.
Definition: aomcx.h:774
@ AV1E_SET_DELTALF_MODE
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled,...
Definition: aomcx.h:1074
@ AV1E_SET_ENABLE_TX64
Codec control function to turn on / off 64-length transforms, int parameter.
Definition: aomcx.h:824
@ AOME_SET_TUNING
Codec control function to set visual tuning, aom_tune_metric (int) parameter.
Definition: aomcx.h:245
@ 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:589
@ 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:537
@ AV1E_SET_REDUCED_TX_TYPE_SET
Control to use a reduced tx type set, int parameter.
Definition: aomcx.h:1128
@ AV1E_SET_INTER_DCT_ONLY
Control to use dct only for inter modes, int parameter.
Definition: aomcx.h:1134
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition: aomcx.h:200
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition: aomcx.h:343
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition: aomcx.h:813
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition: aomcx.h:1066
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition: aomcx.h:964
@ AV1E_SET_FILM_GRAIN_TABLE
Codec control function to set the path to the film grain parameters, const char* parameter.
Definition: aomcx.h:1113
@ AV1E_SET_QM_MAX
Codec control function to set the max quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:691
@ AV1E_SET_MAX_REFERENCE_FRAMES
Control to select maximum reference frames allowed per frame, int parameter.
Definition: aomcx.h:1155
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition: aomcx.h:192
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition: aomcx.h:302
@ AV1E_SET_ENABLE_ONESIDED_COMP
Codec control function to turn on / off one sided compound usage for a sequence, int parameter.
Definition: aomcx.h:916
@ AV1E_SET_DENOISE_BLOCK_SIZE
Sets the denoisers block size, unsigned int parameter.
Definition: aomcx.h:1119
@ 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:1230
@ AV1E_SET_QM_MIN
Codec control function to set the min quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:679
@ AV1E_SET_ENABLE_QM
Codec control function to encode with quantisation matrices, unsigned int parameter.
Definition: aomcx.h:666
@ AV1E_SET_ENABLE_OVERLAY
Codec control function to turn on / off overlay frames for filtered ALTREF frames,...
Definition: aomcx.h:1043
@ AV1E_SET_ENABLE_RECT_PARTITIONS
Codec control function to enable/disable rectangular partitions, int parameter.
Definition: aomcx.h:758
@ AV1E_SET_COLOR_PRIMARIES
Codec control function to set color space info, int parameter.
Definition: aomcx.h:484
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition: aomcx.h:255
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition: aomcx.h:1182
@ AV1E_SET_MIN_CR
Control to set minimum compression ratio, unsigned int parameter Take integer values....
Definition: aomcx.h:1207
@ AV1E_SET_LOSSLESS
Codec control function to set lossless encoding mode, unsigned int parameter.
Definition: aomcx.h:316
@ AOME_SET_ARNR_STRENGTH
Codec control function to set the filter strength for the arf, unsigned int parameter.
Definition: aomcx.h:238
@ AV1_GET_NEW_FRAME_IMAGE
Definition: aom.h:59
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 char * aom_codec_error(aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_codec.h:181
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:101
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition: aom_codec.h:426
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:209
@ AOM_BITS_12
Definition: aom_codec.h:242
@ AOM_BITS_8
Definition: aom_codec.h:240
@ AOM_BITS_10
Definition: aom_codec.h:241
@ AOM_SUPERBLOCK_SIZE_128X128
Definition: aom_codec.h:253
@ AOM_SUPERBLOCK_SIZE_64X64
Definition: aom_codec.h:252
@ AOM_SUPERBLOCK_SIZE_DYNAMIC
Definition: aom_codec.h:254
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:1012
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:941
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:1014
#define AOM_CODEC_USE_HIGHBITDEPTH
Make the encoder output one partition at a time.
Definition: aom_encoder.h:70
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition: aom_encoder.h:68
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
@ AOM_CBR
Definition: aom_encoder.h:186
@ AOM_CQ
Definition: aom_encoder.h:187
@ AOM_VBR
Definition: aom_encoder.h:185
@ AOM_Q
Definition: aom_encoder.h:188
@ AOM_RC_ONE_PASS
Definition: aom_encoder.h:178
@ AOM_RC_LAST_PASS
Definition: aom_encoder.h:180
@ AOM_RC_FIRST_PASS
Definition: aom_encoder.h:179
@ AOM_KF_DISABLED
Definition: aom_encoder.h:202
@ AOM_CODEC_PSNR_PKT
Definition: aom_encoder.h:122
@ AOM_CODEC_CX_FRAME_PKT
Definition: aom_encoder.h:119
@ AOM_CODEC_STATS_PKT
Definition: aom_encoder.h:120
Codec context structure.
Definition: aom_codec.h:219
aom_codec_err_t err
Definition: aom_codec.h:222
Encoder output packet.
Definition: aom_encoder.h:131
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:132
double psnr[4]
Definition: aom_encoder.h:154
aom_fixed_buf_t twopass_stats
Definition: aom_encoder.h:149
aom_fixed_buf_t raw
Definition: aom_encoder.h:156
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:369
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:466
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:417
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:408
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: aom_encoder.h:481
size_t sz
Definition: aom_encoder.h:78
void * buf
Definition: aom_encoder.h:77
Image Descriptor.
Definition: aom_image.h:171
aom_img_fmt_t fmt
Definition: aom_image.h:172
int stride[3]
Definition: aom_image.h:203
unsigned int d_w
Definition: aom_image.h:186
unsigned int d_h
Definition: aom_image.h:187
unsigned char * planes[3]
Definition: aom_image.h:202
Rational Number.
Definition: aom_encoder.h:171
int num
Definition: aom_encoder.h:172
int den
Definition: aom_encoder.h:173
Encoder Config Options.
Definition: aom_encoder.h:210
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:226
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:222
unsigned int disable_trellis_quant
disable trellis quantization
Definition: aom_encoder.h:338
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition: aom_encoder.h:218