35#include "aom_scale/yv12config.h"
37#include "common/tools_common.h"
38#include "common/video_reader.h"
44} UENUM1BYTE(OUTPUT_FORMAT);
46static const char *exec_name;
48void usage_exit(
void) {
50 "Usage: %s <infile> <outfile> <num_references> <num_tile_lists> "
51 "<output format(optional)>\n",
59 unsigned int tile_size = 0;
61 die_codec(codec,
"Failed to get the tile size");
62 const unsigned int tile_width = tile_size >> 16;
63 const unsigned int tile_height = tile_size & 65535;
64 const uint32_t output_frame_width_in_tiles = img->
d_w / tile_width;
66 unsigned int tile_count = 0;
68 die_codec(codec,
"Failed to get the tile size");
72 unsigned int tile_idx;
74 for (tile_idx = 0; tile_idx < tile_count; ++tile_idx) {
75 const int row_offset =
76 (tile_idx / output_frame_width_in_tiles) * tile_height;
77 const int col_offset =
78 (tile_idx % output_frame_width_in_tiles) * tile_width;
81 for (plane = 0; plane < 3; ++plane) {
82 const unsigned char *buf = img->
planes[plane];
83 const int stride = img->
stride[plane];
88 const int w = (plane > 0) ? ((tile_width >> img->
x_chroma_shift) << shift)
89 : (tile_width << shift);
95 buf += roffset * stride + (coffset << shift);
97 for (y = 0; y < h; ++y) {
98 fwrite(buf, 1, w, file);
105int main(
int argc,
char **argv) {
106 FILE *outfile = NULL;
107 AvxVideoReader *reader = NULL;
108 const AvxVideoInfo *info = NULL;
111 aom_image_t reference_images[MAX_EXTERNAL_REFERENCES];
112 size_t frame_size = 0;
113 const unsigned char *frame = NULL;
114 int output_format = YUV1D;
119 if (argc < 5) die(
"Invalid number of arguments.");
121 reader = aom_video_reader_open(argv[1]);
122 if (!reader) die(
"Failed to open %s for reading.", argv[1]);
124 if (!(outfile = fopen(argv[2],
"wb")))
125 die(
"Failed to open %s for writing.", argv[2]);
127 num_references = (int)strtol(argv[3], NULL, 0);
128 num_tile_lists = (int)strtol(argv[4], NULL, 0);
130 if (argc > 5) output_format = (int)strtol(argv[5], NULL, 0);
131 if (output_format < YUV1D || output_format > NV12)
132 die(
"Output format out of range [0, 2]");
134 info = aom_video_reader_get_info(reader);
137 if (!decoder) die(
"Unknown input codec.");
142 die(
"Failed to initialize decoder.");
146 die_codec(&codec,
"Failed to set annex b status");
151 for (i = 0; i < num_references; ++i) {
152 aom_video_reader_read_frame(reader);
153 frame = aom_video_reader_get_frame(reader, &frame_size);
155 die_codec(&codec,
"Failed to decode frame.");
160 die_codec(&codec,
"Failed to get the image format");
164 die_codec(&codec,
"Failed to get the image frame size");
168 for (j = 0; j < num_references; j++) {
169 unsigned int border = AOM_DEC_BORDER_IN_PIXELS;
171 frame_res[0], frame_res[1], 32, 8,
173 fatal(
"Failed to allocate references.");
179 &reference_images[i]))
180 die_codec(&codec,
"Failed to copy decoded reference frame");
186 snprintf(name,
sizeof(name),
"ref_%d.yuv", i);
187 printf(
"writing ref image to %s, %u, %u\n", name, img->
d_w, img->
d_h);
188 FILE *ref_file = fopen(name,
"wb");
189 aom_img_write(img, ref_file);
201 aom_video_reader_read_frame(reader);
202 frame = aom_video_reader_get_frame(reader, &frame_size);
204 die_codec(&codec,
"Failed to decode the frame.");
206 for (n = 0; n < num_tile_lists; n++) {
207 aom_video_reader_read_frame(reader);
208 frame = aom_video_reader_get_frame(reader, &frame_size);
211 die_codec(&codec,
"Failed to decode the tile list.");
214 if (!img) die_codec(&codec,
"Failed to get frame.");
216 if (output_format == YUV1D)
218 write_tile_yuv1d(&codec, img, outfile);
219 else if (output_format == YUV)
220 aom_img_write(img, outfile);
223 aom_img_write_nv12(img, outfile);
226 for (i = 0; i < num_references; i++)
aom_img_free(&reference_images[i]);
228 aom_video_reader_close(reader);
Describes the decoder algorithm interface to applications.
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.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition aom_image.h:38
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Provides definitions for using AOM or AV1 within the aom Decoder interface.
@ AV1_SET_TILE_MODE
Codec control function to set the tile coding mode, unsigned int parameter.
Definition aomdx.h:316
@ AV1D_GET_FRAME_SIZE
Codec control function to get the dimensions that the current frame is decoded at,...
Definition aomdx.h:217
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition aomdx.h:352
@ AV1D_GET_TILE_COUNT
Codec control function to get the tile count in a tile list, unsigned int* parameter.
Definition aomdx.h:248
@ AV1D_GET_TILE_SIZE
Codec control function to get the width and height (in pixels) of the tiles in a tile list,...
Definition aomdx.h:243
@ AV1D_GET_IMG_FORMAT
Codec control function to get the image format of the stream, aom_img_fmt_t* parameter.
Definition aomdx.h:235
@ AV1D_SET_EXT_REF_PTR
Codec control function to set the external references' pointers in the decoder, av1_ext_ref_frame_t* ...
Definition aomdx.h:334
@ AV1_COPY_NEW_FRAME_IMAGE
Codec control function to copy the new frame to an external buffer.
Definition aom.h:76
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:271
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition aom_codec.h:542
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:305
aom_image_t * aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Decoded frames iterator.
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.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition aom_decoder.h:129
Codec context structure.
Definition aom_codec.h:315
Image Descriptor.
Definition aom_image.h:182
unsigned int y_chroma_shift
Definition aom_image.h:206
aom_img_fmt_t fmt
Definition aom_image.h:183
int stride[3]
Definition aom_image.h:216
unsigned int x_chroma_shift
Definition aom_image.h:205
unsigned int d_w
Definition aom_image.h:197
unsigned int d_h
Definition aom_image.h:198
unsigned char * planes[3]
Definition aom_image.h:215
Structure to hold the external reference frame pointer.
Definition aomdx.h:179