104 #include "common/tools_common.h" 105 #include "common/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, 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" :
".");
146 int 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;
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);
184 if (!encoder) die(
"Unsupported codec.");
186 info.codec_fourcc = get_fourcc_by_aom_encoder(encoder);
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(
"Failed to initialize encoder");
227 die_codec(&codec,
"Failed to set cpu-used");
230 while (aom_img_read(&raw, infile)) {
232 if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
234 encode_frame(&codec, &raw, frame_count++, flags, writer);
236 if (max_frames > 0 && frames_encoded >= max_frames)
break;
240 while (encode_frame(&codec, NULL, -1, 0, writer))
continue;
244 printf(
"Processed %d frames.\n", frame_count);
249 aom_video_writer_close(writer);
Operation completed without error.
Definition: aom_codec.h:157
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:406
unsigned int rc_target_bitrate
Target data rate.
Definition: aom_encoder.h:618
uint32_t aom_codec_er_flags_t
Error Resilient flags.
Definition: aom_encoder.h:87
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:931
Encoder configuration structure.
Definition: aom_encoder.h:367
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_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: aom_encoder.h:472
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
Codec context structure.
Definition: aom_codec.h:298
Image Descriptor.
Definition: aom_image.h:171
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.
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 struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition: aom_codec.h:254
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:464
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:111
void aom_img_free(aom_image_t *img)
Close an image descriptor.
struct aom_codec_cx_pkt::@1::@2 frame
Definition: aom_encoder.h:98
Codec control function to set encoder internal speed settings, int parameter.
Definition: aomcx.h:213
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:288
#define AOM_FRAME_IS_KEY
Definition: aom_codec.h:271
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:155
int den
Definition: aom_encoder.h:154
Encoder output packet.
Definition: aom_encoder.h:110
int num
Definition: aom_encoder.h:153
Definition: aom_image.h:45
union aom_codec_cx_pkt::@1 data
#define AOM_EFLAG_FORCE_KF
Force this frame to be a keyframe.
Definition: aom_encoder.h:359
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:415