blob: 30e4fca4e9195c98d787c187a41abe975c7ab59a [file] [log] [blame]
Yunqing Wang40bde4d2018-06-01 16:48:03 -07001/*
2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12// Lightfield Bitstream Parsing
13// ============================
14//
Yunqing Wangce285452018-06-25 14:51:51 -070015// This is a lightfield bitstream parsing example. It takes an input file
Ryan Overbeck18521392018-09-21 09:43:24 -070016// containing the whole compressed lightfield bitstream(ivf file) and a text
17// file containing a stream of tiles to decode and then constructs and outputs
18// a new bitstream that can be decoded by an AV1 decoder. The output bitstream
19// contains reference frames(i.e. anchor frames), camera frame header, and
20// tile list OBUs. num_references is the number of anchor frames coded at the
21// beginning of the light field file. After running the lightfield encoder,
22// run lightfield bitstream parsing:
Yunqing Wangce285452018-06-25 14:51:51 -070023// examples/lightfield_bitstream_parsing vase10x10.ivf vase_tile_list.ivf 4
Ryan Overbeck18521392018-09-21 09:43:24 -070024// tile_list.txt
25//
26// The tile_list.txt is expected to be of the form:
27// Frame <frame_index0>
28// <image_index0> <anchor_index0> <tile_col0> <tile_row0>
29// <image_index1> <anchor_index1> <tile_col1> <tile_row1>
30// ...
31// Frame <frame_index1)
32// ...
33//
34// The "Frame" markers indicate a new render frame and thus a new tile list
35// will be started and the old one flushed. The image_indexN, anchor_indexN,
36// tile_colN, and tile_rowN identify an individual tile to be decoded and
37// to use anchor_indexN anchor image for MCP.
Yunqing Wang40bde4d2018-06-01 16:48:03 -070038
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
Yunqing Wang40bde4d2018-06-01 16:48:03 -070042
43#include "aom/aom_decoder.h"
44#include "aom/aom_encoder.h"
Yunqing Wang946ec2b2018-06-06 12:34:23 -070045#include "aom/aom_integer.h"
Yunqing Wang40bde4d2018-06-01 16:48:03 -070046#include "aom/aomdx.h"
Yunqing Wang946ec2b2018-06-06 12:34:23 -070047#include "aom_dsp/bitwriter_buffer.h"
Yunqing Wang40bde4d2018-06-01 16:48:03 -070048#include "common/tools_common.h"
49#include "common/video_reader.h"
50#include "common/video_writer.h"
51
Yunqing Wangd74f5682018-07-12 14:34:56 -070052#define MAX_TILES 512
53
Yunqing Wang40bde4d2018-06-01 16:48:03 -070054static const char *exec_name;
55
56void usage_exit(void) {
Ryan Overbeck18521392018-09-21 09:43:24 -070057 fprintf(stderr, "Usage: %s <infile> <outfile> <num_references> <tile_list>\n",
Ryan Overbeck49a82172018-06-21 15:24:36 -070058 exec_name);
Yunqing Wang40bde4d2018-06-01 16:48:03 -070059 exit(EXIT_FAILURE);
60}
61
62#define ALIGN_POWER_OF_TWO(value, n) \
63 (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
64
Yunqing Wang6ff48092018-11-13 14:10:48 -080065const int output_frame_width = 512;
66const int output_frame_height = 512;
Yunqing Wang40bde4d2018-06-01 16:48:03 -070067
68// Spec:
69// typedef struct {
70// uint8_t anchor_frame_idx;
71// uint8_t tile_row;
72// uint8_t tile_col;
73// uint16_t coded_tile_data_size_minus_1;
74// uint8_t *coded_tile_data;
75// } TILE_LIST_ENTRY;
76
77// Tile list entry provided by the application
78typedef struct {
79 int image_idx;
80 int reference_idx;
81 int tile_col;
82 int tile_row;
83} TILE_LIST_INFO;
84
Yunqing Wangd74f5682018-07-12 14:34:56 -070085static int get_image_bps(aom_img_fmt_t fmt) {
86 switch (fmt) {
87 case AOM_IMG_FMT_I420: return 12;
88 case AOM_IMG_FMT_I422: return 16;
89 case AOM_IMG_FMT_I444: return 24;
90 case AOM_IMG_FMT_I42016: return 24;
91 case AOM_IMG_FMT_I42216: return 32;
92 case AOM_IMG_FMT_I44416: return 48;
93 default: die("Invalid image format");
94 }
Yaowu Xu0415f2e2018-07-23 11:48:53 -070095 return 0;
Yunqing Wangd74f5682018-07-12 14:34:56 -070096}
97
Ryan Overbeck18521392018-09-21 09:43:24 -070098void process_tile_list(const TILE_LIST_INFO *tiles, int num_tiles,
99 aom_codec_pts_t tl_pts, unsigned char **frames,
100 const size_t *frame_sizes, aom_codec_ctx_t *codec,
Yunqing Wang6ff48092018-11-13 14:10:48 -0800101 unsigned char *tl_buf, AvxVideoWriter *writer,
102 uint8_t output_frame_width_in_tiles_minus_1,
103 uint8_t output_frame_height_in_tiles_minus_1) {
Ryan Overbeck18521392018-09-21 09:43:24 -0700104 unsigned char *tl = tl_buf;
105 struct aom_write_bit_buffer wb = { tl, 0 };
106 unsigned char *saved_obu_size_loc = NULL;
107 uint32_t tile_list_obu_header_size = 0;
108 uint32_t tile_list_obu_size = 0;
109 int num_tiles_minus_1 = num_tiles - 1;
110 int i;
111
112 // Write the tile list OBU header that is 1 byte long.
113 aom_wb_write_literal(&wb, 0, 1); // forbidden bit.
114 aom_wb_write_literal(&wb, 8, 4); // tile list OBU: "1000"
115 aom_wb_write_literal(&wb, 0, 1); // obu_extension = 0
116 aom_wb_write_literal(&wb, 1, 1); // obu_has_size_field
117 aom_wb_write_literal(&wb, 0, 1); // reserved
118 tl++;
119 tile_list_obu_header_size++;
120
121 // Write the OBU size using a fixed length_field_size of 4 bytes.
122 saved_obu_size_loc = tl;
123 // aom_wb_write_unsigned_literal(&wb, data, bits) requires that bits <= 32.
124 aom_wb_write_unsigned_literal(&wb, 0, 32);
125 tl += 4;
126 tile_list_obu_header_size += 4;
127
128 // write_tile_list_obu()
129 aom_wb_write_literal(&wb, output_frame_width_in_tiles_minus_1, 8);
130 aom_wb_write_literal(&wb, output_frame_height_in_tiles_minus_1, 8);
131 aom_wb_write_literal(&wb, num_tiles_minus_1, 16);
132 tl += 4;
133 tile_list_obu_size += 4;
134
135 // Write each tile's data
136 for (i = 0; i <= num_tiles_minus_1; i++) {
137 aom_tile_data tile_data = { 0, NULL, 0 };
138
139 int image_idx = tiles[i].image_idx;
140 int ref_idx = tiles[i].reference_idx;
141 int tc = tiles[i].tile_col;
142 int tr = tiles[i].tile_row;
143
144 // Reset bit writer to the right location.
145 wb.bit_buffer = tl;
146 wb.bit_offset = 0;
147
148 size_t frame_size = frame_sizes[image_idx];
149 const unsigned char *frame = frames[image_idx];
150
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700151 AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_ROW, tr);
152 AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_COL, tc);
Ryan Overbeck18521392018-09-21 09:43:24 -0700153
154 aom_codec_err_t aom_status =
155 aom_codec_decode(codec, frame, frame_size, NULL);
156 if (aom_status) die_codec(codec, "Failed to decode tile.");
157
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700158 AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1D_GET_TILE_DATA, &tile_data);
Ryan Overbeck18521392018-09-21 09:43:24 -0700159
160 // Copy over tile info.
161 // uint8_t anchor_frame_idx;
162 // uint8_t tile_row;
163 // uint8_t tile_col;
164 // uint16_t coded_tile_data_size_minus_1;
165 // uint8_t *coded_tile_data;
166 uint32_t tile_info_bytes = 5;
167 aom_wb_write_literal(&wb, ref_idx, 8);
168 aom_wb_write_literal(&wb, tr, 8);
169 aom_wb_write_literal(&wb, tc, 8);
170 aom_wb_write_literal(&wb, (int)tile_data.coded_tile_data_size - 1, 16);
171 tl += tile_info_bytes;
172
173 memcpy(tl, (uint8_t *)tile_data.coded_tile_data,
174 tile_data.coded_tile_data_size);
175 tl += tile_data.coded_tile_data_size;
176
177 tile_list_obu_size +=
178 tile_info_bytes + (uint32_t)tile_data.coded_tile_data_size;
179 }
180
181 // Write tile list OBU size.
182 size_t bytes_written = 0;
183 if (aom_uleb_encode_fixed_size(tile_list_obu_size, 4, 4, saved_obu_size_loc,
184 &bytes_written))
185 die_codec(codec, "Failed to encode the tile list obu size.");
186
187 // Copy the tile list.
188 if (!aom_video_writer_write_frame(
189 writer, tl_buf, tile_list_obu_header_size + tile_list_obu_size,
190 tl_pts))
191 die_codec(codec, "Failed to copy compressed tile list.");
192}
193
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700194int main(int argc, char **argv) {
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700195 AvxVideoReader *reader = NULL;
196 AvxVideoWriter *writer = NULL;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700197 const AvxVideoInfo *info = NULL;
Ryan Overbeck49a82172018-06-21 15:24:36 -0700198 int num_references;
Ryan Overbeck18521392018-09-21 09:43:24 -0700199 int i;
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700200 aom_codec_pts_t pts;
Ryan Overbeck18521392018-09-21 09:43:24 -0700201 const char *tile_list_file = NULL;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700202
203 exec_name = argv[0];
Ryan Overbeck18521392018-09-21 09:43:24 -0700204 if (argc != 5) die("Invalid number of arguments.");
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700205
206 reader = aom_video_reader_open(argv[1]);
207 if (!reader) die("Failed to open %s for reading.", argv[1]);
208
Ryan Overbeck49a82172018-06-21 15:24:36 -0700209 num_references = (int)strtol(argv[3], NULL, 0);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700210 info = aom_video_reader_get_info(reader);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700211
Yunqing Wang3ae70c92019-01-25 17:34:07 -0800212 aom_video_reader_set_fourcc(reader, AV1_FOURCC);
213
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700214 // The writer to write out ivf file in tile list OBU, which can be decoded by
215 // AV1 decoder.
216 writer = aom_video_writer_open(argv[2], kContainerIVF, info);
217 if (!writer) die("Failed to open %s for writing", argv[2]);
218
Ryan Overbeck18521392018-09-21 09:43:24 -0700219 tile_list_file = argv[4];
220
Elliott Karpilovskycbe219b2020-04-22 16:21:06 -0700221 aom_codec_iface_t *decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700222 if (!decoder) die("Unknown input codec.");
Elliott Karpilovskycbe219b2020-04-22 16:21:06 -0700223 printf("Using %s\n", aom_codec_iface_name(decoder));
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700224
Elliott Karpilovskycbe219b2020-04-22 16:21:06 -0700225 aom_codec_ctx_t codec;
226 if (aom_codec_dec_init(&codec, decoder, NULL, 0))
James Zerndad374f2020-05-06 19:13:19 -0700227 die("Failed to initialize decoder.");
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700228
229 // Decode anchor frames.
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700230 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 0);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700231
Ryan Overbeck18521392018-09-21 09:43:24 -0700232 printf("Reading %d reference images.\n", num_references);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700233 for (i = 0; i < num_references; ++i) {
234 aom_video_reader_read_frame(reader);
235
236 size_t frame_size = 0;
237 const unsigned char *frame =
238 aom_video_reader_get_frame(reader, &frame_size);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700239 pts = (aom_codec_pts_t)aom_video_reader_get_frame_pts(reader);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700240
241 // Copy references bitstream directly.
242 if (!aom_video_writer_write_frame(writer, frame, frame_size, pts))
243 die_codec(&codec, "Failed to copy compressed anchor frame.");
244
245 if (aom_codec_decode(&codec, frame, frame_size, NULL))
246 die_codec(&codec, "Failed to decode frame.");
247 }
248
249 // Decode camera frames.
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700250 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 1);
251 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_EXT_TILE_DEBUG, 1);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700252
253 FILE *infile = aom_video_reader_get_file(reader);
254 // Record the offset of the first camera image.
255 const FileOffset camera_frame_pos = ftello(infile);
256
Ryan Overbeck18521392018-09-21 09:43:24 -0700257 printf("Loading compressed frames into memory.\n");
258
259 // Count the frames in the lightfield.
260 int num_frames = 0;
261 while (aom_video_reader_read_frame(reader)) {
262 ++num_frames;
263 }
264 if (num_frames < 1) die("Input light field has no frames.");
265
266 // Read all of the lightfield frames into memory.
267 unsigned char **frames =
268 (unsigned char **)malloc(num_frames * sizeof(unsigned char *));
269 size_t *frame_sizes = (size_t *)malloc(num_frames * sizeof(size_t));
270 // Seek to the first camera image.
271 fseeko(infile, camera_frame_pos, SEEK_SET);
272 for (int f = 0; f < num_frames; ++f) {
273 aom_video_reader_read_frame(reader);
274 size_t frame_size = 0;
275 const unsigned char *frame =
276 aom_video_reader_get_frame(reader, &frame_size);
277 frames[f] = (unsigned char *)malloc(frame_size * sizeof(unsigned char));
278 memcpy(frames[f], frame, frame_size);
279 frame_sizes[f] = frame_size;
280 }
281 printf("Read %d frames.\n", num_frames);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700282
283 // Copy first camera frame for getting camera frame header. This is done
284 // only once.
285 {
Ryan Overbeck18521392018-09-21 09:43:24 -0700286 size_t frame_size = frame_sizes[0];
287 const unsigned char *frame = frames[0];
288 pts = num_references;
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700289 aom_tile_data frame_header_info = { 0, NULL, 0 };
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700290
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700291 // Need to decode frame header to get camera frame header info. So, here
292 // decoding 1 tile is enough.
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700293 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_DECODE_TILE_ROW, 0);
294 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_DECODE_TILE_COL, 0);
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700295
296 aom_codec_err_t aom_status =
297 aom_codec_decode(&codec, frame, frame_size, NULL);
298 if (aom_status) die_codec(&codec, "Failed to decode tile.");
299
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700300 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_FRAME_HEADER_INFO,
301 &frame_header_info);
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700302
303 size_t obu_size_offset =
304 (uint8_t *)frame_header_info.coded_tile_data - frame;
305 size_t length_field_size = frame_header_info.coded_tile_data_size;
Yaowu Xu6fbfae32018-06-18 10:58:11 -0700306 // Remove ext-tile tile info.
307 uint32_t frame_header_size = (uint32_t)frame_header_info.extra_size - 1;
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700308 size_t bytes_to_copy =
309 obu_size_offset + length_field_size + frame_header_size;
310
311 unsigned char *frame_hdr_buf = (unsigned char *)malloc(bytes_to_copy);
312 if (frame_hdr_buf == NULL)
313 die_codec(&codec, "Failed to allocate frame header buffer.");
314
315 memcpy(frame_hdr_buf, frame, bytes_to_copy);
316
317 // Update frame header OBU size.
318 size_t bytes_written = 0;
319 if (aom_uleb_encode_fixed_size(
320 frame_header_size, length_field_size, length_field_size,
321 frame_hdr_buf + obu_size_offset, &bytes_written))
322 die_codec(&codec, "Failed to encode the tile list obu size.");
323
324 // Copy camera frame header bitstream.
325 if (!aom_video_writer_write_frame(writer, frame_hdr_buf, bytes_to_copy,
326 pts))
327 die_codec(&codec, "Failed to copy compressed camera frame header.");
Yunqing Wangaecdda82018-07-26 12:41:56 -0700328 free(frame_hdr_buf);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700329 }
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700330
Yunqing Wangd74f5682018-07-12 14:34:56 -0700331 // Read out the image format.
332 aom_img_fmt_t ref_fmt = 0;
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700333 if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt))
Yunqing Wangd74f5682018-07-12 14:34:56 -0700334 die_codec(&codec, "Failed to get the image format");
335 const int bps = get_image_bps(ref_fmt);
Yunqing Wangaecdda82018-07-26 12:41:56 -0700336 if (!bps) die_codec(&codec, "Invalid image format.");
Yunqing Wangd74f5682018-07-12 14:34:56 -0700337 // read out the tile size.
338 unsigned int tile_size = 0;
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700339 if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_TILE_SIZE, &tile_size))
Yunqing Wangd74f5682018-07-12 14:34:56 -0700340 die_codec(&codec, "Failed to get the tile size");
341 const unsigned int tile_width = tile_size >> 16;
342 const unsigned int tile_height = tile_size & 65535;
343 // Allocate a buffer to store tile list bitstream.
344 const size_t data_sz = MAX_TILES * ALIGN_POWER_OF_TWO(tile_width, 5) *
345 ALIGN_POWER_OF_TWO(tile_height, 5) * bps / 8;
Ryan Overbeck18521392018-09-21 09:43:24 -0700346
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700347 unsigned char *tl_buf = (unsigned char *)malloc(data_sz);
348 if (tl_buf == NULL) die_codec(&codec, "Failed to allocate tile list buffer.");
349
Ryan Overbeck18521392018-09-21 09:43:24 -0700350 aom_codec_pts_t tl_pts = num_references;
Yunqing Wang6ff48092018-11-13 14:10:48 -0800351 const uint8_t output_frame_width_in_tiles_minus_1 =
352 output_frame_width / tile_width - 1;
353 const uint8_t output_frame_height_in_tiles_minus_1 =
354 output_frame_height / tile_height - 1;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700355
Ryan Overbeck18521392018-09-21 09:43:24 -0700356 printf("Reading tile list from file.\n");
357 char line[1024];
358 FILE *tile_list_fptr = fopen(tile_list_file, "r");
David Turner69c98e42018-11-09 14:17:20 +0000359 if (!tile_list_fptr) die_codec(&codec, "Failed to open tile list file.");
Ryan Overbeck18521392018-09-21 09:43:24 -0700360 int num_tiles = 0;
361 TILE_LIST_INFO tiles[MAX_TILES];
362 while ((fgets(line, 1024, tile_list_fptr)) != NULL) {
363 if (line[0] == 'F' || num_tiles >= MAX_TILES) {
364 // Flush existing tile list and start another, either because we hit a
365 // new render frame or because we've hit our max number of tiles per list.
366 if (num_tiles > 0) {
367 process_tile_list(tiles, num_tiles, tl_pts, frames, frame_sizes, &codec,
Yunqing Wang6ff48092018-11-13 14:10:48 -0800368 tl_buf, writer, output_frame_width_in_tiles_minus_1,
369 output_frame_height_in_tiles_minus_1);
Ryan Overbeck18521392018-09-21 09:43:24 -0700370 ++tl_pts;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700371 }
Ryan Overbeck18521392018-09-21 09:43:24 -0700372 num_tiles = 0;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700373 }
Ryan Overbeck18521392018-09-21 09:43:24 -0700374 if (line[0] == 'F') {
375 continue;
376 }
377 if (sscanf(line, "%d %d %d %d", &tiles[num_tiles].image_idx,
378 &tiles[num_tiles].reference_idx, &tiles[num_tiles].tile_col,
379 &tiles[num_tiles].tile_row) == 4) {
380 if (tiles[num_tiles].image_idx >= num_frames) {
381 die("Tile list image_idx out of bounds: %d >= %d.",
382 tiles[num_tiles].image_idx, num_frames);
383 }
384 if (tiles[num_tiles].reference_idx >= num_references) {
385 die("Tile list reference_idx out of bounds: %d >= %d.",
386 tiles[num_tiles].reference_idx, num_references);
387 }
388 ++num_tiles;
389 }
390 }
391 if (num_tiles > 0) {
392 // Flush out the last tile list.
393 process_tile_list(tiles, num_tiles, tl_pts, frames, frame_sizes, &codec,
Yunqing Wang6ff48092018-11-13 14:10:48 -0800394 tl_buf, writer, output_frame_width_in_tiles_minus_1,
395 output_frame_height_in_tiles_minus_1);
Ryan Overbeck18521392018-09-21 09:43:24 -0700396 ++tl_pts;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700397 }
398
Zoe Liu81738a22018-09-27 11:40:08 -0700399 const int num_tile_lists = (int)(tl_pts - pts);
Ryan Overbeck18521392018-09-21 09:43:24 -0700400 printf("Finished processing tile lists. Num tile lists: %d.\n",
401 num_tile_lists);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700402 free(tl_buf);
Ryan Overbeck18521392018-09-21 09:43:24 -0700403 for (int f = 0; f < num_frames; ++f) {
404 free(frames[f]);
405 }
406 free(frame_sizes);
407 free(frames);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700408 if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
409 aom_video_writer_close(writer);
410 aom_video_reader_close(reader);
411
412 return EXIT_SUCCESS;
413}