diff options
author | trav90 <travawine@palemoon.org> | 2018-10-19 21:52:15 -0500 |
---|---|---|
committer | trav90 <travawine@palemoon.org> | 2018-10-19 21:52:20 -0500 |
commit | bbcc64772580c8a979288791afa02d30bc476d2e (patch) | |
tree | 437ce94c3fdd7497508e5b55de06c6d011678597 /third_party/aom/examples/lightfield_encoder.c | |
parent | 14805f6ddbfb173c327768fff9f81f40ce5e81b0 (diff) | |
download | UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.gz UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.lz UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.xz UXP-bbcc64772580c8a979288791afa02d30bc476d2e.zip |
Update aom to v1.0.0
Update aom to commit id d14c5bb4f336ef1842046089849dee4a301fbbf0.
Diffstat (limited to 'third_party/aom/examples/lightfield_encoder.c')
-rw-r--r-- | third_party/aom/examples/lightfield_encoder.c | 323 |
1 files changed, 172 insertions, 151 deletions
diff --git a/third_party/aom/examples/lightfield_encoder.c b/third_party/aom/examples/lightfield_encoder.c index 0a424db8c..22daf622c 100644 --- a/third_party/aom/examples/lightfield_encoder.c +++ b/third_party/aom/examples/lightfield_encoder.c @@ -24,7 +24,12 @@ // image for MCP. // Run "make test" to download lightfield test data: vase10x10.yuv. // Run lightfield encoder to encode whole lightfield: -// examples/lightfield_encoder 1024 1024 vase10x10.yuv vase10x10.webm 10 10 5 +// examples/lightfield_encoder 1024 1024 vase10x10.yuv vase10x10.ivf 10 10 5 + +// Note: In bitstream.c and encoder.c, define EXT_TILE_DEBUG as 1 will print +// out the uncompressed header and the frame contexts, which can be used to +// test the bit exactness of the headers and the frame contexts for large scale +// tile coded frames. #include <stdio.h> #include <stdlib.h> @@ -34,11 +39,13 @@ #include "aom/aomcx.h" #include "av1/common/enums.h" -#include "../tools_common.h" -#include "../video_writer.h" +#include "common/tools_common.h" +#include "common/video_writer.h" + +#define MAX_EXTERNAL_REFERENCES 128 +#define AOM_BORDER_IN_PIXELS 288 static const char *exec_name; -static const unsigned int deadline = AOM_DL_GOOD_QUALITY; void usage_exit(void) { fprintf(stderr, @@ -48,52 +55,26 @@ void usage_exit(void) { exit(EXIT_FAILURE); } -static aom_image_t *aom_img_copy(aom_image_t *src, aom_image_t *dst) { - dst = aom_img_alloc(dst, src->fmt, src->d_w, src->d_h, 16); - - int plane; - - for (plane = 0; plane < 3; ++plane) { - unsigned char *src_buf = src->planes[plane]; - const int src_stride = src->stride[plane]; - const int src_w = plane == 0 ? src->d_w : src->d_w >> 1; - const int src_h = plane == 0 ? src->d_h : src->d_h >> 1; - - unsigned char *dst_buf = dst->planes[plane]; - const int dst_stride = dst->stride[plane]; - int y; - - for (y = 0; y < src_h; ++y) { - memcpy(dst_buf, src_buf, src_w); - src_buf += src_stride; - dst_buf += dst_stride; - } - } - return dst; -} - static int aom_img_size_bytes(aom_image_t *img) { int image_size_bytes = 0; int plane; for (plane = 0; plane < 3; ++plane) { - const int stride = img->stride[plane]; const int w = aom_img_plane_width(img, plane) * ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); const int h = aom_img_plane_height(img, plane); - image_size_bytes += (w + stride) * h; + image_size_bytes += w * h; } return image_size_bytes; } static int get_frame_stats(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned int duration, - aom_enc_frame_flags_t flags, unsigned int dl, + aom_enc_frame_flags_t flags, aom_fixed_buf_t *stats) { int got_pkts = 0; aom_codec_iter_t iter = NULL; const aom_codec_cx_pkt_t *pkt = NULL; - const aom_codec_err_t res = - aom_codec_encode(ctx, img, pts, duration, flags, dl); + const aom_codec_err_t res = aom_codec_encode(ctx, img, pts, duration, flags); if (res != AOM_CODEC_OK) die_codec(ctx, "Failed to get frame stats."); while ((pkt = aom_codec_get_cx_data(ctx, &iter)) != NULL) { @@ -113,13 +94,11 @@ static int get_frame_stats(aom_codec_ctx_t *ctx, const aom_image_t *img, static int encode_frame(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned int duration, - aom_enc_frame_flags_t flags, unsigned int dl, - AvxVideoWriter *writer) { + aom_enc_frame_flags_t flags, AvxVideoWriter *writer) { int got_pkts = 0; aom_codec_iter_t iter = NULL; const aom_codec_cx_pkt_t *pkt = NULL; - const aom_codec_err_t res = - aom_codec_encode(ctx, img, pts, duration, flags, dl); + const aom_codec_err_t res = aom_codec_encode(ctx, img, pts, duration, flags); if (res != AOM_CODEC_OK) die_codec(ctx, "Failed to encode frame."); while ((pkt = aom_codec_get_cx_data(ctx, &iter)) != NULL) { @@ -139,33 +118,44 @@ static int encode_frame(aom_codec_ctx_t *ctx, const aom_image_t *img, return got_pkts; } +static void get_raw_image(aom_image_t **frame_to_encode, aom_image_t *raw, + aom_image_t *raw_shift) { + if (!CONFIG_LOWBITDEPTH) { + // Need to allocate larger buffer to use hbd internal. + int input_shift = 0; + aom_img_upshift(raw_shift, raw, input_shift); + *frame_to_encode = raw_shift; + } else { + *frame_to_encode = raw; + } +} + static aom_fixed_buf_t pass0(aom_image_t *raw, FILE *infile, const AvxInterface *encoder, const aom_codec_enc_cfg_t *cfg, int lf_width, - int lf_height, int lf_blocksize) { + int lf_height, int lf_blocksize, int flags, + aom_image_t *raw_shift) { aom_codec_ctx_t codec; int frame_count = 0; - int image_size_bytes = 0; + int image_size_bytes = aom_img_size_bytes(raw); int u_blocks, v_blocks; int bu, bv; aom_fixed_buf_t stats = { NULL, 0 }; + aom_image_t *frame_to_encode; - if (aom_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0)) + if (aom_codec_enc_init(&codec, encoder->codec_interface(), cfg, flags)) die_codec(&codec, "Failed to initialize encoder"); - if (aom_codec_control(&codec, AV1E_SET_FRAME_PARALLEL_DECODING, 1)) - die_codec(&codec, "Failed to set frame parallel decoding"); if (aom_codec_control(&codec, AOME_SET_ENABLEAUTOALTREF, 0)) die_codec(&codec, "Failed to turn off auto altref"); - if (aom_codec_control(&codec, AV1E_SET_SINGLE_TILE_DECODING, 1)) - die_codec(&codec, "Failed to turn on single tile decoding"); - - image_size_bytes = aom_img_size_bytes(raw); + if (aom_codec_control(&codec, AV1E_SET_FRAME_PARALLEL_DECODING, 0)) + die_codec(&codec, "Failed to set frame parallel decoding"); // How many reference images we need to encode. u_blocks = (lf_width + lf_blocksize - 1) / lf_blocksize; v_blocks = (lf_height + lf_blocksize - 1) / lf_blocksize; - aom_image_t *reference_images = - (aom_image_t *)malloc(u_blocks * v_blocks * sizeof(aom_image_t)); + + printf("\n First pass: "); + for (bv = 0; bv < v_blocks; ++bv) { for (bu = 0; bu < u_blocks; ++bu) { const int block_u_min = bu * lf_blocksize; @@ -174,7 +164,6 @@ static aom_fixed_buf_t pass0(aom_image_t *raw, FILE *infile, int block_v_end = (bv + 1) * lf_blocksize; int u_block_size, v_block_size; int block_ref_u, block_ref_v; - struct av1_ref_frame ref_frame; block_u_end = block_u_end < lf_width ? block_u_end : lf_width; block_v_end = block_v_end < lf_height ? block_v_end : lf_height; @@ -182,22 +171,28 @@ static aom_fixed_buf_t pass0(aom_image_t *raw, FILE *infile, v_block_size = block_v_end - block_v_min; block_ref_u = block_u_min + u_block_size / 2; block_ref_v = block_v_min + v_block_size / 2; + + printf("A%d, ", (block_ref_u + block_ref_v * lf_width)); fseek(infile, (block_ref_u + block_ref_v * lf_width) * image_size_bytes, SEEK_SET); aom_img_read(raw, infile); - if (aom_codec_control(&codec, AOME_USE_REFERENCE, - AOM_LAST_FLAG | AOM_GOLD_FLAG | AOM_ALT_FLAG)) - die_codec(&codec, "Failed to set reference flags"); + get_raw_image(&frame_to_encode, raw, raw_shift); + // Reference frames can be encoded encoded without tiles. ++frame_count; - get_frame_stats(&codec, raw, frame_count, 1, - AOM_EFLAG_FORCE_GF | AOM_EFLAG_NO_UPD_ENTROPY, deadline, + get_frame_stats(&codec, frame_to_encode, frame_count, 1, + AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | + AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | + AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 | + AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | + AOM_EFLAG_NO_UPD_ARF, &stats); - ref_frame.idx = 0; - aom_codec_control(&codec, AV1_GET_REFERENCE, &ref_frame); - aom_img_copy(&ref_frame.img, &reference_images[frame_count - 1]); } } + + if (aom_codec_control(&codec, AV1E_SET_FRAME_PARALLEL_DECODING, 1)) + die_codec(&codec, "Failed to set frame parallel decoding"); + for (bv = 0; bv < v_blocks; ++bv) { for (bu = 0; bu < u_blocks; ++bu) { const int block_u_min = bu * lf_blocksize; @@ -209,58 +204,39 @@ static aom_fixed_buf_t pass0(aom_image_t *raw, FILE *infile, block_v_end = block_v_end < lf_height ? block_v_end : lf_height; for (v = block_v_min; v < block_v_end; ++v) { for (u = block_u_min; u < block_u_end; ++u) { - // This was a work around for a bug in libvpx. I'm not sure if this - // same bug exists in current version of av1. Need to call this, - // otherwise the default is to not use any reference frames. Then - // if you don't have at least one AOM_EFLAG_NO_REF_* flag, all frames - // will be intra encoded. I'm not sure why the default is not to use - // any reference frames. It looks like there is something about the - // way I encode the reference frames above that sets that as - // default... - if (aom_codec_control(&codec, AOME_USE_REFERENCE, - AOM_LAST_FLAG | AOM_GOLD_FLAG | AOM_ALT_FLAG)) - die_codec(&codec, "Failed to set reference flags"); - - // Set tile size to 64 pixels. The tile_columns and - // tile_rows in the tile coding are overloaded to represent - // tile_width and tile_height, that range from 1 to 64, in the unit - // of 64 pixels. - if (aom_codec_control(&codec, AV1E_SET_TILE_COLUMNS, 1)) - die_codec(&codec, "Failed to set tile width"); - if (aom_codec_control(&codec, AV1E_SET_TILE_ROWS, 1)) - die_codec(&codec, "Failed to set tile height"); - - av1_ref_frame_t ref; - ref.idx = 0; - ref.img = reference_images[bv * u_blocks + bu]; - if (aom_codec_control(&codec, AV1_SET_REFERENCE, &ref)) - die_codec(&codec, "Failed to set reference frame"); - + printf("C%d, ", (u + v * lf_width)); fseek(infile, (u + v * lf_width) * image_size_bytes, SEEK_SET); aom_img_read(raw, infile); + get_raw_image(&frame_to_encode, raw, raw_shift); + ++frame_count; - get_frame_stats(&codec, raw, frame_count, 1, - AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | - AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_UPD_ENTROPY | - AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF, - deadline, &stats); + get_frame_stats(&codec, frame_to_encode, frame_count, 1, + AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | + AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | + AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 | + AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | + AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_UPD_ENTROPY, + &stats); } } } } // Flush encoder. - while (get_frame_stats(&codec, NULL, frame_count, 1, 0, deadline, &stats)) { + // No ARF, this should not be needed. + while (get_frame_stats(&codec, NULL, frame_count, 1, 0, &stats)) { } - printf("Pass 0 complete. Processed %d frames.\n", frame_count); if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); + printf("\nFirst pass complete. Processed %d frames.\n", frame_count); + return stats; } static void pass1(aom_image_t *raw, FILE *infile, const char *outfile_name, - const AvxInterface *encoder, const aom_codec_enc_cfg_t *cfg, - int lf_width, int lf_height, int lf_blocksize) { + const AvxInterface *encoder, aom_codec_enc_cfg_t *cfg, + int lf_width, int lf_height, int lf_blocksize, int flags, + aom_image_t *raw_shift) { AvxVideoInfo info = { encoder->fourcc, cfg->g_w, cfg->g_h, @@ -268,27 +244,48 @@ static void pass1(aom_image_t *raw, FILE *infile, const char *outfile_name, AvxVideoWriter *writer = NULL; aom_codec_ctx_t codec; int frame_count = 0; - int image_size_bytes; + int image_size_bytes = aom_img_size_bytes(raw); int bu, bv; int u_blocks, v_blocks; + aom_image_t *frame_to_encode; + aom_image_t reference_images[MAX_EXTERNAL_REFERENCES]; + int reference_image_num = 0; + int i; writer = aom_video_writer_open(outfile_name, kContainerIVF, &info); if (!writer) die("Failed to open %s for writing", outfile_name); - if (aom_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0)) + if (aom_codec_enc_init(&codec, encoder->codec_interface(), cfg, flags)) die_codec(&codec, "Failed to initialize encoder"); - if (aom_codec_control(&codec, AV1E_SET_FRAME_PARALLEL_DECODING, 1)) - die_codec(&codec, "Failed to set frame parallel decoding"); if (aom_codec_control(&codec, AOME_SET_ENABLEAUTOALTREF, 0)) die_codec(&codec, "Failed to turn off auto altref"); - if (aom_codec_control(&codec, AV1E_SET_SINGLE_TILE_DECODING, 1)) - die_codec(&codec, "Failed to turn on single tile decoding"); + if (aom_codec_control(&codec, AV1E_SET_FRAME_PARALLEL_DECODING, 0)) + die_codec(&codec, "Failed to set frame parallel decoding"); + // Note: The superblock is a sequence parameter and has to be the same for 1 + // sequence. In lightfield application, must choose the superblock size(either + // 64x64 or 128x128) before the encoding starts. Otherwise, the default is + // AOM_SUPERBLOCK_SIZE_DYNAMIC, and the superblock size will be set to 64x64 + // internally. + if (aom_codec_control(&codec, AV1E_SET_SUPERBLOCK_SIZE, + AOM_SUPERBLOCK_SIZE_64X64)) + die_codec(&codec, "Failed to set SB size"); - image_size_bytes = aom_img_size_bytes(raw); u_blocks = (lf_width + lf_blocksize - 1) / lf_blocksize; v_blocks = (lf_height + lf_blocksize - 1) / lf_blocksize; - aom_image_t *reference_images = - (aom_image_t *)malloc(u_blocks * v_blocks * sizeof(aom_image_t)); + + reference_image_num = u_blocks * v_blocks; + aom_img_fmt_t ref_fmt = AOM_IMG_FMT_I420; + if (!CONFIG_LOWBITDEPTH) ref_fmt |= AOM_IMG_FMT_HIGHBITDEPTH; + // Allocate memory with the border so that it can be used as a reference. + for (i = 0; i < reference_image_num; i++) { + if (!aom_img_alloc_with_border(&reference_images[i], ref_fmt, cfg->g_w, + cfg->g_h, 32, 8, AOM_BORDER_IN_PIXELS)) { + die("Failed to allocate image."); + } + } + + printf("\n Second pass: "); + // Encode reference images first. printf("Encoding Reference Images\n"); for (bv = 0; bv < v_blocks; ++bv) { @@ -299,7 +296,6 @@ static void pass1(aom_image_t *raw, FILE *infile, const char *outfile_name, int block_v_end = (bv + 1) * lf_blocksize; int u_block_size, v_block_size; int block_ref_u, block_ref_v; - struct av1_ref_frame ref_frame; block_u_end = block_u_end < lf_width ? block_u_end : lf_width; block_v_end = block_v_end < lf_height ? block_v_end : lf_height; @@ -307,25 +303,52 @@ static void pass1(aom_image_t *raw, FILE *infile, const char *outfile_name, v_block_size = block_v_end - block_v_min; block_ref_u = block_u_min + u_block_size / 2; block_ref_v = block_v_min + v_block_size / 2; + + printf("A%d, ", (block_ref_u + block_ref_v * lf_width)); fseek(infile, (block_ref_u + block_ref_v * lf_width) * image_size_bytes, SEEK_SET); aom_img_read(raw, infile); - if (aom_codec_control(&codec, AOME_USE_REFERENCE, - AOM_LAST_FLAG | AOM_GOLD_FLAG | AOM_ALT_FLAG)) - die_codec(&codec, "Failed to set reference flags"); + + get_raw_image(&frame_to_encode, raw, raw_shift); + // Reference frames may be encoded without tiles. ++frame_count; printf("Encoding reference image %d of %d\n", bv * u_blocks + bu, u_blocks * v_blocks); - encode_frame(&codec, raw, frame_count, 1, - AOM_EFLAG_FORCE_GF | AOM_EFLAG_NO_UPD_ENTROPY, deadline, + encode_frame(&codec, frame_to_encode, frame_count, 1, + AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | + AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | + AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 | + AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | + AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_UPD_ENTROPY, writer); - ref_frame.idx = 0; - aom_codec_control(&codec, AV1_GET_REFERENCE, &ref_frame); - aom_img_copy(&ref_frame.img, &reference_images[frame_count - 1]); + + if (aom_codec_control(&codec, AV1_COPY_NEW_FRAME_IMAGE, + &reference_images[frame_count - 1])) + die_codec(&codec, "Failed to copy decoder reference frame"); } } + cfg->large_scale_tile = 1; + // Fixed q encoding for camera frames. + cfg->rc_end_usage = AOM_Q; + if (aom_codec_enc_config_set(&codec, cfg)) + die_codec(&codec, "Failed to configure encoder"); + + // The fixed q value used in encoding. + if (aom_codec_control(&codec, AOME_SET_CQ_LEVEL, 36)) + die_codec(&codec, "Failed to set cq level"); + if (aom_codec_control(&codec, AV1E_SET_FRAME_PARALLEL_DECODING, 1)) + die_codec(&codec, "Failed to set frame parallel decoding"); + if (aom_codec_control(&codec, AV1E_SET_SINGLE_TILE_DECODING, 1)) + die_codec(&codec, "Failed to turn on single tile decoding"); + // Set tile_columns and tile_rows to MAX values, which guarantees the tile + // size of 64 x 64 pixels(i.e. 1 SB) for <= 4k resolution. + if (aom_codec_control(&codec, AV1E_SET_TILE_COLUMNS, 6)) + die_codec(&codec, "Failed to set tile width"); + if (aom_codec_control(&codec, AV1E_SET_TILE_ROWS, 6)) + die_codec(&codec, "Failed to set tile height"); + for (bv = 0; bv < v_blocks; ++bv) { for (bu = 0; bu < u_blocks; ++bu) { const int block_u_min = bu * lf_blocksize; @@ -337,56 +360,44 @@ static void pass1(aom_image_t *raw, FILE *infile, const char *outfile_name, block_v_end = block_v_end < lf_height ? block_v_end : lf_height; for (v = block_v_min; v < block_v_end; ++v) { for (u = block_u_min; u < block_u_end; ++u) { - // This was a work around for a bug in libvpx. I'm not sure if this - // same bug exists in current version of av1. Need to call this, - // otherwise the default is to not use any reference frames. Then - // if you don't have at least one AOM_EFLAG_NO_REF_* flag, all frames - // will be intra encoded. I'm not sure why the default is not to use - // any reference frames. It looks like there is something about the - // way I encode the reference frames above that sets that as - // default... - if (aom_codec_control(&codec, AOME_USE_REFERENCE, - AOM_LAST_FLAG | AOM_GOLD_FLAG | AOM_ALT_FLAG)) - die_codec(&codec, "Failed to set reference flags"); - - // Set tile size to 64 pixels. The tile_columns and - // tile_rows in the tile coding are overloaded to represent tile_width - // and tile_height, that range from 1 to 64, in the unit of 64 pixels. - if (aom_codec_control(&codec, AV1E_SET_TILE_COLUMNS, 1)) - die_codec(&codec, "Failed to set tile width"); - if (aom_codec_control(&codec, AV1E_SET_TILE_ROWS, 1)) - die_codec(&codec, "Failed to set tile height"); - av1_ref_frame_t ref; ref.idx = 0; + ref.use_external_ref = 1; ref.img = reference_images[bv * u_blocks + bu]; if (aom_codec_control(&codec, AV1_SET_REFERENCE, &ref)) die_codec(&codec, "Failed to set reference frame"); + + printf("C%d, ", (u + v * lf_width)); fseek(infile, (u + v * lf_width) * image_size_bytes, SEEK_SET); aom_img_read(raw, infile); - ++frame_count; + get_raw_image(&frame_to_encode, raw, raw_shift); + ++frame_count; printf("Encoding image %d of %d\n", frame_count - (u_blocks * v_blocks), lf_width * lf_height); - encode_frame(&codec, raw, frame_count, 1, - AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | - AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_UPD_ENTROPY | - AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF, - deadline, writer); + encode_frame(&codec, frame_to_encode, frame_count, 1, + AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | + AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | + AOM_EFLAG_NO_REF_BWD | AOM_EFLAG_NO_REF_ARF2 | + AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | + AOM_EFLAG_NO_UPD_ARF | AOM_EFLAG_NO_UPD_ENTROPY, + writer); } } } } // Flush encoder. - while (encode_frame(&codec, NULL, -1, 1, 0, deadline, writer)) { + // No ARF, this should not be needed. + while (encode_frame(&codec, NULL, -1, 1, 0, writer)) { } - if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); + for (i = 0; i < reference_image_num; i++) aom_img_free(&reference_images[i]); + if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec."); aom_video_writer_close(writer); - printf("Pass 1 complete. Processed %d frames.\n", frame_count); + printf("\nSecond pass complete. Processed %d frames.\n", frame_count); } int main(int argc, char **argv) { @@ -401,8 +412,10 @@ int main(int argc, char **argv) { aom_codec_ctx_t codec; aom_codec_enc_cfg_t cfg; aom_image_t raw; + aom_image_t raw_shift; aom_codec_err_t res; aom_fixed_buf_t stats; + int flags = 0; const AvxInterface *encoder = NULL; const int fps = 30; @@ -435,14 +448,19 @@ int main(int argc, char **argv) { die("Invalid lf_width and/or lf_height: %dx%d", lf_width, lf_height); if (lf_blocksize <= 0) die("Invalid lf_blocksize: %d", lf_blocksize); - if (!aom_img_alloc(&raw, AOM_IMG_FMT_I420, w, h, 1)) - die("Failed to allocate image", w, h); + if (!aom_img_alloc(&raw, AOM_IMG_FMT_I420, w, h, 32)) { + die("Failed to allocate image."); + } + if (!CONFIG_LOWBITDEPTH) { + // Need to allocate larger buffer to use hbd internal. + aom_img_alloc(&raw_shift, AOM_IMG_FMT_I420 | AOM_IMG_FMT_HIGHBITDEPTH, w, h, + 32); + } printf("Using %s\n", aom_codec_iface_name(encoder->codec_interface())); // Configuration res = aom_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); - if (res) die_codec(&codec, "Failed to get default codec config."); cfg.g_w = w; @@ -450,29 +468,32 @@ int main(int argc, char **argv) { cfg.g_timebase.num = 1; cfg.g_timebase.den = fps; cfg.rc_target_bitrate = bitrate; - cfg.g_error_resilient = AOM_ERROR_RESILIENT_DEFAULT; - // Need to set lag_in_frames to 1 or 0. Otherwise the frame flags get - // overridden after the first frame in encode_frame_to_data_rate() (see where - // get_frame_flags() is called). - cfg.g_lag_in_frames = 0; + cfg.g_error_resilient = 0; // This is required. + cfg.g_lag_in_frames = 0; // need to set this since default is 19. cfg.kf_mode = AOM_KF_DISABLED; - cfg.large_scale_tile = 1; + cfg.large_scale_tile = 0; // Only set it to 1 for camera frame encoding. + cfg.g_bit_depth = AOM_BITS_8; + flags |= (cfg.g_bit_depth > AOM_BITS_8 || !CONFIG_LOWBITDEPTH) + ? AOM_CODEC_USE_HIGHBITDEPTH + : 0; if (!(infile = fopen(infile_arg, "rb"))) die("Failed to open %s for reading", infile_arg); // Pass 0 cfg.g_pass = AOM_RC_FIRST_PASS; - stats = pass0(&raw, infile, encoder, &cfg, lf_width, lf_height, lf_blocksize); + stats = pass0(&raw, infile, encoder, &cfg, lf_width, lf_height, lf_blocksize, + flags, &raw_shift); // Pass 1 rewind(infile); cfg.g_pass = AOM_RC_LAST_PASS; cfg.rc_twopass_stats_in = stats; pass1(&raw, infile, outfile_arg, encoder, &cfg, lf_width, lf_height, - lf_blocksize); + lf_blocksize, flags, &raw_shift); free(stats.buf); + if (!CONFIG_LOWBITDEPTH) aom_img_free(&raw_shift); aom_img_free(&raw); fclose(infile); |