103 #include "common/tools_common.h" 
  104 #include "common/video_writer.h" 
  106 static const char *exec_name;
 
  108 void usage_exit(
void) {
 
  110           "Usage: %s <codec> <width> <height> <infile> <outfile> " 
  111           "<keyframe-interval> <error-resilient> <frames to encode>\n" 
  112           "See comments in simple_encoder.c for more information.\n",
 
  118                         int frame_index, 
int flags, AvxVideoWriter *writer) {
 
  124   if (res != 
AOM_CODEC_OK) die_codec(codec, 
"Failed to encode frame");
 
  131       if (!aom_video_writer_write_frame(writer, pkt->
data.
frame.buf,
 
  134         die_codec(codec, 
"Failed to write compressed frame");
 
  136       printf(keyframe ? 
"K" : 
".");
 
  145 int main(
int argc, 
char **argv) {
 
  153   AvxVideoWriter *writer = NULL;
 
  154   const AvxInterface *encoder = NULL;
 
  156   const int bitrate = 200;
 
  157   int keyframe_interval = 0;
 
  159   int frames_encoded = 0;
 
  160   const char *codec_arg = NULL;
 
  161   const char *width_arg = NULL;
 
  162   const char *height_arg = NULL;
 
  163   const char *infile_arg = NULL;
 
  164   const char *outfile_arg = NULL;
 
  165   const char *keyframe_interval_arg = NULL;
 
  171   memset(&info, 0, 
sizeof(info));
 
  173   if (argc != 9) die(
"Invalid number of arguments");
 
  177   height_arg = argv[3];
 
  178   infile_arg = argv[4];
 
  179   outfile_arg = argv[5];
 
  180   keyframe_interval_arg = argv[6];
 
  181   max_frames = (int)strtol(argv[8], NULL, 0);
 
  183   encoder = get_aom_encoder_by_name(codec_arg);
 
  184   if (!encoder) die(
"Unsupported codec.");
 
  186   info.codec_fourcc = encoder->fourcc;
 
  187   info.frame_width = (int)strtol(width_arg, NULL, 0);
 
  188   info.frame_height = (int)strtol(height_arg, NULL, 0);
 
  189   info.time_base.numerator = 1;
 
  190   info.time_base.denominator = fps;
 
  192   if (info.frame_width <= 0 || info.frame_height <= 0 ||
 
  193       (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
 
  194     die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
 
  198                      info.frame_height, 1)) {
 
  199     die(
"Failed to allocate image.");
 
  202   keyframe_interval = (int)strtol(keyframe_interval_arg, NULL, 0);
 
  203   if (keyframe_interval < 0) die(
"Invalid keyframe interval value.");
 
  208   if (res) die_codec(&codec, 
"Failed to get default codec config.");
 
  210   cfg.
g_w = info.frame_width;
 
  211   cfg.
g_h = info.frame_height;
 
  217   writer = aom_video_writer_open(outfile_arg, kContainerIVF, &info);
 
  218   if (!writer) die(
"Failed to open %s for writing.", outfile_arg);
 
  220   if (!(infile = fopen(infile_arg, 
"rb")))
 
  221     die(
"Failed to open %s for reading.", infile_arg);
 
  224     die_codec(&codec, 
"Failed to initialize encoder");
 
  227   while (aom_img_read(&raw, infile)) {
 
  229     if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
 
  231     encode_frame(&codec, &raw, frame_count++, flags, writer);
 
  233     if (max_frames > 0 && frames_encoded >= max_frames) 
break;
 
  237   while (encode_frame(&codec, NULL, -1, 0, writer)) 
continue;
 
  241   printf(
"Processed %d frames.\n", frame_count);
 
  246   aom_video_writer_close(writer);