57#include "aom_scale/yv12config.h"
58#include "common/tools_common.h"
59#include "common/video_writer.h"
60#include "examples/encoder_util.h"
62static const char *exec_name;
64void usage_exit(
void) {
66 "Usage: %s <codec> <width> <height> <infile> <outfile> "
67 "<frame> <limit(optional)>\n",
73 unsigned int frame_out,
int *mismatch_seen) {
76 if (*mismatch_seen)
return;
80 die_codec(encoder,
"Failed to get encoder reference frame");
82 die_codec(decoder,
"Failed to get decoder reference frame");
89 enc_img.
d_w, enc_img.
d_h, 16);
90 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
91 enc_img = enc_hbd_img;
96 dec_img.
d_w, dec_img.
d_h, 16);
97 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
98 dec_img = dec_hbd_img;
102 if (!aom_compare_img(&enc_img, &dec_img)) {
103 int y[4], u[4], v[4];
105 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
107 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
111 "Encode/decode mismatch on frame %u at"
112 " Y[%d, %d] {%d/%d},"
113 " U[%d, %d] {%d/%d},"
114 " V[%d, %d] {%d/%d}",
115 frame_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0], v[1],
125 unsigned int frame_in, AvxVideoWriter *writer,
127 unsigned int *frame_out,
int *mismatch_seen,
134 if (res !=
AOM_CODEC_OK) die_codec(ecodec,
"Failed to encode frame");
146 if (!aom_video_writer_write_frame(writer, pkt->
data.
frame.
buf,
149 die_codec(ecodec,
"Failed to write compressed frame");
151 printf(keyframe ?
"K" :
".");
159 die_codec(dcodec,
"Failed to decode frame.");
162 if (*frame_out == 1 && ext_ref != NULL)
164 die_codec(dcodec,
"Failed to get decoder new frame");
170 if (got_data && test_decode) {
171 testing_decode(ecodec, dcodec, *frame_out, mismatch_seen);
177int main(
int argc,
char **argv) {
182 unsigned int frame_in = 0;
188 AvxVideoWriter *writer = NULL;
190 int allocated_raw_shift = 0;
198 unsigned int frame_out = 0;
201 unsigned int update_frame_num = 0;
202 int mismatch_seen = 0;
205 const int bitrate = 500;
207 const char *codec_arg = NULL;
208 const char *width_arg = NULL;
209 const char *height_arg = NULL;
210 const char *infile_arg = NULL;
211 const char *outfile_arg = NULL;
212 const char *update_frame_num_arg = NULL;
213 unsigned int limit = 0;
218 memset(&ecodec, 0,
sizeof(ecodec));
219 memset(&cfg, 0,
sizeof(cfg));
220 memset(&info, 0,
sizeof(info));
222 if (argc < 7) die(
"Invalid number of arguments");
226 height_arg = argv[3];
227 infile_arg = argv[4];
228 outfile_arg = argv[5];
229 update_frame_num_arg = argv[6];
232 if (!encoder) die(
"Unsupported codec.");
234 update_frame_num = (
unsigned int)strtoul(update_frame_num_arg, NULL, 0);
238 if (update_frame_num <= 1) {
239 die(
"Couldn't parse frame number '%s'\n", update_frame_num_arg);
243 limit = (
unsigned int)strtoul(argv[7], NULL, 0);
244 if (update_frame_num > limit)
245 die(
"Update frame number couldn't larger than limit\n");
248 info.codec_fourcc = get_fourcc_by_aom_encoder(encoder);
249 info.frame_width = (int)strtol(width_arg, NULL, 0);
250 info.frame_height = (int)strtol(height_arg, NULL, 0);
251 info.time_base.numerator = 1;
252 info.time_base.denominator = fps;
254 if (info.frame_width <= 0 || info.frame_height <= 0) {
255 die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
260 if (!
aom_img_alloc(&raw, raw_fmt, info.frame_width, info.frame_height, 32)) {
261 die(
"Failed to allocate image.");
267 info.frame_height, 32, 8,
268 AOM_DEC_BORDER_IN_PIXELS)) {
269 die(
"Failed to allocate image.");
274#if CONFIG_REALTIME_ONLY
279 if (res) die_codec(&ecodec,
"Failed to get default codec config.");
281 cfg.
g_w = info.frame_width;
282 cfg.
g_h = info.frame_height;
293 writer = aom_video_writer_open(outfile_arg, kContainerIVF, &info);
294 if (!writer) die(
"Failed to open %s for writing.", outfile_arg);
296 if (!(infile = fopen(infile_arg,
"rb")))
297 die(
"Failed to open %s for reading.", infile_arg);
300 die(
"Failed to initialize encoder");
304 die_codec(&ecodec,
"Failed to set enable auto alt ref");
309 die(
"Failed to initialize decoder.");
313 while (aom_img_read(&raw, infile)) {
314 if (limit && frame_in >= limit)
break;
317 if (FORCE_HIGHBITDEPTH_DECODING) {
320 if (!allocated_raw_shift) {
322 info.frame_width, info.frame_height, 32);
323 allocated_raw_shift = 1;
325 aom_img_upshift(&raw_shift, &raw, input_shift);
326 frame_to_encode = &raw_shift;
328 frame_to_encode = &raw;
331 if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
338 die_codec(&ecodec,
"Failed to set encoder reference frame");
339 printf(
" <SET_REF>");
341#if CONFIG_REALTIME_ONLY
344 die_codec(&ecodec,
"Failed to set cpu speed");
352 die_codec(&dcodec,
"Failed to set decoder reference frame");
356 encode_frame(&ecodec, frame_to_encode, frame_in, writer, test_decode,
357 &dcodec, &frame_out, &mismatch_seen, &ext_ref);
359 if (mismatch_seen)
break;
364 while (encode_frame(&ecodec, NULL, frame_in, writer, test_decode, &dcodec,
365 &frame_out, &mismatch_seen, NULL)) {
370 printf(
"Processed %u frames.\n", frame_out);
374 printf(
"Encoder/decoder results are matching.\n");
376 printf(
"Encoder/decoder results are NOT matching.\n");
381 die_codec(&dcodec,
"Failed to destroy decoder");
387 die_codec(&ecodec,
"Failed to destroy encoder.");
389 aom_video_writer_close(writer);
Describes the decoder algorithm interface to applications.
Describes the encoder algorithm interface to applications.
aom_image_t * aom_img_alloc_with_border(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align, unsigned int size_align, unsigned int border)
Open a descriptor, allocating storage for the underlying image with a border.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition aom_image.h:38
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
@ AOM_IMG_FMT_I420
Definition aom_image.h:45
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.
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition aomcx.h:228
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:220
@ AV1_GET_NEW_FRAME_IMAGE
Codec control function to get a pointer to the new frame.
Definition aom.h:70
@ AV1_SET_REFERENCE
Codec control function to write a frame into a reference buffer.
Definition aom.h:57
@ AV1_COPY_NEW_FRAME_IMAGE
Codec control function to copy the new frame to an external buffer.
Definition aom.h:76
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:271
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
aom_codec_err_t
Algorithm return codes.
Definition aom_codec.h:155
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:305
#define AOM_FRAME_IS_KEY
Definition aom_codec.h:288
@ AOM_BITS_8
Definition aom_codec.h:336
@ AOM_CODEC_OK
Operation completed without error.
Definition aom_codec.h:157
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
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned long duration, aom_enc_frame_flags_t flags)
Encode a frame.
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition aom_encoder.h:943
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_CODEC_USE_HIGHBITDEPTH
Definition aom_encoder.h:80
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:110
Codec context structure.
Definition aom_codec.h:315
Encoder output packet.
Definition aom_encoder.h:122
size_t sz
Definition aom_encoder.h:127
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:123
union aom_codec_cx_pkt::@1 data
aom_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition aom_encoder.h:129
struct aom_codec_cx_pkt::@1::@2 frame
aom_codec_frame_flags_t flags
Definition aom_encoder.h:132
void * buf
Definition aom_encoder.h:126
Encoder configuration structure.
Definition aom_encoder.h:387
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:489
unsigned int g_h
Height of the frame.
Definition aom_encoder.h:435
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition aom_encoder.h:518
aom_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition aom_encoder.h:467
unsigned int g_w
Width of the frame.
Definition aom_encoder.h:426
unsigned int rc_target_bitrate
Target data rate.
Definition aom_encoder.h:644
Image Descriptor.
Definition aom_image.h:182
aom_img_fmt_t fmt
Definition aom_image.h:183
unsigned int d_w
Definition aom_image.h:197
unsigned int d_h
Definition aom_image.h:198
int num
Definition aom_encoder.h:165
int den
Definition aom_encoder.h:166
AV1 specific reference frame data struct.
Definition aom.h:89
int use_external_ref
Definition aom.h:91
aom_image_t img
Definition aom.h:92
int idx
Definition aom.h:90