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);
Describes the encoder algorithm interface to applications.
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
void aom_img_free(aom_image_t *img)
Close an image descriptor.
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
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:101
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:209
@ AOM_CODEC_OK
Operation completed without error.
Definition: aom_codec.h:103
uint32_t aom_codec_er_flags_t
Error Resilient flags.
Definition: aom_encoder.h:108
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_EFLAG_FORCE_KF
Definition: aom_encoder.h:361
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition: aom_encoder.h:941
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.
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
#define AOM_FRAME_IS_KEY
Definition: aom_encoder.h:89
@ AOM_CODEC_CX_FRAME_PKT
Definition: aom_encoder.h:119
Codec context structure.
Definition: aom_codec.h:219
Encoder output packet.
Definition: aom_encoder.h:131
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:132
union aom_codec_cx_pkt::@1 data
struct aom_codec_cx_pkt::@1::@2 frame
Encoder configuration structure.
Definition: aom_encoder.h:369
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:466
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:417
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:408
aom_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: aom_encoder.h:474
unsigned int rc_target_bitrate
Target data rate.
Definition: aom_encoder.h:622
Image Descriptor.
Definition: aom_image.h:171
int num
Definition: aom_encoder.h:172
int den
Definition: aom_encoder.h:173