31 #include "aom/aom_integer.h" 33 #include "aom_dsp/bitwriter_buffer.h" 34 #include "common/tools_common.h" 35 #include "common/video_reader.h" 36 #include "common/video_writer.h" 38 static const char *exec_name;
40 void usage_exit(
void) {
43 "Usage: %s <infile> <outfile> <lf_width> <lf_height> <lf_blocksize> \n",
48 #define ALIGN_POWER_OF_TWO(value, n) \ 49 (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) 52 const uint8_t output_frame_width_in_tiles_minus_1 = 512 / 64 - 1;
53 const uint8_t output_frame_height_in_tiles_minus_1 = 512 / 64 - 1;
75 const int num_tile_lists = 2;
76 const uint16_t tile_count_minus_1 = 9 - 1;
77 const TILE_LIST_INFO tile_list[2][9] = {
98 int main(
int argc,
char **argv) {
100 AvxVideoReader *reader = NULL;
101 AvxVideoWriter *writer = NULL;
102 const AvxInterface *decoder = NULL;
103 const AvxVideoInfo *info = NULL;
104 const char *lf_width_arg;
105 const char *lf_height_arg;
106 const char *lf_blocksize_arg;
108 int lf_width, lf_height;
110 int u_blocks, v_blocks;
115 if (argc != 6) die(
"Invalid number of arguments.");
117 reader = aom_video_reader_open(argv[1]);
118 if (!reader) die(
"Failed to open %s for reading.", argv[1]);
120 lf_width_arg = argv[3];
121 lf_height_arg = argv[4];
122 lf_blocksize_arg = argv[5];
124 lf_width = (int)strtol(lf_width_arg, NULL, 0);
125 lf_height = (int)strtol(lf_height_arg, NULL, 0);
126 lf_blocksize = (int)strtol(lf_blocksize_arg, NULL, 0);
128 info = aom_video_reader_get_info(reader);
129 width = info->frame_width;
130 height = info->frame_height;
134 writer = aom_video_writer_open(argv[2], kContainerIVF, info);
135 if (!writer) die(
"Failed to open %s for writing", argv[2]);
137 decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
138 if (!decoder) die(
"Unknown input codec.");
142 die_codec(&codec,
"Failed to initialize decoder.");
148 u_blocks = (lf_width + lf_blocksize - 1) / lf_blocksize;
149 v_blocks = (lf_height + lf_blocksize - 1) / lf_blocksize;
151 int num_references = v_blocks * u_blocks;
152 for (i = 0; i < num_references; ++i) {
153 aom_video_reader_read_frame(reader);
155 size_t frame_size = 0;
156 const unsigned char *frame =
157 aom_video_reader_get_frame(reader, &frame_size);
161 if (!aom_video_writer_write_frame(writer, frame, frame_size, pts))
162 die_codec(&codec,
"Failed to copy compressed anchor frame.");
165 die_codec(&codec,
"Failed to decode frame.");
172 FILE *infile = aom_video_reader_get_file(reader);
174 const FileOffset camera_frame_pos = ftello(infile);
177 aom_video_reader_read_frame(reader);
182 size_t frame_size = 0;
183 const unsigned char *frame =
184 aom_video_reader_get_frame(reader, &frame_size);
195 if (aom_status) die_codec(&codec,
"Failed to decode tile.");
199 size_t obu_size_offset =
203 uint32_t frame_header_size = (uint32_t)frame_header_info.
extra_size - 1;
204 size_t bytes_to_copy =
205 obu_size_offset + length_field_size + frame_header_size;
207 unsigned char *frame_hdr_buf = (
unsigned char *)malloc(bytes_to_copy);
208 if (frame_hdr_buf == NULL)
209 die_codec(&codec,
"Failed to allocate frame header buffer.");
211 memcpy(frame_hdr_buf, frame, bytes_to_copy);
214 size_t bytes_written = 0;
215 if (aom_uleb_encode_fixed_size(
216 frame_header_size, length_field_size, length_field_size,
217 frame_hdr_buf + obu_size_offset, &bytes_written))
218 die_codec(&codec,
"Failed to encode the tile list obu size.");
221 if (!aom_video_writer_write_frame(writer, frame_hdr_buf, bytes_to_copy,
223 die_codec(&codec,
"Failed to copy compressed camera frame header.");
229 ALIGN_POWER_OF_TWO(width, 5) * ALIGN_POWER_OF_TWO(height, 5) * 12 / 8;
230 unsigned char *tl_buf = (
unsigned char *)malloc(data_sz);
231 if (tl_buf == NULL) die_codec(&codec,
"Failed to allocate tile list buffer.");
236 for (n = 0; n < num_tile_lists; n++) {
237 unsigned char *tl = tl_buf;
238 struct aom_write_bit_buffer wb = { tl, 0 };
239 unsigned char *saved_obu_size_loc = NULL;
240 uint32_t tile_list_obu_header_size = 0;
241 uint32_t tile_list_obu_size = 0;
244 aom_wb_write_literal(&wb, 0, 1);
245 aom_wb_write_literal(&wb, 8, 4);
246 aom_wb_write_literal(&wb, 0, 1);
247 aom_wb_write_literal(&wb, 1, 1);
248 aom_wb_write_literal(&wb, 0, 1);
250 tile_list_obu_header_size++;
253 saved_obu_size_loc = tl;
254 aom_wb_write_literal(&wb, 0, 32);
256 tile_list_obu_header_size += 4;
259 aom_wb_write_literal(&wb, output_frame_width_in_tiles_minus_1, 8);
260 aom_wb_write_literal(&wb, output_frame_height_in_tiles_minus_1, 8);
261 aom_wb_write_literal(&wb, tile_count_minus_1, 16);
263 tile_list_obu_size += 4;
266 for (i = 0; i <= tile_count_minus_1; i++) {
269 int image_idx = tile_list[n][i].image_idx;
270 int ref_idx = tile_list[n][i].reference_idx;
271 int tc = tile_list[n][i].tile_col;
272 int tr = tile_list[n][i].tile_row;
280 fseeko(infile, camera_frame_pos, SEEK_SET);
283 while (frame_cnt != image_idx) {
284 aom_video_reader_read_frame(reader);
288 size_t frame_size = 0;
289 const unsigned char *frame =
290 aom_video_reader_get_frame(reader, &frame_size);
297 if (aom_status) die_codec(&codec,
"Failed to decode tile.");
307 uint32_t tile_info_bytes = 5;
308 aom_wb_write_literal(&wb, ref_idx, 8);
309 aom_wb_write_literal(&wb, tr, 8);
310 aom_wb_write_literal(&wb, tc, 8);
312 tl += tile_info_bytes;
318 tile_list_obu_size +=
323 size_t bytes_written = 0;
324 if (aom_uleb_encode_fixed_size(tile_list_obu_size, 4, 4, saved_obu_size_loc,
326 die_codec(&codec,
"Failed to encode the tile list obu size.");
329 if (!aom_video_writer_write_frame(
330 writer, tl_buf, tile_list_obu_header_size + tile_list_obu_size,
332 die_codec(&codec,
"Failed to copy compressed tile list.");
339 aom_video_writer_close(writer);
340 aom_video_reader_close(reader);
Describes the encoder algorithm interface to applications.
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_encoder.h:94
Codec context structure.
Definition: aom_codec.h:204
Describes the decoder algorithm interface to applications.
Structure to hold a tile's start address and size in the bitstream.
Definition: aomdx.h:67
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.
size_t extra_size
Definition: aomdx.h:73
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
Provides definitions for using AOM or AV1 within the aom Decoder interface.