28 #include "common/tools_common.h" 29 #include "common/video_reader.h" 31 #define MAX_EXTERNAL_REFERENCES 128 32 #define AOM_BORDER_IN_PIXELS 288 34 static const char *exec_name;
36 void usage_exit(
void) {
37 fprintf(stderr,
"Usage: %s <infile> <outfile> <num_references>\n", exec_name);
52 const int num_tile_lists = 2;
53 const uint16_t tile_count_minus_1 = 9 - 1;
54 const TILE_LIST_INFO tile_list[2][9] = {
75 int main(
int argc,
char **argv) {
78 AvxVideoReader *reader = NULL;
79 const AvxInterface *decoder = NULL;
80 const AvxVideoInfo *info = NULL;
83 aom_image_t reference_images[MAX_EXTERNAL_REFERENCES];
84 size_t frame_size = 0;
85 const unsigned char *frame = NULL;
89 if (argc != 4) die(
"Invalid number of arguments.");
91 reader = aom_video_reader_open(argv[1]);
92 if (!reader) die(
"Failed to open %s for reading.", argv[1]);
94 if (!(outfile = fopen(argv[2],
"wb")))
95 die(
"Failed to open %s for writing.", argv[2]);
97 num_references = (int)strtol(argv[3], NULL, 0);
99 info = aom_video_reader_get_info(reader);
100 width = info->frame_width;
101 height = info->frame_height;
103 decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
104 if (!decoder) die(
"Unknown input codec.");
108 die_codec(&codec,
"Failed to initialize decoder.");
113 for (i = 0; i < num_references; i++) {
114 unsigned int border = AOM_BORDER_IN_PIXELS;
117 die(
"Failed to allocate references.");
122 for (i = 0; i < num_references; ++i) {
123 aom_video_reader_read_frame(reader);
124 frame = aom_video_reader_get_frame(reader, &frame_size);
126 die_codec(&codec,
"Failed to decode frame.");
129 &reference_images[i]))
130 die_codec(&codec,
"Failed to copy decoded reference frame");
136 snprintf(name,
sizeof(name),
"ref_%d.yuv", i);
137 printf(
"writing ref image to %s, %d, %d\n", name, img->
d_w, img->
d_h);
138 FILE *ref_file = fopen(name,
"wb");
139 aom_img_write(img, ref_file);
144 FILE *infile = aom_video_reader_get_file(reader);
146 const FileOffset camera_frame_pos = ftello(infile);
149 for (n = 0; n < num_tile_lists; n++) {
150 for (i = 0; i <= tile_count_minus_1; i++) {
151 int image_idx = tile_list[n][i].image_idx;
152 int ref_idx = tile_list[n][i].reference_idx;
153 int tc = tile_list[n][i].tile_col;
154 int tr = tile_list[n][i].tile_row;
158 fseeko(infile, camera_frame_pos, SEEK_SET);
161 while (frame_cnt != image_idx) {
162 aom_video_reader_read_frame(reader);
166 frame = aom_video_reader_get_frame(reader, &frame_size);
176 ref.
img = reference_images[ref_idx];
178 die_codec(&codec,
"Failed to set reference frame.");
183 if (aom_status) die_codec(&codec,
"Failed to decode tile.");
187 aom_img_write(img, outfile);
191 for (i = 0; i < num_references; i++)
aom_img_free(&reference_images[i]);
193 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