32 #include "common/tools_common.h" 33 #include "common/video_reader.h" 35 #define MAX_EXTERNAL_REFERENCES 128 36 #define AOM_BORDER_IN_PIXELS 288 38 static const char *exec_name;
40 void usage_exit(
void) {
43 "Usage: %s <infile> <outfile> <lf_width> <lf_height> <lf_blocksize>\n",
59 const int num_tile_lists = 2;
60 const uint16_t tile_count_minus_1 = 9 - 1;
61 const TILE_LIST_INFO tile_list[2][9] = {
82 int main(
int argc,
char **argv) {
85 AvxVideoReader *reader = NULL;
86 const AvxInterface *decoder = NULL;
87 const AvxVideoInfo *info = NULL;
88 const char *lf_width_arg;
89 const char *lf_height_arg;
90 const char *lf_blocksize_arg;
92 int lf_width, lf_height;
96 aom_image_t reference_images[MAX_EXTERNAL_REFERENCES];
97 size_t frame_size = 0;
98 const unsigned char *frame = NULL;
103 if (argc != 6) die(
"Invalid number of arguments.");
105 reader = aom_video_reader_open(argv[1]);
106 if (!reader) die(
"Failed to open %s for reading.", argv[1]);
108 if (!(outfile = fopen(argv[2],
"wb")))
109 die(
"Failed to open %s for writing.", argv[2]);
111 lf_width_arg = argv[3];
112 lf_height_arg = argv[4];
113 lf_blocksize_arg = argv[5];
114 lf_width = (int)strtol(lf_width_arg, NULL, 0);
115 lf_height = (int)strtol(lf_height_arg, NULL, 0);
116 lf_blocksize = (int)strtol(lf_blocksize_arg, NULL, 0);
118 info = aom_video_reader_get_info(reader);
119 width = info->frame_width;
120 height = info->frame_height;
122 decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
123 if (!decoder) die(
"Unknown input codec.");
127 die_codec(&codec,
"Failed to initialize decoder.");
130 u_blocks = (lf_width + lf_blocksize - 1) / lf_blocksize;
131 v_blocks = (lf_height + lf_blocksize - 1) / lf_blocksize;
133 int num_references = v_blocks * u_blocks;
139 for (i = 0; i < num_references; i++) {
140 unsigned int border = AOM_BORDER_IN_PIXELS;
143 die(
"Failed to allocate references.");
150 for (i = 0; i < num_references; ++i) {
151 aom_video_reader_read_frame(reader);
152 frame = aom_video_reader_get_frame(reader, &frame_size);
154 die_codec(&codec,
"Failed to decode frame.");
157 &reference_images[i]))
158 die_codec(&codec,
"Failed to copy decoded reference frame");
164 snprintf(name,
sizeof(name),
"ref_%d.yuv", i);
165 printf(
"writing ref image to %s, %d, %d\n", name, img->
d_w, img->
d_h);
166 FILE *ref_file = fopen(name,
"wb");
167 aom_img_write(img, ref_file);
172 FILE *infile = aom_video_reader_get_file(reader);
174 const FileOffset camera_frame_pos = ftello(infile);
177 for (n = 0; n < num_tile_lists; n++) {
178 for (i = 0; i <= tile_count_minus_1; i++) {
179 int image_idx = tile_list[n][i].image_idx;
180 int ref_idx = tile_list[n][i].reference_idx;
181 int tc = tile_list[n][i].tile_col;
182 int tr = tile_list[n][i].tile_row;
186 fseeko(infile, camera_frame_pos, SEEK_SET);
189 while (frame_cnt != image_idx) {
190 aom_video_reader_read_frame(reader);
194 frame = aom_video_reader_get_frame(reader, &frame_size);
204 ref.
img = reference_images[ref_idx];
206 die_codec(&codec,
"Failed to set reference frame.");
211 if (aom_status) die_codec(&codec,
"Failed to decode tile.");
215 aom_img_write(img, outfile);
219 for (i = 0; i < num_references; i++)
aom_img_free(&reference_images[i]);
221 aom_video_reader_close(reader);
unsigned int d_h
Definition: aom_image.h:157
aom_image_t * aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Decoded frames iterator.
int idx
Definition: aom.h:109
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
Codec context structure.
Definition: aom_codec.h:204
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
Describes the decoder algorithm interface to applications.
Image Descriptor.
Definition: aom_image.h:141
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.
aom_image_t * aom_img_alloc_with_border(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align, unsigned int size_align, unsigned int border)
Open a descriptor, allocating storage for the underlying image with a border.
void aom_img_free(aom_image_t *img)
Close an image descriptor.
#define aom_codec_control(ctx, id, data)
aom_codec_control wrapper macro
Definition: aom_codec.h:423
AV1 specific reference frame data struct.
Definition: aom.h:108
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:194
int use_external_ref
Definition: aom.h:110
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:101
Provides definitions for using AOM or AV1 within the aom Decoder interface.
aom_image_t img
Definition: aom.h:111
Definition: aom_image.h:45
unsigned int d_w
Definition: aom_image.h:156