79#include "common/tools_common.h"
80#include "common/video_writer.h"
82static const char *exec_name;
84void usage_exit(
void) {
86 "Usage: %s <codec> <width> <height> <infile0> <infile1> "
87 "<outfile> <frames to encode>\n"
88 "See comments in scalable_encoder.c for more information.\n",
94 int frame_index,
int flags, FILE *outfile) {
100 if (res !=
AOM_CODEC_OK) die_codec(codec,
"Failed to encode frame");
109 die_codec(codec,
"Failed to write compressed frame");
111 printf(keyframe ?
"K" :
".");
120int main(
int argc,
char **argv) {
121 FILE *infile0 = NULL;
122 FILE *infile1 = NULL;
129 const int bitrate = 200;
130 int keyframe_interval = 0;
132 int frames_encoded = 0;
133 const char *codec_arg = NULL;
134 const char *width_arg = NULL;
135 const char *height_arg = NULL;
136 const char *infile0_arg = NULL;
137 const char *infile1_arg = NULL;
138 const char *outfile_arg = NULL;
140 FILE *outfile = NULL;
146 memset(&info, 0,
sizeof(info));
148 if (argc != 8) die(
"Invalid number of arguments");
152 height_arg = argv[3];
153 infile0_arg = argv[4];
154 infile1_arg = argv[5];
155 outfile_arg = argv[6];
156 max_frames = (int)strtol(argv[7], NULL, 0);
159 if (!encoder) die(
"Unsupported codec.");
161 info.codec_fourcc = get_fourcc_by_aom_encoder(encoder);
162 info.frame_width = (int)strtol(width_arg, NULL, 0);
163 info.frame_height = (int)strtol(height_arg, NULL, 0);
164 info.time_base.numerator = 1;
165 info.time_base.denominator = fps;
167 if (info.frame_width <= 0 || info.frame_height <= 0 ||
168 (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
169 die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
173 info.frame_height, 1)) {
174 die(
"Failed to allocate image for layer 0.");
177 info.frame_height, 1)) {
178 die(
"Failed to allocate image for layer 1.");
182 keyframe_interval = 100;
183 if (keyframe_interval < 0) die(
"Invalid keyframe interval value.");
189 if (res) die_codec(&codec,
"Failed to get default codec config.");
191 cfg.
g_w = info.frame_width;
192 cfg.
g_h = info.frame_height;
201 outfile = fopen(outfile_arg,
"wb");
202 if (!outfile) die(
"Failed to open %s for writing.", outfile_arg);
204 if (!(infile0 = fopen(infile0_arg,
"rb")))
205 die(
"Failed to open %s for reading.", infile0_arg);
206 if (!(infile1 = fopen(infile1_arg,
"rb")))
207 die(
"Failed to open %s for reading.", infile0_arg);
210 die(
"Failed to initialize encoder");
212 die_codec(&codec,
"Failed to set cpu to 8");
215 die_codec(&codec,
"Failed to set tile columns to 2");
217 die_codec(&codec,
"Failed to set num of tile groups to 3");
220 die_codec(&codec,
"Failed to set number of spatial layers to 2");
223 while (aom_img_read(&raw0, infile0)) {
228 if (keyframe_interval > 0 && frames_encoded % keyframe_interval == 0)
239 cfg.
g_w = info.frame_width;
240 cfg.
g_h = info.frame_height;
242 die_codec(&codec,
"Failed to set enc cfg for layer 0");
244 die_codec(&codec,
"Failed to set layer id to 0");
246 die_codec(&codec,
"Failed to set cq level");
247 encode_frame(&codec, &raw0, frame_count++, flags, outfile);
257 cfg.
g_w = info.frame_width;
258 cfg.
g_h = info.frame_height;
259 aom_img_read(&raw1, infile1);
261 die_codec(&codec,
"Failed to set enc cfg for layer 1");
263 die_codec(&codec,
"Failed to set layer id to 1");
265 die_codec(&codec,
"Failed to set cq level");
266 encode_frame(&codec, &raw1, frame_count++, flags, outfile);
270 if (max_frames > 0 && frames_encoded >= max_frames)
break;
274 while (encode_frame(&codec, NULL, -1, 0, outfile))
continue;
279 printf(
"Processed %d frames.\n", frame_count / 2);
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.
#define AOM_EFLAG_NO_UPD_ARF
Don't update the alternate reference frame.
Definition aomcx.h:136
#define AOM_EFLAG_NO_REF_LAST2
Don't reference the last2 frame.
Definition aomcx.h:79
#define AOM_EFLAG_NO_REF_BWD
Don't reference the bwd reference frame.
Definition aomcx.h:108
#define AOM_EFLAG_NO_UPD_LAST
Don't update the last frame.
Definition aomcx.h:122
#define AOM_EFLAG_NO_REF_ARF
Don't reference the alternate reference frame.
Definition aomcx.h:101
#define AOM_EFLAG_NO_REF_LAST3
Don't reference the last3 frame.
Definition aomcx.h:86
#define AOM_EFLAG_NO_UPD_GF
Don't update the golden frame.
Definition aomcx.h:129
#define AOM_EFLAG_NO_REF_GF
Don't reference the golden frame.
Definition aomcx.h:93
#define AOM_EFLAG_NO_UPD_ENTROPY
Disable entropy update.
Definition aomcx.h:142
#define AOM_EFLAG_NO_REF_ARF2
Don't reference the alt2 reference frame.
Definition aomcx.h:115
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition aomcx.h:789
@ AOME_SET_SPATIAL_LAYER_ID
Codec control function to set encoder spatial layer id, int parameter.
Definition aomcx.h:202
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition aomcx.h:380
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:220
@ AOME_SET_NUMBER_SPATIAL_LAYERS
Codec control function to set number of spatial layers, int parameter.
Definition aomcx.h:311
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition aomcx.h:292
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.
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_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx, const aom_codec_enc_cfg_t *cfg)
Set or change configuration.
@ AOM_Q
Definition aom_encoder.h:189
@ 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
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
enum aom_rc_mode rc_end_usage
Rate control algorithm to use.
Definition aom_encoder.h:623
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition aom_encoder.h:518
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
unsigned int save_as_annexb
Bitstream syntax mode.
Definition aom_encoder.h:844
Image Descriptor.
Definition aom_image.h:182
int num
Definition aom_encoder.h:165
int den
Definition aom_encoder.h:166