57 #include "aom_scale/yv12config.h" 
   58 #include "common/tools_common.h" 
   59 #include "common/video_writer.h" 
   60 #include "examples/encoder_util.h" 
   62 static const char *exec_name;
 
   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 %d 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);
 
  177 int main(
int argc, 
char **argv) {
 
  182   unsigned int frame_in = 0;
 
  188   AvxVideoWriter *writer = NULL;
 
  189   const AvxInterface *encoder = NULL;
 
  191   int allocated_raw_shift = 0;
 
  199   unsigned int frame_out = 0;
 
  202   unsigned int update_frame_num = 0;
 
  203   int mismatch_seen = 0;
 
  206   const int bitrate = 500;
 
  208   const char *codec_arg = NULL;
 
  209   const char *width_arg = NULL;
 
  210   const char *height_arg = NULL;
 
  211   const char *infile_arg = NULL;
 
  212   const char *outfile_arg = NULL;
 
  213   const char *update_frame_num_arg = NULL;
 
  214   unsigned int limit = 0;
 
  219   memset(&ecodec, 0, 
sizeof(ecodec));
 
  220   memset(&cfg, 0, 
sizeof(cfg));
 
  221   memset(&info, 0, 
sizeof(info));
 
  223   if (argc < 7) die(
"Invalid number of arguments");
 
  227   height_arg = argv[3];
 
  228   infile_arg = argv[4];
 
  229   outfile_arg = argv[5];
 
  230   update_frame_num_arg = argv[6];
 
  232   encoder = get_aom_encoder_by_name(codec_arg);
 
  233   if (!encoder) die(
"Unsupported codec.");
 
  235   update_frame_num = (
unsigned int)strtoul(update_frame_num_arg, NULL, 0);
 
  239   if (update_frame_num <= 1) {
 
  240     die(
"Couldn't parse frame number '%s'\n", update_frame_num_arg);
 
  244     limit = (
unsigned int)strtoul(argv[7], NULL, 0);
 
  245     if (update_frame_num > limit)
 
  246       die(
"Update frame number couldn't larger than limit\n");
 
  249   info.codec_fourcc = encoder->fourcc;
 
  250   info.frame_width = (int)strtol(width_arg, NULL, 0);
 
  251   info.frame_height = (int)strtol(height_arg, NULL, 0);
 
  252   info.time_base.numerator = 1;
 
  253   info.time_base.denominator = fps;
 
  255   if (info.frame_width <= 0 || info.frame_height <= 0) {
 
  256     die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
 
  261   if (!
aom_img_alloc(&raw, raw_fmt, info.frame_width, info.frame_height, 32)) {
 
  262     die(
"Failed to allocate image.");
 
  268                                  info.frame_height, 32, 8,
 
  269                                  AOM_BORDER_IN_PIXELS)) {
 
  270     die(
"Failed to allocate image.");
 
  276   if (res) die_codec(&ecodec, 
"Failed to get default codec config.");
 
  278   cfg.
g_w = info.frame_width;
 
  279   cfg.
g_h = info.frame_height;
 
  290   writer = aom_video_writer_open(outfile_arg, kContainerIVF, &info);
 
  291   if (!writer) die(
"Failed to open %s for writing.", outfile_arg);
 
  293   if (!(infile = fopen(infile_arg, 
"rb")))
 
  294     die(
"Failed to open %s for reading.", infile_arg);
 
  297     die_codec(&ecodec, 
"Failed to initialize encoder");
 
  301     die_codec(&ecodec, 
"Failed to set enable auto alt ref");
 
  304     const AvxInterface *decoder = get_aom_decoder_by_name(codec_arg);
 
  306       die_codec(&dcodec, 
"Failed to initialize decoder.");
 
  310   while (aom_img_read(&raw, infile)) {
 
  311     if (limit && frame_in >= limit) 
break;
 
  314     if (FORCE_HIGHBITDEPTH_DECODING) {
 
  317       if (!allocated_raw_shift) {
 
  319                       info.frame_width, info.frame_height, 32);
 
  320         allocated_raw_shift = 1;
 
  322       aom_img_upshift(&raw_shift, &raw, input_shift);
 
  323       frame_to_encode = &raw_shift;
 
  325       frame_to_encode = &raw;
 
  328     if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
 
  335         die_codec(&ecodec, 
"Failed to set encoder reference frame");
 
  336       printf(
" <SET_REF>");
 
  343           die_codec(&dcodec, 
"Failed to set decoder reference frame");
 
  347     encode_frame(&ecodec, frame_to_encode, frame_in, writer, test_decode,
 
  348                  &dcodec, &frame_out, &mismatch_seen, &ext_ref);
 
  350     if (mismatch_seen) 
break;
 
  355     while (encode_frame(&ecodec, NULL, frame_in, writer, test_decode, &dcodec,
 
  356                         &frame_out, &mismatch_seen, NULL)) {
 
  361   printf(
"Processed %d frames.\n", frame_out);
 
  365       printf(
"Encoder/decoder results are matching.\n");
 
  367       printf(
"Encoder/decoder results are NOT matching.\n");
 
  372       die_codec(&dcodec, 
"Failed to destroy decoder");
 
  378     die_codec(&ecodec, 
"Failed to destroy encoder.");
 
  380   aom_video_writer_close(writer);