78 #include "av1/common/enums.h"
79 #include "common/tools_common.h"
80 #include "common/video_writer.h"
82 static const char *exec_name;
84 void usage_exit(
void) {
86 "Usage: %s <codec> <width> <height> <infile0> <infile1> "
87 "<outfile> <frames to encode>\n"
88 "See comments in scalable_encoder.c for more information.\n",
94 int frame_index,
int flags, FILE *outfile) {
100 if (res !=
AOM_CODEC_OK) die_codec(codec,
"Failed to encode frame");
109 die_codec(codec,
"Failed to write compressed frame");
111 printf(keyframe ?
"K" :
".");
112 printf(
" %6d\n", (
int)pkt->
data.
frame.sz);
120 int main(
int argc,
char **argv) {
121 FILE *infile0 = NULL;
122 FILE *infile1 = NULL;
129 const AvxInterface *encoder = NULL;
131 const int bitrate = 200;
132 int keyframe_interval = 0;
134 int frames_encoded = 0;
135 const char *codec_arg = NULL;
136 const char *width_arg = NULL;
137 const char *height_arg = NULL;
138 const char *infile0_arg = NULL;
139 const char *infile1_arg = NULL;
140 const char *outfile_arg = NULL;
142 FILE *outfile = NULL;
148 memset(&info, 0,
sizeof(info));
150 if (argc != 8) die(
"Invalid number of arguments");
154 height_arg = argv[3];
155 infile0_arg = argv[4];
156 infile1_arg = argv[5];
157 outfile_arg = argv[6];
158 max_frames = (int)strtol(argv[7], NULL, 0);
160 encoder = get_aom_encoder_by_name(codec_arg);
161 if (!encoder) die(
"Unsupported codec.");
163 info.codec_fourcc = encoder->fourcc;
164 info.frame_width = (int)strtol(width_arg, NULL, 0);
165 info.frame_height = (int)strtol(height_arg, NULL, 0);
166 info.time_base.numerator = 1;
167 info.time_base.denominator = fps;
169 if (info.frame_width <= 0 || info.frame_height <= 0 ||
170 (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
171 die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
175 info.frame_height, 1)) {
176 die(
"Failed to allocate image for layer 0.");
179 info.frame_height, 1)) {
180 die(
"Failed to allocate image for layer 1.");
184 keyframe_interval = 100;
185 if (keyframe_interval < 0) die(
"Invalid keyframe interval value.");
190 if (res) die_codec(&codec,
"Failed to get default codec config.");
192 cfg.
g_w = info.frame_width;
193 cfg.
g_h = info.frame_height;
202 outfile = fopen(outfile_arg,
"wb");
203 if (!outfile) die(
"Failed to open %s for writing.", outfile_arg);
205 if (!(infile0 = fopen(infile0_arg,
"rb")))
206 die(
"Failed to open %s for reading.", infile0_arg);
207 if (!(infile1 = fopen(infile1_arg,
"rb")))
208 die(
"Failed to open %s for reading.", infile0_arg);
211 die_codec(&codec,
"Failed to initialize encoder");
213 die_codec(&codec,
"Failed to set cpu to 8");
216 die_codec(&codec,
"Failed to set tile columns to 2");
218 die_codec(&codec,
"Failed to set num of tile groups to 3");
221 die_codec(&codec,
"Failed to set number of spatial layers to 2");
224 while (aom_img_read(&raw0, infile0)) {
229 if (keyframe_interval > 0 && frames_encoded % keyframe_interval == 0)
240 cfg.
g_w = info.frame_width;
241 cfg.
g_h = info.frame_height;
243 die_codec(&codec,
"Failed to set enc cfg for layer 0");
245 die_codec(&codec,
"Failed to set layer id to 0");
247 die_codec(&codec,
"Failed to set cq level");
248 encode_frame(&codec, &raw0, frame_count++, flags, outfile);
258 cfg.
g_w = info.frame_width;
259 cfg.
g_h = info.frame_height;
260 aom_img_read(&raw1, infile1);
262 die_codec(&codec,
"Failed to set enc cfg for layer 1");
264 die_codec(&codec,
"Failed to set layer id to 1");
266 die_codec(&codec,
"Failed to set cq level");
267 encode_frame(&codec, &raw1, frame_count++, flags, outfile);
271 if (max_frames > 0 && frames_encoded >= max_frames)
break;
275 while (encode_frame(&codec, NULL, -1, 0, outfile))
continue;
280 printf(
"Processed %d frames.\n", frame_count / 2);