1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98#include <stdio.h>
99#include <stdlib.h>
100#include <string.h>
101
104#include "common/tools_common.h"
105#include "common/video_writer.h"
106
107static const char *exec_name;
108
109void usage_exit(void) {
110 fprintf(stderr,
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",
114 exec_name);
115 exit(EXIT_FAILURE);
116}
117
119 int frame_index, int flags, AvxVideoWriter *writer) {
120 int got_pkts = 0;
125 if (res !=
AOM_CODEC_OK) die_codec(codec,
"Failed to encode frame");
126
128 got_pkts = 1;
129
132 if (!aom_video_writer_write_frame(writer, pkt->
data.
frame.
buf,
135 die_codec(codec, "Failed to write compressed frame");
136 }
137 printf(keyframe ? "K" : ".");
138 fflush(stdout);
139 }
140 }
141
142 return got_pkts;
143}
144
145
146int main(int argc, char **argv) {
147 FILE *infile = NULL;
150 int frame_count = 0;
153 AvxVideoInfo info;
154 AvxVideoWriter *writer = NULL;
155 const int fps = 30;
156 const int bitrate = 200;
157 int keyframe_interval = 0;
158 int max_frames = 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
167 const int usage = 1;
168 const int speed = 7;
169#else
170 const int usage = 0;
171 const int speed = 2;
172#endif
173
174 exec_name = argv[0];
175
176
177
178 memset(&info, 0, sizeof(info));
179
180 if (argc != 9) die("Invalid number of arguments");
181
182 codec_arg = argv[1];
183 width_arg = argv[2];
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);
189
191 if (!encoder) die("Unsupported codec.");
192
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;
198
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);
202 }
203
205 info.frame_height, 1)) {
206 die("Failed to allocate image.");
207 }
208
209 keyframe_interval = (int)strtol(keyframe_interval_arg, NULL, 0);
210 if (keyframe_interval < 0) die("Invalid keyframe interval value.");
211
213
215 if (res) die_codec(&codec, "Failed to get default codec config.");
216
217 cfg.
g_w = info.frame_width;
218 cfg.
g_h = info.frame_height;
223
224 writer = aom_video_writer_open(outfile_arg, kContainerIVF, &info);
225 if (!writer) die("Failed to open %s for writing.", outfile_arg);
226
227 if (!(infile = fopen(infile_arg, "rb")))
228 die("Failed to open %s for reading.", infile_arg);
229
231 die("Failed to initialize encoder");
232
234 die_codec(&codec, "Failed to set cpu-used");
235
236
237 while (aom_img_read(&raw, infile)) {
238 int flags = 0;
239 if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
241 encode_frame(&codec, &raw, frame_count++, flags, writer);
242 frames_encoded++;
243 if (max_frames > 0 && frames_encoded >= max_frames) break;
244 }
245
246
247 while (encode_frame(&codec, NULL, -1, 0, writer)) continue;
248
249 printf("\n");
250 fclose(infile);
251 printf("Processed %d frames.\n", frame_count);
252
255
256 aom_video_writer_close(writer);
257
258 return EXIT_SUCCESS;
259}
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
struct aom_image aom_image_t
Image Descriptor.
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.
struct aom_codec_ctx aom_codec_ctx_t
Codec context structure.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:254
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:288
#define AOM_FRAME_IS_KEY
Definition aom_codec.h:271
@ 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.
struct aom_codec_cx_pkt aom_codec_cx_pkt_t
Encoder output packet.
uint32_t aom_codec_er_flags_t
Error Resilient flags.
Definition aom_encoder.h:97
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:377
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition aom_encoder.h:938
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.
struct aom_codec_enc_cfg aom_codec_enc_cfg_t
Encoder configuration structure.
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:108
size_t sz
Definition aom_encoder.h:125
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:121
union aom_codec_cx_pkt::@202210014045072156205127107315337341215221351166 data
aom_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition aom_encoder.h:127
aom_codec_frame_flags_t flags
Definition aom_encoder.h:130
struct aom_codec_cx_pkt::@202210014045072156205127107315337341215221351166::@052232317104146204273007241322037340334334344046 frame
void * buf
Definition aom_encoder.h:124
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:487
unsigned int g_h
Height of the frame.
Definition aom_encoder.h:433
unsigned int g_w
Width of the frame.
Definition aom_encoder.h:424
aom_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition aom_encoder.h:495
unsigned int rc_target_bitrate
Target data rate.
Definition aom_encoder.h:641
int num
Definition aom_encoder.h:163
int den
Definition aom_encoder.h:164