55 #include "common/tools_common.h"
56 #include "common/video_writer.h"
58 static const char *exec_name;
60 void usage_exit(
void) {
62 "Usage: %s <codec> <width> <height> <infile> <outfile> "
63 "<limit(optional)>\n",
76 if (res !=
AOM_CODEC_OK) die_codec(ctx,
"Failed to get frame stats.");
84 stats->
buf = realloc(stats->
buf, stats->
sz + pkt_size);
85 memcpy((uint8_t *)stats->
buf + stats->
sz, pkt_buf, pkt_size);
86 stats->
sz += pkt_size;
100 if (res !=
AOM_CODEC_OK) die_codec(ctx,
"Failed to encode frame.");
107 if (!aom_video_writer_write_frame(writer, pkt->
data.
frame.buf,
110 die_codec(ctx,
"Failed to write compressed frame.");
111 printf(keyframe ?
"K" :
".");
120 const AvxInterface *encoder,
127 die_codec(&codec,
"Failed to initialize encoder");
130 while (aom_img_read(raw, infile) && frame_count < limit) {
132 get_frame_stats(&codec, raw, frame_count, 1, 0, &stats);
136 while (get_frame_stats(&codec, NULL, frame_count, 1, 0, &stats)) {
139 printf(
"Pass 0 complete. Processed %d frames.\n", frame_count);
145 static void pass1(
aom_image_t *raw, FILE *infile,
const char *outfile_name,
148 AvxVideoInfo info = { encoder->fourcc,
152 AvxVideoWriter *writer = NULL;
156 writer = aom_video_writer_open(outfile_name, kContainerIVF, &info);
157 if (!writer) die(
"Failed to open %s for writing", outfile_name);
160 die_codec(&codec,
"Failed to initialize encoder");
163 while (aom_img_read(raw, infile) && frame_count < limit) {
165 encode_frame(&codec, raw, frame_count, 1, 0, writer);
169 while (encode_frame(&codec, NULL, -1, 1, 0, writer)) {
176 aom_video_writer_close(writer);
178 printf(
"Pass 1 complete. Processed %d frames.\n", frame_count);
181 int main(
int argc,
char **argv) {
190 const AvxInterface *encoder = NULL;
192 const int bitrate = 200;
193 const char *
const codec_arg = argv[1];
194 const char *
const width_arg = argv[2];
195 const char *
const height_arg = argv[3];
196 const char *
const infile_arg = argv[4];
197 const char *
const outfile_arg = argv[5];
201 if (argc < 6) die(
"Invalid number of arguments");
203 if (argc > 6) limit = (int)strtol(argv[6], NULL, 0);
205 if (limit == 0) limit = 100;
207 encoder = get_aom_encoder_by_name(codec_arg);
208 if (!encoder) die(
"Unsupported codec.");
210 w = (int)strtol(width_arg, NULL, 0);
211 h = (int)strtol(height_arg, NULL, 0);
213 if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
214 die(
"Invalid frame size: %dx%d", w, h);
217 die(
"Failed to allocate image", w, h);
223 if (res) die_codec(&codec,
"Failed to get default codec config.");
231 if (!(infile = fopen(infile_arg,
"rb")))
232 die(
"Failed to open %s for reading", infile_arg);
236 stats = pass0(&raw, infile, encoder, &cfg, limit);
242 pass1(&raw, infile, outfile_arg, encoder, &cfg, limit);
void * buf
Definition: aom_encoder.h:85
Operation completed without error.
Definition: aom_codec.h:103
Definition: aom_encoder.h:196
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:276
unsigned int rc_target_bitrate
Target data rate.
Definition: aom_encoder.h:491
Describes the encoder algorithm interface to applications.
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition: aom_encoder.h:774
Encoder configuration structure.
Definition: aom_encoder.h:237
aom_fixed_buf_t rc_twopass_stats_in
Two-pass stats buffer.
Definition: aom_encoder.h:478
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_encoder.h:94
Codec context structure.
Definition: aom_codec.h:204
#define AOM_FRAME_IS_KEY
Definition: aom_encoder.h:104
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int reserved)
Get a default configuration.
Image Descriptor.
Definition: aom_image.h:141
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.
Generic fixed size buffer structure.
Definition: aom_encoder.h:84
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
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.
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:334
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
Definition: aom_encoder.h:136
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:148
void aom_img_free(aom_image_t *img)
Close an image descriptor.
struct aom_codec_cx_pkt::@1::@2 frame
Definition: aom_encoder.h:135
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:194
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:101
aom_fixed_buf_t twopass_stats
Definition: aom_encoder.h:165
int den
Definition: aom_encoder.h:189
Encoder output packet.
Definition: aom_encoder.h:147
int num
Definition: aom_encoder.h:188
Definition: aom_image.h:45
long aom_enc_frame_flags_t
Encoded Frame Flags.
Definition: aom_encoder.h:228
union aom_codec_cx_pkt::@1 data
size_t sz
Definition: aom_encoder.h:86
Definition: aom_encoder.h:195
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: aom_encoder.h:349
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:285