35 #include "aom_scale/yv12config.h"
36 #include "av1/common/enums.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;
102 AvxVideoReader *reader = NULL;
103 const AvxInterface *decoder = NULL;
104 const AvxVideoInfo *info = NULL;
107 aom_image_t reference_images[MAX_EXTERNAL_REFERENCES];
108 size_t frame_size = 0;
109 const unsigned char *frame = NULL;
110 int output_format = YUV1D;
115 if (argc < 5) die(
"Invalid number of arguments.");
117 reader = aom_video_reader_open(argv[1]);
118 if (!reader) die(
"Failed to open %s for reading.", argv[1]);
120 if (!(outfile = fopen(argv[2],
"wb")))
121 die(
"Failed to open %s for writing.", argv[2]);
123 num_references = (int)strtol(argv[3], NULL, 0);
124 num_tile_lists = (int)strtol(argv[4], NULL, 0);
126 if (argc > 5) output_format = (int)strtol(argv[5], NULL, 0);
127 if (output_format < YUV1D || output_format > NV12)
128 die(
"Output format out of range [0, 2]");
130 info = aom_video_reader_get_info(reader);
132 decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
133 if (!decoder) die(
"Unknown input codec.");
137 die_codec(&codec,
"Failed to initialize decoder.");
141 die(
"Failed to set annex b status");
146 for (i = 0; i < num_references; ++i) {
147 aom_video_reader_read_frame(reader);
148 frame = aom_video_reader_get_frame(reader, &frame_size);
150 die_codec(&codec,
"Failed to decode frame.");
155 die_codec(&codec,
"Failed to get the image format");
159 die_codec(&codec,
"Failed to get the image frame size");
163 for (j = 0; j < num_references; j++) {
164 unsigned int border = AOM_DEC_BORDER_IN_PIXELS;
166 frame_res[0], frame_res[1], 32, 8,
168 die(
"Failed to allocate references.");
174 &reference_images[i]))
175 die_codec(&codec,
"Failed to copy decoded reference frame");
181 snprintf(name,
sizeof(name),
"ref_%d.yuv", i);
182 printf(
"writing ref image to %s, %d, %d\n", name, img->
d_w, img->
d_h);
183 FILE *ref_file = fopen(name,
"wb");
184 aom_img_write(img, ref_file);
196 aom_video_reader_read_frame(reader);
197 frame = aom_video_reader_get_frame(reader, &frame_size);
199 die_codec(&codec,
"Failed to decode the frame.");
201 for (n = 0; n < num_tile_lists; n++) {
202 aom_video_reader_read_frame(reader);
203 frame = aom_video_reader_get_frame(reader, &frame_size);
206 die_codec(&codec,
"Failed to decode the tile list.");
209 if (!img) die_codec(&codec,
"Failed to get frame.");
211 if (output_format == YUV1D)
213 write_tile_yuv1d(&codec, img, outfile);
214 else if (output_format == YUV)
215 aom_img_write(img, outfile);
218 aom_img_write_nv12(img, outfile);
221 for (i = 0; i < num_references; i++)
aom_img_free(&reference_images[i]);
223 aom_video_reader_close(reader);
Describes the decoder algorithm interface to applications.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
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.
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, int parameter.
Definition: aomdx.h:225
@ AV1D_GET_FRAME_SIZE
Codec control function to get the dimensions that the current frame is decoded at,...
Definition: aomdx.h:132
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition: aomdx.h:261
@ AV1D_GET_TILE_COUNT
Codec control function to get the tile count in a tile list, int* parameter.
Definition: aomdx.h:158
@ AV1D_GET_TILE_SIZE
Codec control function to get the size of the tile, unsigned int parameter.
Definition: aomdx.h:153
@ AV1D_GET_IMG_FORMAT
Codec control function to get the image format of the stream, aom_img_fmt_t* parameter.
Definition: aomdx.h:149
@ 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:243
@ AV1_COPY_NEW_FRAME_IMAGE
Definition: aom.h:61
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.
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition: aom_codec.h:426
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:209
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:219
Image Descriptor.
Definition: aom_image.h:171
unsigned int y_chroma_shift
Definition: aom_image.h:195
aom_img_fmt_t fmt
Definition: aom_image.h:172
int stride[3]
Definition: aom_image.h:203
unsigned int x_chroma_shift
Definition: aom_image.h:194
unsigned int d_w
Definition: aom_image.h:186
unsigned int d_h
Definition: aom_image.h:187
unsigned char * planes[3]
Definition: aom_image.h:202
Structure to hold the external reference frame pointer.
Definition: aomdx.h:96