104 #include "../tools_common.h"
105 #include "../video_writer.h"
107 static const char *exec_name;
109 void usage_exit(
void) {
111 "Usage: %s <codec> <width> <height> <infile> <outfile> "
112 "<keyframe-interval> <error-resilient> <frames to encode>\n"
113 "See comments in simple_encoder.c for more information.\n",
119 int frame_index,
int flags, VpxVideoWriter *writer) {
125 if (res !=
VPX_CODEC_OK) die_codec(codec,
"Failed to encode frame");
132 if (!vpx_video_writer_write_frame(writer, pkt->
data.
frame.buf,
135 die_codec(codec,
"Failed to write compressed frame");
137 printf(keyframe ?
"K" :
".");
146 int main(
int argc,
char **argv) {
153 VpxVideoInfo info = { 0, 0, 0, { 0, 0 } };
154 VpxVideoWriter *writer = NULL;
155 const VpxInterface *encoder = NULL;
157 const int bitrate = 200;
158 int keyframe_interval = 0;
160 int frames_encoded = 0;
161 const char *codec_arg = NULL;
162 const char *width_arg = NULL;
163 const char *height_arg = NULL;
164 const char *infile_arg = NULL;
165 const char *outfile_arg = NULL;
166 const char *keyframe_interval_arg = NULL;
170 if (argc != 9) die(
"Invalid number of arguments");
174 height_arg = argv[3];
175 infile_arg = argv[4];
176 outfile_arg = argv[5];
177 keyframe_interval_arg = argv[6];
178 max_frames = (int)strtol(argv[8], NULL, 0);
180 encoder = get_vpx_encoder_by_name(codec_arg);
181 if (!encoder) die(
"Unsupported codec.");
183 info.codec_fourcc = encoder->fourcc;
184 info.frame_width = (int)strtol(width_arg, NULL, 0);
185 info.frame_height = (int)strtol(height_arg, NULL, 0);
186 info.time_base.numerator = 1;
187 info.time_base.denominator = fps;
189 if (info.frame_width <= 0 || info.frame_height <= 0 ||
190 (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
191 die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
195 info.frame_height, 1)) {
196 die(
"Failed to allocate image.");
199 keyframe_interval = (int)strtol(keyframe_interval_arg, NULL, 0);
200 if (keyframe_interval < 0) die(
"Invalid keyframe interval value.");
205 if (res) die_codec(&codec,
"Failed to get default codec config.");
207 cfg.
g_w = info.frame_width;
208 cfg.
g_h = info.frame_height;
214 writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
215 if (!writer) die(
"Failed to open %s for writing.", outfile_arg);
217 if (!(infile = fopen(infile_arg,
"rb")))
218 die(
"Failed to open %s for reading.", infile_arg);
221 die(
"Failed to initialize encoder");
224 while (vpx_img_read(&raw, infile)) {
226 if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
228 encode_frame(&codec, &raw, frame_count++, flags, writer);
230 if (max_frames > 0 && frames_encoded >= max_frames)
break;
234 while (encode_frame(&codec, NULL, -1, 0, writer)) {
239 printf(
"Processed %d frames.\n", frame_count);
244 vpx_video_writer_close(writer);