35 #include "aom_scale/yv12config.h" 37 #include "common/tools_common.h" 38 #include "common/video_reader.h" 40 static const char *exec_name;
42 void usage_exit(
void) {
44 "Usage: %s <infile> <outfile> <num_references> <num_tile_lists> " 45 "<output format(optional)>\n",
53 unsigned int tile_size = 0;
55 die_codec(codec,
"Failed to get the tile size");
56 const unsigned int tile_width = tile_size >> 16;
57 const unsigned int tile_height = tile_size & 65535;
58 const uint32_t output_frame_width_in_tiles = img->
d_w / tile_width;
60 unsigned int tile_count = 0;
62 die_codec(codec,
"Failed to get the tile size");
66 unsigned int tile_idx;
68 for (tile_idx = 0; tile_idx < tile_count; ++tile_idx) {
69 const int row_offset =
70 (tile_idx / output_frame_width_in_tiles) * tile_height;
71 const int col_offset =
72 (tile_idx % output_frame_width_in_tiles) * tile_width;
75 for (plane = 0; plane < 3; ++plane) {
76 const unsigned char *buf = img->
planes[plane];
77 const int stride = img->
stride[plane];
82 const int w = (plane > 0) ? ((tile_width >> img->
x_chroma_shift) << shift)
83 : (tile_width << shift);
89 buf += roffset * stride + (coffset << shift);
91 for (y = 0; y < h; ++y) {
92 fwrite(buf, 1, w, file);
99 int main(
int argc,
char **argv) {
100 FILE *outfile = NULL;
101 AvxVideoReader *reader = NULL;
102 const AvxVideoInfo *info = NULL;
105 aom_image_t reference_images[MAX_EXTERNAL_REFERENCES];
106 size_t frame_size = 0;
107 const unsigned char *frame = NULL;
108 int output_format = YUV1D;
113 if (argc < 5) die(
"Invalid number of arguments.");
115 reader = aom_video_reader_open(argv[1]);
116 if (!reader) die(
"Failed to open %s for reading.", argv[1]);
118 if (!(outfile = fopen(argv[2],
"wb")))
119 die(
"Failed to open %s for writing.", argv[2]);
121 num_references = (int)strtol(argv[3], NULL, 0);
122 num_tile_lists = (int)strtol(argv[4], NULL, 0);
124 if (argc > 5) output_format = (int)strtol(argv[5], NULL, 0);
125 if (output_format < YUV1D || output_format > NV12)
126 die(
"Output format out of range [0, 2]");
128 info = aom_video_reader_get_info(reader);
131 if (!decoder) die(
"Unknown input codec.");
136 die(
"Failed to initialize decoder.");
140 die_codec(&codec,
"Failed to set annex b status");
145 for (i = 0; i < num_references; ++i) {
146 aom_video_reader_read_frame(reader);
147 frame = aom_video_reader_get_frame(reader, &frame_size);
149 die_codec(&codec,
"Failed to decode frame.");
154 die_codec(&codec,
"Failed to get the image format");
158 die_codec(&codec,
"Failed to get the image frame size");
162 for (j = 0; j < num_references; j++) {
163 unsigned int border = AOM_DEC_BORDER_IN_PIXELS;
165 frame_res[0], frame_res[1], 32, 8,
167 die(
"Failed to allocate references.");
173 &reference_images[i]))
174 die_codec(&codec,
"Failed to copy decoded reference frame");
180 snprintf(name,
sizeof(name),
"ref_%d.yuv", i);
181 printf(
"writing ref image to %s, %u, %u\n", name, img->
d_w, img->
d_h);
182 FILE *ref_file = fopen(name,
"wb");
183 aom_img_write(img, ref_file);
195 aom_video_reader_read_frame(reader);
196 frame = aom_video_reader_get_frame(reader, &frame_size);
198 die_codec(&codec,
"Failed to decode the frame.");
200 for (n = 0; n < num_tile_lists; n++) {
201 aom_video_reader_read_frame(reader);
202 frame = aom_video_reader_get_frame(reader, &frame_size);
205 die_codec(&codec,
"Failed to decode the tile list.");
208 if (!img) die_codec(&codec,
"Failed to get frame.");
210 if (output_format == YUV1D)
212 write_tile_yuv1d(&codec, img, outfile);
213 else if (output_format == YUV)
214 aom_img_write(img, outfile);
217 aom_img_write_nv12(img, outfile);
220 for (i = 0; i < num_references; i++)
aom_img_free(&reference_images[i]);
222 aom_video_reader_close(reader);
unsigned int d_h
Definition: aom_image.h:187
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition: aom_codec.h:520
aom_image_t * aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Decoded frames iterator.
Codec control function to get the tile count in a tile list, int* parameter.
Definition: aomdx.h:242
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
unsigned char * planes[3]
Definition: aom_image.h:202
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter...
Definition: aomdx.h:345
Codec context structure.
Definition: aom_codec.h:298
Codec control function to get the size of the tile, unsigned int parameter.
Definition: aomdx.h:237
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
unsigned int y_chroma_shift
Definition: aom_image.h:195
Describes the decoder algorithm interface to applications.
Codec control function to set the external references' pointers in the decoder, av1_ext_ref_frame_t* ...
Definition: aomdx.h:327
Codec control function to get the dimensions that the current frame is decoded at, int* parameter. This may be different to the intended display size for the frame as specified in the wrapper or frame header (see AV1D_GET_DISPLAY_SIZE).
Definition: aomdx.h:216
Image Descriptor.
Definition: aom_image.h:171
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.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition: aom_codec.h:254
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition: aom_decoder.h:129
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.
Codec control function to get the image format of the stream, aom_img_fmt_t* parameter.
Definition: aomdx.h:233
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Codec control function to copy the new frame to an external buffer.
Definition: aom.h:76
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:288
unsigned int x_chroma_shift
Definition: aom_image.h:194
Codec control function to set the tile coding mode, int parameter.
Definition: aomdx.h:309
Structure to hold the external reference frame pointer.
Definition: aomdx.h:179
Provides definitions for using AOM or AV1 within the aom Decoder interface.
int stride[3]
Definition: aom_image.h:203
unsigned int d_w
Definition: aom_image.h:186
aom_img_fmt_t fmt
Definition: aom_image.h:172