30 #include "aom/aom_integer.h" 32 #include "aom_dsp/bitwriter_buffer.h" 33 #include "common/tools_common.h" 34 #include "common/video_reader.h" 35 #include "common/video_writer.h" 39 static const char *exec_name;
41 void usage_exit(
void) {
42 fprintf(stderr,
"Usage: %s <infile> <outfile> <num_references> \n",
47 #define ALIGN_POWER_OF_TWO(value, n) \ 48 (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) 51 const uint8_t output_frame_width_in_tiles_minus_1 = 512 / 64 - 1;
52 const uint8_t output_frame_height_in_tiles_minus_1 = 512 / 64 - 1;
74 const int num_tile_lists = 2;
75 const uint16_t tile_count_minus_1 = 9 - 1;
76 const TILE_LIST_INFO tile_list[2][9] = {
105 default: die(
"Invalid image format");
110 int main(
int argc,
char **argv) {
112 AvxVideoReader *reader = NULL;
113 AvxVideoWriter *writer = NULL;
114 const AvxInterface *decoder = NULL;
115 const AvxVideoInfo *info = NULL;
121 if (argc != 4) die(
"Invalid number of arguments.");
123 reader = aom_video_reader_open(argv[1]);
124 if (!reader) die(
"Failed to open %s for reading.", argv[1]);
126 num_references = (int)strtol(argv[3], NULL, 0);
127 info = aom_video_reader_get_info(reader);
131 writer = aom_video_writer_open(argv[2], kContainerIVF, info);
132 if (!writer) die(
"Failed to open %s for writing", argv[2]);
134 decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
135 if (!decoder) die(
"Unknown input codec.");
139 die_codec(&codec,
"Failed to initialize decoder.");
144 for (i = 0; i < num_references; ++i) {
145 aom_video_reader_read_frame(reader);
147 size_t frame_size = 0;
148 const unsigned char *frame =
149 aom_video_reader_get_frame(reader, &frame_size);
153 if (!aom_video_writer_write_frame(writer, frame, frame_size, pts))
154 die_codec(&codec,
"Failed to copy compressed anchor frame.");
157 die_codec(&codec,
"Failed to decode frame.");
164 FILE *infile = aom_video_reader_get_file(reader);
166 const FileOffset camera_frame_pos = ftello(infile);
169 aom_video_reader_read_frame(reader);
174 size_t frame_size = 0;
175 const unsigned char *frame =
176 aom_video_reader_get_frame(reader, &frame_size);
187 if (aom_status) die_codec(&codec,
"Failed to decode tile.");
191 size_t obu_size_offset =
195 uint32_t frame_header_size = (uint32_t)frame_header_info.
extra_size - 1;
196 size_t bytes_to_copy =
197 obu_size_offset + length_field_size + frame_header_size;
199 unsigned char *frame_hdr_buf = (
unsigned char *)malloc(bytes_to_copy);
200 if (frame_hdr_buf == NULL)
201 die_codec(&codec,
"Failed to allocate frame header buffer.");
203 memcpy(frame_hdr_buf, frame, bytes_to_copy);
206 size_t bytes_written = 0;
207 if (aom_uleb_encode_fixed_size(
208 frame_header_size, length_field_size, length_field_size,
209 frame_hdr_buf + obu_size_offset, &bytes_written))
210 die_codec(&codec,
"Failed to encode the tile list obu size.");
213 if (!aom_video_writer_write_frame(writer, frame_hdr_buf, bytes_to_copy,
215 die_codec(&codec,
"Failed to copy compressed camera frame header.");
222 die_codec(&codec,
"Failed to get the image format");
223 const int bps = get_image_bps(ref_fmt);
224 if (!bps) die_codec(&codec,
"Invalid image format.");
226 unsigned int tile_size = 0;
228 die_codec(&codec,
"Failed to get the tile size");
229 const unsigned int tile_width = tile_size >> 16;
230 const unsigned int tile_height = tile_size & 65535;
232 const size_t data_sz = MAX_TILES * ALIGN_POWER_OF_TWO(tile_width, 5) *
233 ALIGN_POWER_OF_TWO(tile_height, 5) * bps / 8;
234 unsigned char *tl_buf = (
unsigned char *)malloc(data_sz);
235 if (tl_buf == NULL) die_codec(&codec,
"Failed to allocate tile list buffer.");
240 for (n = 0; n < num_tile_lists; n++) {
241 unsigned char *tl = tl_buf;
242 struct aom_write_bit_buffer wb = { tl, 0 };
243 unsigned char *saved_obu_size_loc = NULL;
244 uint32_t tile_list_obu_header_size = 0;
245 uint32_t tile_list_obu_size = 0;
248 aom_wb_write_literal(&wb, 0, 1);
249 aom_wb_write_literal(&wb, 8, 4);
250 aom_wb_write_literal(&wb, 0, 1);
251 aom_wb_write_literal(&wb, 1, 1);
252 aom_wb_write_literal(&wb, 0, 1);
254 tile_list_obu_header_size++;
257 saved_obu_size_loc = tl;
259 aom_wb_write_unsigned_literal(&wb, 0, 32);
261 tile_list_obu_header_size += 4;
264 aom_wb_write_literal(&wb, output_frame_width_in_tiles_minus_1, 8);
265 aom_wb_write_literal(&wb, output_frame_height_in_tiles_minus_1, 8);
266 aom_wb_write_literal(&wb, tile_count_minus_1, 16);
268 tile_list_obu_size += 4;
271 for (i = 0; i <= tile_count_minus_1; i++) {
274 int image_idx = tile_list[n][i].image_idx;
275 int ref_idx = tile_list[n][i].reference_idx;
276 int tc = tile_list[n][i].tile_col;
277 int tr = tile_list[n][i].tile_row;
285 fseeko(infile, camera_frame_pos, SEEK_SET);
288 while (frame_cnt != image_idx) {
289 aom_video_reader_read_frame(reader);
293 size_t frame_size = 0;
294 const unsigned char *frame =
295 aom_video_reader_get_frame(reader, &frame_size);
302 if (aom_status) die_codec(&codec,
"Failed to decode tile.");
312 uint32_t tile_info_bytes = 5;
313 aom_wb_write_literal(&wb, ref_idx, 8);
314 aom_wb_write_literal(&wb, tr, 8);
315 aom_wb_write_literal(&wb, tc, 8);
317 tl += tile_info_bytes;
323 tile_list_obu_size +=
328 size_t bytes_written = 0;
329 if (aom_uleb_encode_fixed_size(tile_list_obu_size, 4, 4, saved_obu_size_loc,
331 die_codec(&codec,
"Failed to encode the tile list obu size.");
334 if (!aom_video_writer_write_frame(
335 writer, tl_buf, tile_list_obu_header_size + tile_list_obu_size,
337 die_codec(&codec,
"Failed to copy compressed tile list.");
344 aom_video_writer_close(writer);
345 aom_video_reader_close(reader);
Describes the encoder algorithm interface to applications.
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_encoder.h:86
Definition: aom_image.h:50
Codec context structure.
Definition: aom_codec.h:204
Describes the decoder algorithm interface to applications.
Definition: aom_image.h:49
Structure to hold a tile's start address and size in the bitstream.
Definition: aomdx.h:67
Definition: aom_image.h:54
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, size_t data_sz, void *user_priv)
Decode data.
aom_codec_err_t aom_codec_control_(aom_codec_ctx_t *ctx, int ctrl_id,...)
Control algorithm.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition: aom_decoder.h:142
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
Definition: aom_image.h:53
size_t extra_size
Definition: aomdx.h:73
#define aom_codec_control(ctx, id, data)
aom_codec_control wrapper macro
Definition: aom_codec.h:414
size_t coded_tile_data_size
Definition: aomdx.h:69
const void * coded_tile_data
Definition: aomdx.h:71
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:101
Definition: aom_image.h:52
Provides definitions for using AOM or AV1 within the aom Decoder interface.
Definition: aom_image.h:45