104#include "common/tools_common.h"
105#include "common/video_writer.h"
107static const char *exec_name;
109void 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, AvxVideoWriter *writer) {
125 if (res !=
AOM_CODEC_OK) die_codec(codec,
"Failed to encode frame");
132 if (!aom_video_writer_write_frame(writer, pkt->
data.
frame.
buf,
135 die_codec(codec,
"Failed to write compressed frame");
137 printf(keyframe ?
"K" :
".");
146int main(
int argc,
char **argv) {
154 AvxVideoWriter *writer = 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;
166#if CONFIG_REALTIME_ONLY
178 memset(&info, 0,
sizeof(info));
180 if (argc != 9) die(
"Invalid number of arguments");
184 height_arg = argv[3];
185 infile_arg = argv[4];
186 outfile_arg = argv[5];
187 keyframe_interval_arg = argv[6];
188 max_frames = (int)strtol(argv[8], NULL, 0);
191 if (!encoder) die(
"Unsupported codec.");
193 info.codec_fourcc = get_fourcc_by_aom_encoder(encoder);
194 info.frame_width = (int)strtol(width_arg, NULL, 0);
195 info.frame_height = (int)strtol(height_arg, NULL, 0);
196 info.time_base.numerator = 1;
197 info.time_base.denominator = fps;
199 if (info.frame_width <= 0 || info.frame_height <= 0 ||
200 (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
201 die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
205 info.frame_height, 1)) {
206 die(
"Failed to allocate image.");
209 keyframe_interval = (int)strtol(keyframe_interval_arg, NULL, 0);
210 if (keyframe_interval < 0) die(
"Invalid keyframe interval value.");
215 if (res) die_codec(&codec,
"Failed to get default codec config.");
217 cfg.
g_w = info.frame_width;
218 cfg.
g_h = info.frame_height;
224 writer = aom_video_writer_open(outfile_arg, kContainerIVF, &info);
225 if (!writer) die(
"Failed to open %s for writing.", outfile_arg);
227 if (!(infile = fopen(infile_arg,
"rb")))
228 die(
"Failed to open %s for reading.", infile_arg);
231 die(
"Failed to initialize encoder");
234 die_codec(&codec,
"Failed to set cpu-used");
237 while (aom_img_read(&raw, infile)) {
239 if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
241 encode_frame(&codec, &raw, frame_count++, flags, writer);
243 if (max_frames > 0 && frames_encoded >= max_frames)
break;
247 while (encode_frame(&codec, NULL, -1, 0, writer))
continue;
251 printf(
"Processed %d frames.\n", frame_count);
256 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.
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:220
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:271
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:155
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:305
#define AOM_FRAME_IS_KEY
Definition aom_codec.h:288
@ AOM_CODEC_OK
Operation completed without error.
Definition aom_codec.h:157
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
uint32_t aom_codec_er_flags_t
Error Resilient flags.
Definition aom_encoder.h:99
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
Force this frame to be a keyframe.
Definition aom_encoder.h:379
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition aom_encoder.h:943
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.
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:110
Codec context structure.
Definition aom_codec.h:315
Encoder output packet.
Definition aom_encoder.h:122
size_t sz
Definition aom_encoder.h:127
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:123
union aom_codec_cx_pkt::@1 data
aom_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition aom_encoder.h:129
struct aom_codec_cx_pkt::@1::@2 frame
aom_codec_frame_flags_t flags
Definition aom_encoder.h:132
void * buf
Definition aom_encoder.h:126
Encoder configuration structure.
Definition aom_encoder.h:387
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:489
unsigned int g_h
Height of the frame.
Definition aom_encoder.h:435
unsigned int g_w
Width of the frame.
Definition aom_encoder.h:426
aom_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition aom_encoder.h:497
unsigned int rc_target_bitrate
Target data rate.
Definition aom_encoder.h:644
Image Descriptor.
Definition aom_image.h:182
int num
Definition aom_encoder.h:165
int den
Definition aom_encoder.h:166