ref: ef4554092702629d4a6d5144935fbdab3b49518a
parent: c69cc4ce1f384827d0a0aef349b9c6396b07014f
author: clang-format <[email protected]>
date: Mon Jul 18 15:04:56 EDT 2016
examples: apply clang-format Change-Id: Icc3bbb07c99a31a70030baec7e51b881902a7b5e
--- a/examples/decode_to_md5.c
+++ b/examples/decode_to_md5.c
@@ -65,8 +65,7 @@
static void print_md5(FILE *stream, unsigned char digest[16]) {
int i;
- for (i = 0; i < 16; ++i)
- fprintf(stream, "%02x", digest[i]);
+ for (i = 0; i < 16; ++i) fprintf(stream, "%02x", digest[i]);
}
static const char *exec_name;
@@ -86,12 +85,10 @@
exec_name = argv[0];
- if (argc != 3)
- die("Invalid number of arguments.");
+ if (argc != 3) die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]);
- if (!reader)
- die("Failed to open %s for reading.", argv[1]);
+ if (!reader) die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing.", argv[2]);
@@ -99,8 +96,7 @@
info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
- if (!decoder)
- die("Unknown input codec.");
+ if (!decoder) die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@@ -111,8 +107,8 @@
vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL;
size_t frame_size = 0;
- const unsigned char *frame = vpx_video_reader_get_frame(reader,
- &frame_size);
+ const unsigned char *frame =
+ vpx_video_reader_get_frame(reader, &frame_size);
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
die_codec(&codec, "Failed to decode frame");
@@ -121,14 +117,13 @@
get_image_md5(img, digest);
print_md5(outfile, digest);
- fprintf(outfile, " img-%dx%d-%04d.i420\n",
- img->d_w, img->d_h, ++frame_cnt);
+ fprintf(outfile, " img-%dx%d-%04d.i420\n", img->d_w, img->d_h,
+ ++frame_cnt);
}
}
printf("Processed %d frames.\n", frame_cnt);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
vpx_video_reader_close(reader);
--- a/examples/decode_with_drops.c
+++ b/examples/decode_with_drops.c
@@ -84,12 +84,10 @@
exec_name = argv[0];
- if (argc != 4)
- die("Invalid number of arguments.");
+ if (argc != 4) die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]);
- if (!reader)
- die("Failed to open %s for reading.", argv[1]);
+ if (!reader) die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing.", argv[2]);
@@ -103,8 +101,7 @@
info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
- if (!decoder)
- die("Unknown input codec.");
+ if (!decoder) die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@@ -116,8 +113,8 @@
vpx_image_t *img = NULL;
size_t frame_size = 0;
int skip;
- const unsigned char *frame = vpx_video_reader_get_frame(reader,
- &frame_size);
+ const unsigned char *frame =
+ vpx_video_reader_get_frame(reader, &frame_size);
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
die_codec(&codec, "Failed to decode frame.");
@@ -139,8 +136,7 @@
}
printf("Processed %d frames.\n", frame_cnt);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
info->frame_width, info->frame_height, argv[2]);
--- a/examples/postproc.c
+++ b/examples/postproc.c
@@ -68,12 +68,10 @@
exec_name = argv[0];
- if (argc != 3)
- die("Invalid number of arguments.");
+ if (argc != 3) die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]);
- if (!reader)
- die("Failed to open %s for reading.", argv[1]);
+ if (!reader) die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing", argv[2]);
@@ -81,8 +79,7 @@
info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
- if (!decoder)
- die("Unknown input codec.");
+ if (!decoder) die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@@ -91,26 +88,25 @@
if (res == VPX_CODEC_INCAPABLE)
die_codec(&codec, "Postproc not supported by this decoder.");
- if (res)
- die_codec(&codec, "Failed to initialize decoder.");
+ if (res) die_codec(&codec, "Failed to initialize decoder.");
while (vpx_video_reader_read_frame(reader)) {
vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL;
size_t frame_size = 0;
- const unsigned char *frame = vpx_video_reader_get_frame(reader,
- &frame_size);
+ const unsigned char *frame =
+ vpx_video_reader_get_frame(reader, &frame_size);
++frame_cnt;
if (frame_cnt % 30 == 1) {
- vp8_postproc_cfg_t pp = {0, 0, 0};
+ vp8_postproc_cfg_t pp = { 0, 0, 0 };
- if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
- die_codec(&codec, "Failed to turn off postproc.");
+ if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
+ die_codec(&codec, "Failed to turn off postproc.");
} else if (frame_cnt % 30 == 16) {
- vp8_postproc_cfg_t pp = {VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE,
- 4, 0};
+ vp8_postproc_cfg_t pp = { VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE, 4,
+ 0 };
if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
die_codec(&codec, "Failed to turn on postproc.");
};
@@ -125,8 +121,7 @@
}
printf("Processed %d frames.\n", frame_cnt);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
info->frame_width, info->frame_height, argv[2]);
--- a/examples/resize_util.c
+++ b/examples/resize_util.c
@@ -34,10 +34,8 @@
static int parse_dim(char *v, int *width, int *height) {
char *x = strchr(v, 'x');
- if (x == NULL)
- x = strchr(v, 'X');
- if (x == NULL)
- return 0;
+ if (x == NULL) x = strchr(v, 'X');
+ if (x == NULL) return 0;
*width = atoi(v);
*height = atoi(&x[1]);
if (*width <= 0 || *height <= 0)
@@ -93,17 +91,15 @@
else
frames = INT_MAX;
- printf("Input size: %dx%d\n",
- width, height);
- printf("Target size: %dx%d, Frames: ",
- target_width, target_height);
+ printf("Input size: %dx%d\n", width, height);
+ printf("Target size: %dx%d, Frames: ", target_width, target_height);
if (frames == INT_MAX)
printf("All\n");
else
printf("%d\n", frames);
- inbuf = (uint8_t*)malloc(width * height * 3 / 2);
- outbuf = (uint8_t*)malloc(target_width * target_height * 3 / 2);
+ inbuf = (uint8_t *)malloc(width * height * 3 / 2);
+ outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2);
inbuf_u = inbuf + width * height;
inbuf_v = inbuf_u + width * height / 4;
outbuf_u = outbuf + target_width * target_height;
@@ -110,13 +106,10 @@
outbuf_v = outbuf_u + target_width * target_height / 4;
f = 0;
while (f < frames) {
- if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1)
- break;
- vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2,
- height, width,
- outbuf, target_width, outbuf_u, outbuf_v,
- target_width / 2,
- target_height, target_width);
+ if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1) break;
+ vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height,
+ width, outbuf, target_width, outbuf_u, outbuf_v,
+ target_width / 2, target_height, target_width);
fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout);
f++;
}
--- a/examples/set_maps.c
+++ b/examples/set_maps.c
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
// VP8 Set Active and ROI Maps
// ===========================
//
@@ -86,8 +85,7 @@
roi.static_threshold[3] = 0;
roi.roi_map = (uint8_t *)malloc(roi.rows * roi.cols);
- for (i = 0; i < roi.rows * roi.cols; ++i)
- roi.roi_map[i] = i % 4;
+ for (i = 0; i < roi.rows * roi.cols; ++i) roi.roi_map[i] = i % 4;
if (vpx_codec_control(codec, VP8E_SET_ROI_MAP, &roi))
die_codec(codec, "Failed to set ROI map");
@@ -98,14 +96,13 @@
static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
vpx_codec_ctx_t *codec) {
unsigned int i;
- vpx_active_map_t map = {0, 0, 0};
+ vpx_active_map_t map = { 0, 0, 0 };
map.rows = (cfg->g_h + 15) / 16;
map.cols = (cfg->g_w + 15) / 16;
map.active_map = (uint8_t *)malloc(map.rows * map.cols);
- for (i = 0; i < map.rows * map.cols; ++i)
- map.active_map[i] = i % 2;
+ for (i = 0; i < map.rows * map.cols; ++i) map.active_map[i] = i % 2;
if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map))
die_codec(codec, "Failed to set active map");
@@ -115,7 +112,7 @@
static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
vpx_codec_ctx_t *codec) {
- vpx_active_map_t map = {0, 0, 0};
+ vpx_active_map_t map = { 0, 0, 0 };
map.rows = (cfg->g_h + 15) / 16;
map.cols = (cfg->g_w + 15) / 16;
@@ -125,17 +122,14 @@
die_codec(codec, "Failed to set active map");
}
-static int encode_frame(vpx_codec_ctx_t *codec,
- vpx_image_t *img,
- int frame_index,
- VpxVideoWriter *writer) {
+static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
+ int frame_index, VpxVideoWriter *writer) {
int got_pkts = 0;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
- const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0,
- VPX_DL_GOOD_QUALITY);
- if (res != VPX_CODEC_OK)
- die_codec(codec, "Failed to encode frame");
+ const vpx_codec_err_t res =
+ vpx_codec_encode(codec, img, frame_index, 1, 0, VPX_DL_GOOD_QUALITY);
+ if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1;
@@ -142,8 +136,7 @@
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
- if (!vpx_video_writer_write_frame(writer,
- pkt->data.frame.buf,
+ if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
pkt->data.frame.sz,
pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame");
@@ -167,12 +160,11 @@
VpxVideoInfo info;
VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL;
- const int fps = 2; // TODO(dkovalev) add command line argument
+ const int fps = 2; // TODO(dkovalev) add command line argument
const double bits_per_pixel_per_frame = 0.067;
exec_name = argv[0];
- if (argc != 6)
- die("Invalid number of arguments");
+ if (argc != 6) die("Invalid number of arguments");
memset(&info, 0, sizeof(info));
@@ -187,15 +179,13 @@
info.time_base.numerator = 1;
info.time_base.denominator = fps;
- if (info.frame_width <= 0 ||
- info.frame_height <= 0 ||
- (info.frame_width % 2) != 0 ||
- (info.frame_height % 2) != 0) {
+ if (info.frame_width <= 0 || info.frame_height <= 0 ||
+ (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
}
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
- info.frame_height, 1)) {
+ info.frame_height, 1)) {
die("Failed to allocate image.");
}
@@ -202,20 +192,18 @@
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
- if (res)
- die_codec(&codec, "Failed to get default codec config.");
+ if (res) die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height;
cfg.g_timebase.num = info.time_base.numerator;
cfg.g_timebase.den = info.time_base.denominator;
- cfg.rc_target_bitrate = (unsigned int)(bits_per_pixel_per_frame * cfg.g_w *
- cfg.g_h * fps / 1000);
+ cfg.rc_target_bitrate =
+ (unsigned int)(bits_per_pixel_per_frame * cfg.g_w * cfg.g_h * fps / 1000);
cfg.g_lag_in_frames = 0;
writer = vpx_video_writer_open(argv[5], kContainerIVF, &info);
- if (!writer)
- die("Failed to open %s for writing.", argv[5]);
+ if (!writer) die("Failed to open %s for writing.", argv[5]);
if (!(infile = fopen(argv[4], "rb")))
die("Failed to open %s for reading.", argv[4]);
@@ -239,7 +227,8 @@
}
// Flush encoder.
- while (encode_frame(&codec, NULL, -1, writer)) {}
+ while (encode_frame(&codec, NULL, -1, writer)) {
+ }
printf("\n");
fclose(infile);
@@ -246,8 +235,7 @@
printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer);
--- a/examples/simple_decoder.c
+++ b/examples/simple_decoder.c
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
// Simple Decoder
// ==============
//
@@ -103,12 +102,10 @@
exec_name = argv[0];
- if (argc != 3)
- die("Invalid number of arguments.");
+ if (argc != 3) die("Invalid number of arguments.");
reader = vpx_video_reader_open(argv[1]);
- if (!reader)
- die("Failed to open %s for reading.", argv[1]);
+ if (!reader) die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing.", argv[2]);
@@ -116,8 +113,7 @@
info = vpx_video_reader_get_info(reader);
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
- if (!decoder)
- die("Unknown input codec.");
+ if (!decoder) die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
@@ -128,8 +124,8 @@
vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL;
size_t frame_size = 0;
- const unsigned char *frame = vpx_video_reader_get_frame(reader,
- &frame_size);
+ const unsigned char *frame =
+ vpx_video_reader_get_frame(reader, &frame_size);
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
die_codec(&codec, "Failed to decode frame.");
@@ -140,8 +136,7 @@
}
printf("Processed %d frames.\n", frame_cnt);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
info->frame_width, info->frame_height, argv[2]);
--- a/examples/simple_encoder.c
+++ b/examples/simple_encoder.c
@@ -109,24 +109,20 @@
void usage_exit(void) {
fprintf(stderr,
"Usage: %s <codec> <width> <height> <infile> <outfile> "
- "<keyframe-interval> <error-resilient> <frames to encode>\n"
- "See comments in simple_encoder.c for more information.\n",
+ "<keyframe-interval> <error-resilient> <frames to encode>\n"
+ "See comments in simple_encoder.c for more information.\n",
exec_name);
exit(EXIT_FAILURE);
}
-static int encode_frame(vpx_codec_ctx_t *codec,
- vpx_image_t *img,
- int frame_index,
- int flags,
- VpxVideoWriter *writer) {
+static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
+ int frame_index, int flags, VpxVideoWriter *writer) {
int got_pkts = 0;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
- const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1,
- flags, VPX_DL_GOOD_QUALITY);
- if (res != VPX_CODEC_OK)
- die_codec(codec, "Failed to encode frame");
+ const vpx_codec_err_t res =
+ vpx_codec_encode(codec, img, frame_index, 1, flags, VPX_DL_GOOD_QUALITY);
+ if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1;
@@ -133,8 +129,7 @@
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
- if (!vpx_video_writer_write_frame(writer,
- pkt->data.frame.buf,
+ if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
pkt->data.frame.sz,
pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame");
@@ -155,7 +150,7 @@
int frame_count = 0;
vpx_image_t raw;
vpx_codec_err_t res;
- VpxVideoInfo info = {0};
+ VpxVideoInfo info = { 0 };
VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL;
const int fps = 30;
@@ -172,8 +167,7 @@
exec_name = argv[0];
- if (argc != 9)
- die("Invalid number of arguments");
+ if (argc != 9) die("Invalid number of arguments");
codec_arg = argv[1];
width_arg = argv[2];
@@ -184,8 +178,7 @@
max_frames = strtol(argv[8], NULL, 0);
encoder = get_vpx_encoder_by_name(codec_arg);
- if (!encoder)
- die("Unsupported codec.");
+ if (!encoder) die("Unsupported codec.");
info.codec_fourcc = encoder->fourcc;
info.frame_width = strtol(width_arg, NULL, 0);
@@ -193,27 +186,23 @@
info.time_base.numerator = 1;
info.time_base.denominator = fps;
- if (info.frame_width <= 0 ||
- info.frame_height <= 0 ||
- (info.frame_width % 2) != 0 ||
- (info.frame_height % 2) != 0) {
+ if (info.frame_width <= 0 || info.frame_height <= 0 ||
+ (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
}
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
- info.frame_height, 1)) {
+ info.frame_height, 1)) {
die("Failed to allocate image.");
}
keyframe_interval = strtol(keyframe_interval_arg, NULL, 0);
- if (keyframe_interval < 0)
- die("Invalid keyframe interval value.");
+ if (keyframe_interval < 0) die("Invalid keyframe interval value.");
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
- if (res)
- die_codec(&codec, "Failed to get default codec config.");
+ if (res) die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height;
@@ -223,8 +212,7 @@
cfg.g_error_resilient = strtol(argv[7], NULL, 0);
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
- if (!writer)
- die("Failed to open %s for writing.", outfile_arg);
+ if (!writer) die("Failed to open %s for writing.", outfile_arg);
if (!(infile = fopen(infile_arg, "rb")))
die("Failed to open %s for reading.", infile_arg);
@@ -239,12 +227,12 @@
flags |= VPX_EFLAG_FORCE_KF;
encode_frame(&codec, &raw, frame_count++, flags, writer);
frames_encoded++;
- if (max_frames > 0 && frames_encoded >= max_frames)
- break;
+ if (max_frames > 0 && frames_encoded >= max_frames) break;
}
// Flush encoder.
- while (encode_frame(&codec, NULL, -1, 0, writer)) {};
+ while (encode_frame(&codec, NULL, -1, 0, writer)) {
+ }
printf("\n");
fclose(infile);
@@ -251,8 +239,7 @@
printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer);
--- a/examples/twopass_encoder.c
+++ b/examples/twopass_encoder.c
@@ -61,25 +61,21 @@
void usage_exit(void) {
fprintf(stderr,
"Usage: %s <codec> <width> <height> <infile> <outfile> "
- "<frame limit>\n",
+ "<frame limit>\n",
exec_name);
exit(EXIT_FAILURE);
}
-static int get_frame_stats(vpx_codec_ctx_t *ctx,
- const vpx_image_t *img,
- vpx_codec_pts_t pts,
- unsigned int duration,
- vpx_enc_frame_flags_t flags,
- unsigned int deadline,
+static int get_frame_stats(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
+ vpx_codec_pts_t pts, unsigned int duration,
+ vpx_enc_frame_flags_t flags, unsigned int deadline,
vpx_fixed_buf_t *stats) {
int got_pkts = 0;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
- const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags,
- deadline);
- if (res != VPX_CODEC_OK)
- die_codec(ctx, "Failed to get frame stats.");
+ const vpx_codec_err_t res =
+ vpx_codec_encode(ctx, img, pts, duration, flags, deadline);
+ if (res != VPX_CODEC_OK) die_codec(ctx, "Failed to get frame stats.");
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
got_pkts = 1;
@@ -96,20 +92,16 @@
return got_pkts;
}
-static int encode_frame(vpx_codec_ctx_t *ctx,
- const vpx_image_t *img,
- vpx_codec_pts_t pts,
- unsigned int duration,
- vpx_enc_frame_flags_t flags,
- unsigned int deadline,
+static int encode_frame(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
+ vpx_codec_pts_t pts, unsigned int duration,
+ vpx_enc_frame_flags_t flags, unsigned int deadline,
VpxVideoWriter *writer) {
int got_pkts = 0;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
- const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags,
- deadline);
- if (res != VPX_CODEC_OK)
- die_codec(ctx, "Failed to encode frame.");
+ const vpx_codec_err_t res =
+ vpx_codec_encode(ctx, img, pts, duration, flags, deadline);
+ if (res != VPX_CODEC_OK) die_codec(ctx, "Failed to encode frame.");
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
got_pkts = 1;
@@ -117,8 +109,8 @@
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
- pkt->data.frame.sz,
- pkt->data.frame.pts))
+ pkt->data.frame.sz,
+ pkt->data.frame.pts))
die_codec(ctx, "Failed to write compressed frame.");
printf(keyframe ? "K" : ".");
fflush(stdout);
@@ -128,14 +120,12 @@
return got_pkts;
}
-static vpx_fixed_buf_t pass0(vpx_image_t *raw,
- FILE *infile,
+static vpx_fixed_buf_t pass0(vpx_image_t *raw, FILE *infile,
const VpxInterface *encoder,
- const vpx_codec_enc_cfg_t *cfg,
- int max_frames) {
+ const vpx_codec_enc_cfg_t *cfg, int max_frames) {
vpx_codec_ctx_t codec;
int frame_count = 0;
- vpx_fixed_buf_t stats = {NULL, 0};
+ vpx_fixed_buf_t stats = { NULL, 0 };
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
die_codec(&codec, "Failed to initialize encoder");
@@ -145,40 +135,33 @@
++frame_count;
get_frame_stats(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY,
&stats);
- if (max_frames > 0 && frame_count >= max_frames)
- break;
+ if (max_frames > 0 && frame_count >= max_frames) break;
}
// Flush encoder.
- while (get_frame_stats(&codec, NULL, frame_count, 1, 0,
- VPX_DL_GOOD_QUALITY, &stats)) {}
+ while (get_frame_stats(&codec, NULL, frame_count, 1, 0, VPX_DL_GOOD_QUALITY,
+ &stats)) {
+ }
printf("Pass 0 complete. Processed %d frames.\n", frame_count);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
return stats;
}
-static void pass1(vpx_image_t *raw,
- FILE *infile,
- const char *outfile_name,
- const VpxInterface *encoder,
- const vpx_codec_enc_cfg_t *cfg,
+static void pass1(vpx_image_t *raw, FILE *infile, const char *outfile_name,
+ const VpxInterface *encoder, const vpx_codec_enc_cfg_t *cfg,
int max_frames) {
- VpxVideoInfo info = {
- encoder->fourcc,
- cfg->g_w,
- cfg->g_h,
- {cfg->g_timebase.num, cfg->g_timebase.den}
- };
+ VpxVideoInfo info = { encoder->fourcc,
+ cfg->g_w,
+ cfg->g_h,
+ { cfg->g_timebase.num, cfg->g_timebase.den } };
VpxVideoWriter *writer = NULL;
vpx_codec_ctx_t codec;
int frame_count = 0;
writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info);
- if (!writer)
- die("Failed to open %s for writing", outfile_name);
+ if (!writer) die("Failed to open %s for writing", outfile_name);
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
die_codec(&codec, "Failed to initialize encoder");
@@ -188,17 +171,16 @@
++frame_count;
encode_frame(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, writer);
- if (max_frames > 0 && frame_count >= max_frames)
- break;
+ if (max_frames > 0 && frame_count >= max_frames) break;
}
// Flush encoder.
- while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_GOOD_QUALITY, writer)) {}
+ while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_GOOD_QUALITY, writer)) {
+ }
printf("\n");
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer);
@@ -215,8 +197,8 @@
vpx_fixed_buf_t stats;
const VpxInterface *encoder = NULL;
- const int fps = 30; // TODO(dkovalev) add command line argument
- const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
+ const int fps = 30; // TODO(dkovalev) add command line argument
+ const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
const char *const codec_arg = argv[1];
const char *const width_arg = argv[2];
const char *const height_arg = argv[3];
@@ -225,19 +207,17 @@
int max_frames = 0;
exec_name = argv[0];
- if (argc != 7)
- die("Invalid number of arguments.");
+ if (argc != 7) die("Invalid number of arguments.");
max_frames = strtol(argv[6], NULL, 0);
encoder = get_vpx_encoder_by_name(codec_arg);
- if (!encoder)
- die("Unsupported codec.");
+ if (!encoder) die("Unsupported codec.");
w = strtol(width_arg, NULL, 0);
h = strtol(height_arg, NULL, 0);
- if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
+ if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
die("Invalid frame size: %dx%d", w, h);
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, w, h, 1))
@@ -247,8 +227,7 @@
// Configuration
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
- if (res)
- die_codec(&codec, "Failed to get default codec config.");
+ if (res) die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = w;
cfg.g_h = h;
--- a/examples/vp8_multi_resolution_encoder.c
+++ b/examples/vp8_multi_resolution_encoder.c
@@ -35,11 +35,9 @@
#include "vpx_ports/mem_ops.h"
#include "../tools_common.h"
#define interface (vpx_codec_vp8_cx())
-#define fourcc 0x30385056
+#define fourcc 0x30385056
-void usage_exit(void) {
- exit(EXIT_FAILURE);
-}
+void usage_exit(void) { exit(EXIT_FAILURE); }
/*
* The input video frame is downsampled several times to generate a multi-level
@@ -64,107 +62,100 @@
int (*read_frame_p)(FILE *f, vpx_image_t *img);
static int read_frame(FILE *f, vpx_image_t *img) {
- size_t nbytes, to_read;
- int res = 1;
+ size_t nbytes, to_read;
+ int res = 1;
- to_read = img->w*img->h*3/2;
- nbytes = fread(img->planes[0], 1, to_read, f);
- if(nbytes != to_read) {
- res = 0;
- if(nbytes > 0)
- printf("Warning: Read partial frame. Check your width & height!\n");
- }
- return res;
+ to_read = img->w * img->h * 3 / 2;
+ nbytes = fread(img->planes[0], 1, to_read, f);
+ if (nbytes != to_read) {
+ res = 0;
+ if (nbytes > 0)
+ printf("Warning: Read partial frame. Check your width & height!\n");
+ }
+ return res;
}
static int read_frame_by_row(FILE *f, vpx_image_t *img) {
- size_t nbytes, to_read;
- int res = 1;
- int plane;
+ size_t nbytes, to_read;
+ int res = 1;
+ int plane;
- for (plane = 0; plane < 3; plane++)
- {
- unsigned char *ptr;
- int w = (plane ? (1 + img->d_w) / 2 : img->d_w);
- int h = (plane ? (1 + img->d_h) / 2 : img->d_h);
- int r;
+ for (plane = 0; plane < 3; plane++) {
+ unsigned char *ptr;
+ int w = (plane ? (1 + img->d_w) / 2 : img->d_w);
+ int h = (plane ? (1 + img->d_h) / 2 : img->d_h);
+ int r;
- /* Determine the correct plane based on the image format. The for-loop
- * always counts in Y,U,V order, but this may not match the order of
- * the data on disk.
- */
- switch (plane)
- {
- case 1:
- ptr = img->planes[img->fmt==VPX_IMG_FMT_YV12? VPX_PLANE_V : VPX_PLANE_U];
- break;
- case 2:
- ptr = img->planes[img->fmt==VPX_IMG_FMT_YV12?VPX_PLANE_U : VPX_PLANE_V];
- break;
- default:
- ptr = img->planes[plane];
- }
+ /* Determine the correct plane based on the image format. The for-loop
+ * always counts in Y,U,V order, but this may not match the order of
+ * the data on disk.
+ */
+ switch (plane) {
+ case 1:
+ ptr = img->planes[img->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_V
+ : VPX_PLANE_U];
+ break;
+ case 2:
+ ptr = img->planes[img->fmt == VPX_IMG_FMT_YV12 ? VPX_PLANE_U
+ : VPX_PLANE_V];
+ break;
+ default: ptr = img->planes[plane];
+ }
- for (r = 0; r < h; r++)
- {
- to_read = w;
+ for (r = 0; r < h; r++) {
+ to_read = w;
- nbytes = fread(ptr, 1, to_read, f);
- if(nbytes != to_read) {
- res = 0;
- if(nbytes > 0)
- printf("Warning: Read partial frame. Check your width & height!\n");
- break;
- }
+ nbytes = fread(ptr, 1, to_read, f);
+ if (nbytes != to_read) {
+ res = 0;
+ if (nbytes > 0)
+ printf("Warning: Read partial frame. Check your width & height!\n");
+ break;
+ }
- ptr += img->stride[plane];
- }
- if (!res)
- break;
+ ptr += img->stride[plane];
}
+ if (!res) break;
+ }
- return res;
+ return res;
}
-static void write_ivf_file_header(FILE *outfile,
- const vpx_codec_enc_cfg_t *cfg,
+static void write_ivf_file_header(FILE *outfile, const vpx_codec_enc_cfg_t *cfg,
int frame_cnt) {
- char header[32];
+ char header[32];
- if(cfg->g_pass != VPX_RC_ONE_PASS && cfg->g_pass != VPX_RC_LAST_PASS)
- return;
- header[0] = 'D';
- header[1] = 'K';
- header[2] = 'I';
- header[3] = 'F';
- mem_put_le16(header+4, 0); /* version */
- mem_put_le16(header+6, 32); /* headersize */
- mem_put_le32(header+8, fourcc); /* headersize */
- mem_put_le16(header+12, cfg->g_w); /* width */
- mem_put_le16(header+14, cfg->g_h); /* height */
- mem_put_le32(header+16, cfg->g_timebase.den); /* rate */
- mem_put_le32(header+20, cfg->g_timebase.num); /* scale */
- mem_put_le32(header+24, frame_cnt); /* length */
- mem_put_le32(header+28, 0); /* unused */
+ if (cfg->g_pass != VPX_RC_ONE_PASS && cfg->g_pass != VPX_RC_LAST_PASS) return;
+ header[0] = 'D';
+ header[1] = 'K';
+ header[2] = 'I';
+ header[3] = 'F';
+ mem_put_le16(header + 4, 0); /* version */
+ mem_put_le16(header + 6, 32); /* headersize */
+ mem_put_le32(header + 8, fourcc); /* headersize */
+ mem_put_le16(header + 12, cfg->g_w); /* width */
+ mem_put_le16(header + 14, cfg->g_h); /* height */
+ mem_put_le32(header + 16, cfg->g_timebase.den); /* rate */
+ mem_put_le32(header + 20, cfg->g_timebase.num); /* scale */
+ mem_put_le32(header + 24, frame_cnt); /* length */
+ mem_put_le32(header + 28, 0); /* unused */
- (void) fwrite(header, 1, 32, outfile);
+ (void)fwrite(header, 1, 32, outfile);
}
static void write_ivf_frame_header(FILE *outfile,
- const vpx_codec_cx_pkt_t *pkt)
-{
- char header[12];
- vpx_codec_pts_t pts;
+ const vpx_codec_cx_pkt_t *pkt) {
+ char header[12];
+ vpx_codec_pts_t pts;
- if(pkt->kind != VPX_CODEC_CX_FRAME_PKT)
- return;
+ if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return;
- pts = pkt->data.frame.pts;
- mem_put_le32(header, pkt->data.frame.sz);
- mem_put_le32(header+4, pts&0xFFFFFFFF);
- mem_put_le32(header+8, pts >> 32);
+ pts = pkt->data.frame.pts;
+ mem_put_le32(header, pkt->data.frame.sz);
+ mem_put_le32(header + 4, pts & 0xFFFFFFFF);
+ mem_put_le32(header + 8, pts >> 32);
- (void) fwrite(header, 1, 12, outfile);
+ (void)fwrite(header, 1, 12, outfile);
}
/* Temporal scaling parameters */
@@ -173,559 +164,505 @@
* parameters will be passed in as user parameters in another version.
*/
static void set_temporal_layer_pattern(int num_temporal_layers,
- vpx_codec_enc_cfg_t *cfg,
- int bitrate,
- int *layer_flags)
-{
- assert(num_temporal_layers <= MAX_NUM_TEMPORAL_LAYERS);
- switch (num_temporal_layers)
- {
- case 1:
- {
- /* 1-layer */
- cfg->ts_number_layers = 1;
- cfg->ts_periodicity = 1;
- cfg->ts_rate_decimator[0] = 1;
- cfg->ts_layer_id[0] = 0;
- cfg->ts_target_bitrate[0] = bitrate;
+ vpx_codec_enc_cfg_t *cfg, int bitrate,
+ int *layer_flags) {
+ assert(num_temporal_layers <= MAX_NUM_TEMPORAL_LAYERS);
+ switch (num_temporal_layers) {
+ case 1: {
+ /* 1-layer */
+ cfg->ts_number_layers = 1;
+ cfg->ts_periodicity = 1;
+ cfg->ts_rate_decimator[0] = 1;
+ cfg->ts_layer_id[0] = 0;
+ cfg->ts_target_bitrate[0] = bitrate;
- // Update L only.
- layer_flags[0] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
- break;
+ // Update L only.
+ layer_flags[0] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
+ break;
}
- case 2:
- {
- /* 2-layers, with sync point at first frame of layer 1. */
- cfg->ts_number_layers = 2;
- cfg->ts_periodicity = 2;
- cfg->ts_rate_decimator[0] = 2;
- cfg->ts_rate_decimator[1] = 1;
- cfg->ts_layer_id[0] = 0;
- cfg->ts_layer_id[1] = 1;
- // Use 60/40 bit allocation as example.
- cfg->ts_target_bitrate[0] = 0.6f * bitrate;
- cfg->ts_target_bitrate[1] = bitrate;
+ case 2: {
+ /* 2-layers, with sync point at first frame of layer 1. */
+ cfg->ts_number_layers = 2;
+ cfg->ts_periodicity = 2;
+ cfg->ts_rate_decimator[0] = 2;
+ cfg->ts_rate_decimator[1] = 1;
+ cfg->ts_layer_id[0] = 0;
+ cfg->ts_layer_id[1] = 1;
+ // Use 60/40 bit allocation as example.
+ cfg->ts_target_bitrate[0] = 0.6f * bitrate;
+ cfg->ts_target_bitrate[1] = bitrate;
- /* 0=L, 1=GF */
- // ARF is used as predictor for all frames, and is only updated on
- // key frame. Sync point every 8 frames.
+ /* 0=L, 1=GF */
+ // ARF is used as predictor for all frames, and is only updated on
+ // key frame. Sync point every 8 frames.
- // Layer 0: predict from L and ARF, update L and G.
- layer_flags[0] = VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ // Layer 0: predict from L and ARF, update L and G.
+ layer_flags[0] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF;
- // Layer 1: sync point: predict from L and ARF, and update G.
- layer_flags[1] = VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ARF;
+ // Layer 1: sync point: predict from L and ARF, and update G.
+ layer_flags[1] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
- // Layer 0, predict from L and ARF, update L.
- layer_flags[2] = VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ // Layer 0, predict from L and ARF, update L.
+ layer_flags[2] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
- // Layer 1: predict from L, G and ARF, and update G.
- layer_flags[3] = VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ENTROPY;
+ // Layer 1: predict from L, G and ARF, and update G.
+ layer_flags[3] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
+ VP8_EFLAG_NO_UPD_ENTROPY;
- // Layer 0
- layer_flags[4] = layer_flags[2];
+ // Layer 0
+ layer_flags[4] = layer_flags[2];
- // Layer 1
- layer_flags[5] = layer_flags[3];
+ // Layer 1
+ layer_flags[5] = layer_flags[3];
- // Layer 0
- layer_flags[6] = layer_flags[4];
+ // Layer 0
+ layer_flags[6] = layer_flags[4];
- // Layer 1
- layer_flags[7] = layer_flags[5];
- break;
+ // Layer 1
+ layer_flags[7] = layer_flags[5];
+ break;
}
case 3:
- default:
- {
- // 3-layers structure where ARF is used as predictor for all frames,
- // and is only updated on key frame.
- // Sync points for layer 1 and 2 every 8 frames.
- cfg->ts_number_layers = 3;
- cfg->ts_periodicity = 4;
- cfg->ts_rate_decimator[0] = 4;
- cfg->ts_rate_decimator[1] = 2;
- cfg->ts_rate_decimator[2] = 1;
- cfg->ts_layer_id[0] = 0;
- cfg->ts_layer_id[1] = 2;
- cfg->ts_layer_id[2] = 1;
- cfg->ts_layer_id[3] = 2;
- // Use 40/20/40 bit allocation as example.
- cfg->ts_target_bitrate[0] = 0.4f * bitrate;
- cfg->ts_target_bitrate[1] = 0.6f * bitrate;
- cfg->ts_target_bitrate[2] = bitrate;
+ default: {
+ // 3-layers structure where ARF is used as predictor for all frames,
+ // and is only updated on key frame.
+ // Sync points for layer 1 and 2 every 8 frames.
+ cfg->ts_number_layers = 3;
+ cfg->ts_periodicity = 4;
+ cfg->ts_rate_decimator[0] = 4;
+ cfg->ts_rate_decimator[1] = 2;
+ cfg->ts_rate_decimator[2] = 1;
+ cfg->ts_layer_id[0] = 0;
+ cfg->ts_layer_id[1] = 2;
+ cfg->ts_layer_id[2] = 1;
+ cfg->ts_layer_id[3] = 2;
+ // Use 40/20/40 bit allocation as example.
+ cfg->ts_target_bitrate[0] = 0.4f * bitrate;
+ cfg->ts_target_bitrate[1] = 0.6f * bitrate;
+ cfg->ts_target_bitrate[2] = bitrate;
- /* 0=L, 1=GF, 2=ARF */
+ /* 0=L, 1=GF, 2=ARF */
- // Layer 0: predict from L and ARF; update L and G.
- layer_flags[0] = VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_REF_GF;
+ // Layer 0: predict from L and ARF; update L and G.
+ layer_flags[0] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
- // Layer 2: sync point: predict from L and ARF; update none.
- layer_flags[1] = VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ENTROPY;
+ // Layer 2: sync point: predict from L and ARF; update none.
+ layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
+ VP8_EFLAG_NO_UPD_ENTROPY;
- // Layer 1: sync point: predict from L and ARF; update G.
- layer_flags[2] = VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST;
+ // Layer 1: sync point: predict from L and ARF; update G.
+ layer_flags[2] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
- // Layer 2: predict from L, G, ARF; update none.
- layer_flags[3] = VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ENTROPY;
+ // Layer 2: predict from L, G, ARF; update none.
+ layer_flags[3] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
- // Layer 0: predict from L and ARF; update L.
- layer_flags[4] = VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_REF_GF;
+ // Layer 0: predict from L and ARF; update L.
+ layer_flags[4] =
+ VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
- // Layer 2: predict from L, G, ARF; update none.
- layer_flags[5] = layer_flags[3];
+ // Layer 2: predict from L, G, ARF; update none.
+ layer_flags[5] = layer_flags[3];
- // Layer 1: predict from L, G, ARF; update G.
- layer_flags[6] = VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST;
+ // Layer 1: predict from L, G, ARF; update G.
+ layer_flags[6] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
- // Layer 2: predict from L, G, ARF; update none.
- layer_flags[7] = layer_flags[3];
- break;
+ // Layer 2: predict from L, G, ARF; update none.
+ layer_flags[7] = layer_flags[3];
+ break;
}
- }
+ }
}
/* The periodicity of the pattern given the number of temporal layers. */
-static int periodicity_to_num_layers[MAX_NUM_TEMPORAL_LAYERS] = {1, 8, 8};
+static int periodicity_to_num_layers[MAX_NUM_TEMPORAL_LAYERS] = { 1, 8, 8 };
-int main(int argc, char **argv)
-{
- FILE *infile, *outfile[NUM_ENCODERS];
- FILE *downsampled_input[NUM_ENCODERS - 1];
- char filename[50];
- vpx_codec_ctx_t codec[NUM_ENCODERS];
- vpx_codec_enc_cfg_t cfg[NUM_ENCODERS];
- int frame_cnt = 0;
- vpx_image_t raw[NUM_ENCODERS];
- vpx_codec_err_t res[NUM_ENCODERS];
+int main(int argc, char **argv) {
+ FILE *infile, *outfile[NUM_ENCODERS];
+ FILE *downsampled_input[NUM_ENCODERS - 1];
+ char filename[50];
+ vpx_codec_ctx_t codec[NUM_ENCODERS];
+ vpx_codec_enc_cfg_t cfg[NUM_ENCODERS];
+ int frame_cnt = 0;
+ vpx_image_t raw[NUM_ENCODERS];
+ vpx_codec_err_t res[NUM_ENCODERS];
- int i;
- long width;
- long height;
- int length_frame;
- int frame_avail;
- int got_data;
- int flags = 0;
- int layer_id = 0;
+ int i;
+ long width;
+ long height;
+ int length_frame;
+ int frame_avail;
+ int got_data;
+ int flags = 0;
+ int layer_id = 0;
- int layer_flags[VPX_TS_MAX_PERIODICITY * NUM_ENCODERS]
- = {0};
- int flag_periodicity;
+ int layer_flags[VPX_TS_MAX_PERIODICITY * NUM_ENCODERS] = { 0 };
+ int flag_periodicity;
- /*Currently, only realtime mode is supported in multi-resolution encoding.*/
- int arg_deadline = VPX_DL_REALTIME;
+ /*Currently, only realtime mode is supported in multi-resolution encoding.*/
+ int arg_deadline = VPX_DL_REALTIME;
- /* Set show_psnr to 1/0 to show/not show PSNR. Choose show_psnr=0 if you
- don't need to know PSNR, which will skip PSNR calculation and save
- encoding time. */
- int show_psnr = 0;
- int key_frame_insert = 0;
- uint64_t psnr_sse_total[NUM_ENCODERS] = {0};
- uint64_t psnr_samples_total[NUM_ENCODERS] = {0};
- double psnr_totals[NUM_ENCODERS][4] = {{0,0}};
- int psnr_count[NUM_ENCODERS] = {0};
+ /* Set show_psnr to 1/0 to show/not show PSNR. Choose show_psnr=0 if you
+ don't need to know PSNR, which will skip PSNR calculation and save
+ encoding time. */
+ int show_psnr = 0;
+ int key_frame_insert = 0;
+ uint64_t psnr_sse_total[NUM_ENCODERS] = { 0 };
+ uint64_t psnr_samples_total[NUM_ENCODERS] = { 0 };
+ double psnr_totals[NUM_ENCODERS][4] = { { 0, 0 } };
+ int psnr_count[NUM_ENCODERS] = { 0 };
- int64_t cx_time = 0;
+ int64_t cx_time = 0;
- /* Set the required target bitrates for each resolution level.
- * If target bitrate for highest-resolution level is set to 0,
- * (i.e. target_bitrate[0]=0), we skip encoding at that level.
- */
- unsigned int target_bitrate[NUM_ENCODERS]={1000, 500, 100};
+ /* Set the required target bitrates for each resolution level.
+ * If target bitrate for highest-resolution level is set to 0,
+ * (i.e. target_bitrate[0]=0), we skip encoding at that level.
+ */
+ unsigned int target_bitrate[NUM_ENCODERS] = { 1000, 500, 100 };
- /* Enter the frame rate of the input video */
- int framerate = 30;
+ /* Enter the frame rate of the input video */
+ int framerate = 30;
- /* Set down-sampling factor for each resolution level.
- dsf[0] controls down sampling from level 0 to level 1;
- dsf[1] controls down sampling from level 1 to level 2;
- dsf[2] is not used. */
- vpx_rational_t dsf[NUM_ENCODERS] = {{2, 1}, {2, 1}, {1, 1}};
+ /* Set down-sampling factor for each resolution level.
+ dsf[0] controls down sampling from level 0 to level 1;
+ dsf[1] controls down sampling from level 1 to level 2;
+ dsf[2] is not used. */
+ vpx_rational_t dsf[NUM_ENCODERS] = { { 2, 1 }, { 2, 1 }, { 1, 1 } };
- /* Set the number of temporal layers for each encoder/resolution level,
- * starting from highest resoln down to lowest resoln. */
- unsigned int num_temporal_layers[NUM_ENCODERS] = {3, 3, 3};
+ /* Set the number of temporal layers for each encoder/resolution level,
+ * starting from highest resoln down to lowest resoln. */
+ unsigned int num_temporal_layers[NUM_ENCODERS] = { 3, 3, 3 };
- if(argc!= (7 + 3 * NUM_ENCODERS))
- die("Usage: %s <width> <height> <frame_rate> <infile> <outfile(s)> "
- "<rate_encoder(s)> <temporal_layer(s)> <key_frame_insert> <output psnr?> \n",
- argv[0]);
+ if (argc != (7 + 3 * NUM_ENCODERS))
+ die(
+ "Usage: %s <width> <height> <frame_rate> <infile> <outfile(s)> "
+ "<rate_encoder(s)> <temporal_layer(s)> <key_frame_insert> <output "
+ "psnr?> \n",
+ argv[0]);
- printf("Using %s\n",vpx_codec_iface_name(interface));
+ printf("Using %s\n", vpx_codec_iface_name(interface));
- width = strtol(argv[1], NULL, 0);
- height = strtol(argv[2], NULL, 0);
- framerate = strtol(argv[3], NULL, 0);
+ width = strtol(argv[1], NULL, 0);
+ height = strtol(argv[2], NULL, 0);
+ framerate = strtol(argv[3], NULL, 0);
- if(width < 16 || width%2 || height <16 || height%2)
- die("Invalid resolution: %ldx%ld", width, height);
+ if (width < 16 || width % 2 || height < 16 || height % 2)
+ die("Invalid resolution: %ldx%ld", width, height);
- /* Open input video file for encoding */
- if(!(infile = fopen(argv[4], "rb")))
- die("Failed to open %s for reading", argv[4]);
+ /* Open input video file for encoding */
+ if (!(infile = fopen(argv[4], "rb")))
+ die("Failed to open %s for reading", argv[4]);
- /* Open output file for each encoder to output bitstreams */
- for (i=0; i< NUM_ENCODERS; i++)
- {
- if(!target_bitrate[i])
- {
- outfile[i] = NULL;
- continue;
- }
-
- if(!(outfile[i] = fopen(argv[i+5], "wb")))
- die("Failed to open %s for writing", argv[i+4]);
+ /* Open output file for each encoder to output bitstreams */
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ if (!target_bitrate[i]) {
+ outfile[i] = NULL;
+ continue;
}
- // Bitrates per spatial layer: overwrite default rates above.
- for (i=0; i< NUM_ENCODERS; i++)
- {
- target_bitrate[i] = strtol(argv[NUM_ENCODERS + 5 + i], NULL, 0);
- }
+ if (!(outfile[i] = fopen(argv[i + 5], "wb")))
+ die("Failed to open %s for writing", argv[i + 4]);
+ }
- // Temporal layers per spatial layers: overwrite default settings above.
- for (i=0; i< NUM_ENCODERS; i++)
- {
- num_temporal_layers[i] = strtol(argv[2 * NUM_ENCODERS + 5 + i], NULL, 0);
- if (num_temporal_layers[i] < 1 || num_temporal_layers[i] > 3)
- die("Invalid temporal layers: %d, Must be 1, 2, or 3. \n",
- num_temporal_layers);
- }
+ // Bitrates per spatial layer: overwrite default rates above.
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ target_bitrate[i] = strtol(argv[NUM_ENCODERS + 5 + i], NULL, 0);
+ }
- /* Open file to write out each spatially downsampled input stream. */
- for (i=0; i< NUM_ENCODERS - 1; i++)
- {
- // Highest resoln is encoder 0.
- if (sprintf(filename,"ds%d.yuv",NUM_ENCODERS - i) < 0)
- {
- return EXIT_FAILURE;
- }
- downsampled_input[i] = fopen(filename,"wb");
+ // Temporal layers per spatial layers: overwrite default settings above.
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ num_temporal_layers[i] = strtol(argv[2 * NUM_ENCODERS + 5 + i], NULL, 0);
+ if (num_temporal_layers[i] < 1 || num_temporal_layers[i] > 3)
+ die("Invalid temporal layers: %d, Must be 1, 2, or 3. \n",
+ num_temporal_layers);
+ }
+
+ /* Open file to write out each spatially downsampled input stream. */
+ for (i = 0; i < NUM_ENCODERS - 1; i++) {
+ // Highest resoln is encoder 0.
+ if (sprintf(filename, "ds%d.yuv", NUM_ENCODERS - i) < 0) {
+ return EXIT_FAILURE;
}
+ downsampled_input[i] = fopen(filename, "wb");
+ }
- key_frame_insert = strtol(argv[3 * NUM_ENCODERS + 5], NULL, 0);
+ key_frame_insert = strtol(argv[3 * NUM_ENCODERS + 5], NULL, 0);
- show_psnr = strtol(argv[3 * NUM_ENCODERS + 6], NULL, 0);
+ show_psnr = strtol(argv[3 * NUM_ENCODERS + 6], NULL, 0);
-
- /* Populate default encoder configuration */
- for (i=0; i< NUM_ENCODERS; i++)
- {
- res[i] = vpx_codec_enc_config_default(interface, &cfg[i], 0);
- if(res[i]) {
- printf("Failed to get config: %s\n", vpx_codec_err_to_string(res[i]));
- return EXIT_FAILURE;
- }
+ /* Populate default encoder configuration */
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ res[i] = vpx_codec_enc_config_default(interface, &cfg[i], 0);
+ if (res[i]) {
+ printf("Failed to get config: %s\n", vpx_codec_err_to_string(res[i]));
+ return EXIT_FAILURE;
}
+ }
- /*
- * Update the default configuration according to needs of the application.
- */
- /* Highest-resolution encoder settings */
- cfg[0].g_w = width;
- cfg[0].g_h = height;
- cfg[0].rc_dropframe_thresh = 0;
- cfg[0].rc_end_usage = VPX_CBR;
- cfg[0].rc_resize_allowed = 0;
- cfg[0].rc_min_quantizer = 2;
- cfg[0].rc_max_quantizer = 56;
- cfg[0].rc_undershoot_pct = 100;
- cfg[0].rc_overshoot_pct = 15;
- cfg[0].rc_buf_initial_sz = 500;
- cfg[0].rc_buf_optimal_sz = 600;
- cfg[0].rc_buf_sz = 1000;
- cfg[0].g_error_resilient = 1; /* Enable error resilient mode */
- cfg[0].g_lag_in_frames = 0;
+ /*
+ * Update the default configuration according to needs of the application.
+ */
+ /* Highest-resolution encoder settings */
+ cfg[0].g_w = width;
+ cfg[0].g_h = height;
+ cfg[0].rc_dropframe_thresh = 0;
+ cfg[0].rc_end_usage = VPX_CBR;
+ cfg[0].rc_resize_allowed = 0;
+ cfg[0].rc_min_quantizer = 2;
+ cfg[0].rc_max_quantizer = 56;
+ cfg[0].rc_undershoot_pct = 100;
+ cfg[0].rc_overshoot_pct = 15;
+ cfg[0].rc_buf_initial_sz = 500;
+ cfg[0].rc_buf_optimal_sz = 600;
+ cfg[0].rc_buf_sz = 1000;
+ cfg[0].g_error_resilient = 1; /* Enable error resilient mode */
+ cfg[0].g_lag_in_frames = 0;
- /* Disable automatic keyframe placement */
- /* Note: These 3 settings are copied to all levels. But, except the lowest
- * resolution level, all other levels are set to VPX_KF_DISABLED internally.
- */
- cfg[0].kf_mode = VPX_KF_AUTO;
- cfg[0].kf_min_dist = 3000;
- cfg[0].kf_max_dist = 3000;
+ /* Disable automatic keyframe placement */
+ /* Note: These 3 settings are copied to all levels. But, except the lowest
+ * resolution level, all other levels are set to VPX_KF_DISABLED internally.
+ */
+ cfg[0].kf_mode = VPX_KF_AUTO;
+ cfg[0].kf_min_dist = 3000;
+ cfg[0].kf_max_dist = 3000;
- cfg[0].rc_target_bitrate = target_bitrate[0]; /* Set target bitrate */
- cfg[0].g_timebase.num = 1; /* Set fps */
- cfg[0].g_timebase.den = framerate;
+ cfg[0].rc_target_bitrate = target_bitrate[0]; /* Set target bitrate */
+ cfg[0].g_timebase.num = 1; /* Set fps */
+ cfg[0].g_timebase.den = framerate;
- /* Other-resolution encoder settings */
- for (i=1; i< NUM_ENCODERS; i++)
- {
- memcpy(&cfg[i], &cfg[0], sizeof(vpx_codec_enc_cfg_t));
+ /* Other-resolution encoder settings */
+ for (i = 1; i < NUM_ENCODERS; i++) {
+ memcpy(&cfg[i], &cfg[0], sizeof(vpx_codec_enc_cfg_t));
- cfg[i].rc_target_bitrate = target_bitrate[i];
+ cfg[i].rc_target_bitrate = target_bitrate[i];
- /* Note: Width & height of other-resolution encoders are calculated
- * from the highest-resolution encoder's size and the corresponding
- * down_sampling_factor.
- */
- {
- unsigned int iw = cfg[i-1].g_w*dsf[i-1].den + dsf[i-1].num - 1;
- unsigned int ih = cfg[i-1].g_h*dsf[i-1].den + dsf[i-1].num - 1;
- cfg[i].g_w = iw/dsf[i-1].num;
- cfg[i].g_h = ih/dsf[i-1].num;
- }
-
- /* Make width & height to be multiplier of 2. */
- // Should support odd size ???
- if((cfg[i].g_w)%2)cfg[i].g_w++;
- if((cfg[i].g_h)%2)cfg[i].g_h++;
+ /* Note: Width & height of other-resolution encoders are calculated
+ * from the highest-resolution encoder's size and the corresponding
+ * down_sampling_factor.
+ */
+ {
+ unsigned int iw = cfg[i - 1].g_w * dsf[i - 1].den + dsf[i - 1].num - 1;
+ unsigned int ih = cfg[i - 1].g_h * dsf[i - 1].den + dsf[i - 1].num - 1;
+ cfg[i].g_w = iw / dsf[i - 1].num;
+ cfg[i].g_h = ih / dsf[i - 1].num;
}
+ /* Make width & height to be multiplier of 2. */
+ // Should support odd size ???
+ if ((cfg[i].g_w) % 2) cfg[i].g_w++;
+ if ((cfg[i].g_h) % 2) cfg[i].g_h++;
+ }
- // Set the number of threads per encode/spatial layer.
- // (1, 1, 1) means no encoder threading.
- cfg[0].g_threads = 2;
- cfg[1].g_threads = 1;
- cfg[2].g_threads = 1;
+ // Set the number of threads per encode/spatial layer.
+ // (1, 1, 1) means no encoder threading.
+ cfg[0].g_threads = 2;
+ cfg[1].g_threads = 1;
+ cfg[2].g_threads = 1;
- /* Allocate image for each encoder */
- for (i=0; i< NUM_ENCODERS; i++)
- if(!vpx_img_alloc(&raw[i], VPX_IMG_FMT_I420, cfg[i].g_w, cfg[i].g_h, 32))
- die("Failed to allocate image", cfg[i].g_w, cfg[i].g_h);
+ /* Allocate image for each encoder */
+ for (i = 0; i < NUM_ENCODERS; i++)
+ if (!vpx_img_alloc(&raw[i], VPX_IMG_FMT_I420, cfg[i].g_w, cfg[i].g_h, 32))
+ die("Failed to allocate image", cfg[i].g_w, cfg[i].g_h);
- if (raw[0].stride[VPX_PLANE_Y] == raw[0].d_w)
- read_frame_p = read_frame;
- else
- read_frame_p = read_frame_by_row;
+ if (raw[0].stride[VPX_PLANE_Y] == raw[0].d_w)
+ read_frame_p = read_frame;
+ else
+ read_frame_p = read_frame_by_row;
- for (i=0; i< NUM_ENCODERS; i++)
- if(outfile[i])
- write_ivf_file_header(outfile[i], &cfg[i], 0);
+ for (i = 0; i < NUM_ENCODERS; i++)
+ if (outfile[i]) write_ivf_file_header(outfile[i], &cfg[i], 0);
- /* Temporal layers settings */
- for ( i=0; i<NUM_ENCODERS; i++)
- {
- set_temporal_layer_pattern(num_temporal_layers[i],
- &cfg[i],
- cfg[i].rc_target_bitrate,
- &layer_flags[i * VPX_TS_MAX_PERIODICITY]);
- }
+ /* Temporal layers settings */
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ set_temporal_layer_pattern(num_temporal_layers[i], &cfg[i],
+ cfg[i].rc_target_bitrate,
+ &layer_flags[i * VPX_TS_MAX_PERIODICITY]);
+ }
- /* Initialize multi-encoder */
- if(vpx_codec_enc_init_multi(&codec[0], interface, &cfg[0], NUM_ENCODERS,
- (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[0]))
- die_codec(&codec[0], "Failed to initialize encoder");
+ /* Initialize multi-encoder */
+ if (vpx_codec_enc_init_multi(&codec[0], interface, &cfg[0], NUM_ENCODERS,
+ (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[0]))
+ die_codec(&codec[0], "Failed to initialize encoder");
- /* The extra encoding configuration parameters can be set as follows. */
- /* Set encoding speed */
- for ( i=0; i<NUM_ENCODERS; i++)
- {
- int speed = -6;
- /* Lower speed for the lowest resolution. */
- if (i == NUM_ENCODERS - 1) speed = -4;
- if(vpx_codec_control(&codec[i], VP8E_SET_CPUUSED, speed))
- die_codec(&codec[i], "Failed to set cpu_used");
- }
+ /* The extra encoding configuration parameters can be set as follows. */
+ /* Set encoding speed */
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ int speed = -6;
+ /* Lower speed for the lowest resolution. */
+ if (i == NUM_ENCODERS - 1) speed = -4;
+ if (vpx_codec_control(&codec[i], VP8E_SET_CPUUSED, speed))
+ die_codec(&codec[i], "Failed to set cpu_used");
+ }
- /* Set static threshold = 1 for all encoders */
- for ( i=0; i<NUM_ENCODERS; i++)
- {
- if(vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD, 1))
- die_codec(&codec[i], "Failed to set static threshold");
- }
+ /* Set static threshold = 1 for all encoders */
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ if (vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD, 1))
+ die_codec(&codec[i], "Failed to set static threshold");
+ }
- /* Set NOISE_SENSITIVITY to do TEMPORAL_DENOISING */
- /* Enable denoising for the highest-resolution encoder. */
- if(vpx_codec_control(&codec[0], VP8E_SET_NOISE_SENSITIVITY, 1))
- die_codec(&codec[0], "Failed to set noise_sensitivity");
- for ( i=1; i< NUM_ENCODERS; i++)
- {
- if(vpx_codec_control(&codec[i], VP8E_SET_NOISE_SENSITIVITY, 0))
- die_codec(&codec[i], "Failed to set noise_sensitivity");
- }
+ /* Set NOISE_SENSITIVITY to do TEMPORAL_DENOISING */
+ /* Enable denoising for the highest-resolution encoder. */
+ if (vpx_codec_control(&codec[0], VP8E_SET_NOISE_SENSITIVITY, 1))
+ die_codec(&codec[0], "Failed to set noise_sensitivity");
+ for (i = 1; i < NUM_ENCODERS; i++) {
+ if (vpx_codec_control(&codec[i], VP8E_SET_NOISE_SENSITIVITY, 0))
+ die_codec(&codec[i], "Failed to set noise_sensitivity");
+ }
- /* Set the number of token partitions */
- for ( i=0; i<NUM_ENCODERS; i++)
- {
- if(vpx_codec_control(&codec[i], VP8E_SET_TOKEN_PARTITIONS, 1))
- die_codec(&codec[i], "Failed to set static threshold");
- }
+ /* Set the number of token partitions */
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ if (vpx_codec_control(&codec[i], VP8E_SET_TOKEN_PARTITIONS, 1))
+ die_codec(&codec[i], "Failed to set static threshold");
+ }
- /* Set the max intra target bitrate */
- for ( i=0; i<NUM_ENCODERS; i++)
- {
- unsigned int max_intra_size_pct =
- (int)(((double)cfg[0].rc_buf_optimal_sz * 0.5) * framerate / 10);
- if(vpx_codec_control(&codec[i], VP8E_SET_MAX_INTRA_BITRATE_PCT,
- max_intra_size_pct))
- die_codec(&codec[i], "Failed to set static threshold");
- //printf("%d %d \n",i,max_intra_size_pct);
- }
+ /* Set the max intra target bitrate */
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ unsigned int max_intra_size_pct =
+ (int)(((double)cfg[0].rc_buf_optimal_sz * 0.5) * framerate / 10);
+ if (vpx_codec_control(&codec[i], VP8E_SET_MAX_INTRA_BITRATE_PCT,
+ max_intra_size_pct))
+ die_codec(&codec[i], "Failed to set static threshold");
+ // printf("%d %d \n",i,max_intra_size_pct);
+ }
- frame_avail = 1;
- got_data = 0;
+ frame_avail = 1;
+ got_data = 0;
- while(frame_avail || got_data)
- {
- struct vpx_usec_timer timer;
- vpx_codec_iter_t iter[NUM_ENCODERS]={NULL};
- const vpx_codec_cx_pkt_t *pkt[NUM_ENCODERS];
+ while (frame_avail || got_data) {
+ struct vpx_usec_timer timer;
+ vpx_codec_iter_t iter[NUM_ENCODERS] = { NULL };
+ const vpx_codec_cx_pkt_t *pkt[NUM_ENCODERS];
- flags = 0;
- frame_avail = read_frame_p(infile, &raw[0]);
+ flags = 0;
+ frame_avail = read_frame_p(infile, &raw[0]);
- if(frame_avail)
- {
- for ( i=1; i<NUM_ENCODERS; i++)
- {
- /*Scale the image down a number of times by downsampling factor*/
- /* FilterMode 1 or 2 give better psnr than FilterMode 0. */
- I420Scale(raw[i-1].planes[VPX_PLANE_Y], raw[i-1].stride[VPX_PLANE_Y],
- raw[i-1].planes[VPX_PLANE_U], raw[i-1].stride[VPX_PLANE_U],
- raw[i-1].planes[VPX_PLANE_V], raw[i-1].stride[VPX_PLANE_V],
- raw[i-1].d_w, raw[i-1].d_h,
- raw[i].planes[VPX_PLANE_Y], raw[i].stride[VPX_PLANE_Y],
- raw[i].planes[VPX_PLANE_U], raw[i].stride[VPX_PLANE_U],
- raw[i].planes[VPX_PLANE_V], raw[i].stride[VPX_PLANE_V],
- raw[i].d_w, raw[i].d_h, 1);
- /* Write out down-sampled input. */
- length_frame = cfg[i].g_w * cfg[i].g_h *3/2;
- if (fwrite(raw[i].planes[0], 1, length_frame,
- downsampled_input[NUM_ENCODERS - i - 1]) !=
- length_frame)
- {
- return EXIT_FAILURE;
- }
- }
+ if (frame_avail) {
+ for (i = 1; i < NUM_ENCODERS; i++) {
+ /*Scale the image down a number of times by downsampling factor*/
+ /* FilterMode 1 or 2 give better psnr than FilterMode 0. */
+ I420Scale(
+ raw[i - 1].planes[VPX_PLANE_Y], raw[i - 1].stride[VPX_PLANE_Y],
+ raw[i - 1].planes[VPX_PLANE_U], raw[i - 1].stride[VPX_PLANE_U],
+ raw[i - 1].planes[VPX_PLANE_V], raw[i - 1].stride[VPX_PLANE_V],
+ raw[i - 1].d_w, raw[i - 1].d_h, raw[i].planes[VPX_PLANE_Y],
+ raw[i].stride[VPX_PLANE_Y], raw[i].planes[VPX_PLANE_U],
+ raw[i].stride[VPX_PLANE_U], raw[i].planes[VPX_PLANE_V],
+ raw[i].stride[VPX_PLANE_V], raw[i].d_w, raw[i].d_h, 1);
+ /* Write out down-sampled input. */
+ length_frame = cfg[i].g_w * cfg[i].g_h * 3 / 2;
+ if (fwrite(raw[i].planes[0], 1, length_frame,
+ downsampled_input[NUM_ENCODERS - i - 1]) != length_frame) {
+ return EXIT_FAILURE;
}
+ }
+ }
- /* Set the flags (reference and update) for all the encoders.*/
- for ( i=0; i<NUM_ENCODERS; i++)
- {
- layer_id = cfg[i].ts_layer_id[frame_cnt % cfg[i].ts_periodicity];
- flags = 0;
- flag_periodicity = periodicity_to_num_layers
- [num_temporal_layers[i] - 1];
- flags = layer_flags[i * VPX_TS_MAX_PERIODICITY +
- frame_cnt % flag_periodicity];
- // Key frame flag for first frame.
- if (frame_cnt == 0)
- {
- flags |= VPX_EFLAG_FORCE_KF;
- }
- if (frame_cnt > 0 && frame_cnt == key_frame_insert)
- {
- flags = VPX_EFLAG_FORCE_KF;
- }
+ /* Set the flags (reference and update) for all the encoders.*/
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ layer_id = cfg[i].ts_layer_id[frame_cnt % cfg[i].ts_periodicity];
+ flags = 0;
+ flag_periodicity = periodicity_to_num_layers[num_temporal_layers[i] - 1];
+ flags = layer_flags[i * VPX_TS_MAX_PERIODICITY +
+ frame_cnt % flag_periodicity];
+ // Key frame flag for first frame.
+ if (frame_cnt == 0) {
+ flags |= VPX_EFLAG_FORCE_KF;
+ }
+ if (frame_cnt > 0 && frame_cnt == key_frame_insert) {
+ flags = VPX_EFLAG_FORCE_KF;
+ }
- vpx_codec_control(&codec[i], VP8E_SET_FRAME_FLAGS, flags);
- vpx_codec_control(&codec[i], VP8E_SET_TEMPORAL_LAYER_ID, layer_id);
- }
+ vpx_codec_control(&codec[i], VP8E_SET_FRAME_FLAGS, flags);
+ vpx_codec_control(&codec[i], VP8E_SET_TEMPORAL_LAYER_ID, layer_id);
+ }
- /* Encode each frame at multi-levels */
- /* Note the flags must be set to 0 in the encode call if they are set
- for each frame with the vpx_codec_control(), as done above. */
- vpx_usec_timer_start(&timer);
- if(vpx_codec_encode(&codec[0], frame_avail? &raw[0] : NULL,
- frame_cnt, 1, 0, arg_deadline))
- {
- die_codec(&codec[0], "Failed to encode frame");
- }
- vpx_usec_timer_mark(&timer);
- cx_time += vpx_usec_timer_elapsed(&timer);
+ /* Encode each frame at multi-levels */
+ /* Note the flags must be set to 0 in the encode call if they are set
+ for each frame with the vpx_codec_control(), as done above. */
+ vpx_usec_timer_start(&timer);
+ if (vpx_codec_encode(&codec[0], frame_avail ? &raw[0] : NULL, frame_cnt, 1,
+ 0, arg_deadline)) {
+ die_codec(&codec[0], "Failed to encode frame");
+ }
+ vpx_usec_timer_mark(&timer);
+ cx_time += vpx_usec_timer_elapsed(&timer);
- for (i=NUM_ENCODERS-1; i>=0 ; i--)
- {
- got_data = 0;
- while( (pkt[i] = vpx_codec_get_cx_data(&codec[i], &iter[i])) )
- {
- got_data = 1;
- switch(pkt[i]->kind) {
- case VPX_CODEC_CX_FRAME_PKT:
- write_ivf_frame_header(outfile[i], pkt[i]);
- (void) fwrite(pkt[i]->data.frame.buf, 1,
- pkt[i]->data.frame.sz, outfile[i]);
- break;
- case VPX_CODEC_PSNR_PKT:
- if (show_psnr)
- {
- int j;
+ for (i = NUM_ENCODERS - 1; i >= 0; i--) {
+ got_data = 0;
+ while ((pkt[i] = vpx_codec_get_cx_data(&codec[i], &iter[i]))) {
+ got_data = 1;
+ switch (pkt[i]->kind) {
+ case VPX_CODEC_CX_FRAME_PKT:
+ write_ivf_frame_header(outfile[i], pkt[i]);
+ (void)fwrite(pkt[i]->data.frame.buf, 1, pkt[i]->data.frame.sz,
+ outfile[i]);
+ break;
+ case VPX_CODEC_PSNR_PKT:
+ if (show_psnr) {
+ int j;
- psnr_sse_total[i] += pkt[i]->data.psnr.sse[0];
- psnr_samples_total[i] += pkt[i]->data.psnr.samples[0];
- for (j = 0; j < 4; j++)
- {
- psnr_totals[i][j] += pkt[i]->data.psnr.psnr[j];
- }
- psnr_count[i]++;
- }
+ psnr_sse_total[i] += pkt[i]->data.psnr.sse[0];
+ psnr_samples_total[i] += pkt[i]->data.psnr.samples[0];
+ for (j = 0; j < 4; j++) {
+ psnr_totals[i][j] += pkt[i]->data.psnr.psnr[j];
+ }
+ psnr_count[i]++;
+ }
- break;
- default:
- break;
- }
- printf(pkt[i]->kind == VPX_CODEC_CX_FRAME_PKT
- && (pkt[i]->data.frame.flags & VPX_FRAME_IS_KEY)? "K":"");
- fflush(stdout);
- }
+ break;
+ default: break;
}
- frame_cnt++;
+ printf(pkt[i]->kind == VPX_CODEC_CX_FRAME_PKT &&
+ (pkt[i]->data.frame.flags & VPX_FRAME_IS_KEY)
+ ? "K"
+ : "");
+ fflush(stdout);
+ }
}
- printf("\n");
- printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
- frame_cnt,
- 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
- 1000000 * (double)frame_cnt / (double)cx_time);
+ frame_cnt++;
+ }
+ printf("\n");
+ printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
+ frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
+ 1000000 * (double)frame_cnt / (double)cx_time);
- fclose(infile);
+ fclose(infile);
- printf("Processed %ld frames.\n",(long int)frame_cnt-1);
- for (i=0; i< NUM_ENCODERS; i++)
- {
- /* Calculate PSNR and print it out */
- if ( (show_psnr) && (psnr_count[i]>0) )
- {
- int j;
- double ovpsnr = sse_to_psnr(psnr_samples_total[i], 255.0,
- psnr_sse_total[i]);
+ printf("Processed %ld frames.\n", (long int)frame_cnt - 1);
+ for (i = 0; i < NUM_ENCODERS; i++) {
+ /* Calculate PSNR and print it out */
+ if ((show_psnr) && (psnr_count[i] > 0)) {
+ int j;
+ double ovpsnr =
+ sse_to_psnr(psnr_samples_total[i], 255.0, psnr_sse_total[i]);
- fprintf(stderr, "\n ENC%d PSNR (Overall/Avg/Y/U/V)", i);
+ fprintf(stderr, "\n ENC%d PSNR (Overall/Avg/Y/U/V)", i);
- fprintf(stderr, " %.3lf", ovpsnr);
- for (j = 0; j < 4; j++)
- {
- fprintf(stderr, " %.3lf", psnr_totals[i][j]/psnr_count[i]);
- }
- }
+ fprintf(stderr, " %.3lf", ovpsnr);
+ for (j = 0; j < 4; j++) {
+ fprintf(stderr, " %.3lf", psnr_totals[i][j] / psnr_count[i]);
+ }
+ }
- if(vpx_codec_destroy(&codec[i]))
- die_codec(&codec[i], "Failed to destroy codec");
+ if (vpx_codec_destroy(&codec[i]))
+ die_codec(&codec[i], "Failed to destroy codec");
- vpx_img_free(&raw[i]);
+ vpx_img_free(&raw[i]);
- if(!outfile[i])
- continue;
+ if (!outfile[i]) continue;
- /* Try to rewrite the file header with the actual frame count */
- if(!fseek(outfile[i], 0, SEEK_SET))
- write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1);
- fclose(outfile[i]);
- }
- printf("\n");
+ /* Try to rewrite the file header with the actual frame count */
+ if (!fseek(outfile[i], 0, SEEK_SET))
+ write_ivf_file_header(outfile[i], &cfg[i], frame_cnt - 1);
+ fclose(outfile[i]);
+ }
+ printf("\n");
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
--- a/examples/vp8cx_set_ref.c
+++ b/examples/vp8cx_set_ref.c
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
// VP8 Set Reference Frame
// =======================
//
@@ -64,17 +63,14 @@
exit(EXIT_FAILURE);
}
-static int encode_frame(vpx_codec_ctx_t *codec,
- vpx_image_t *img,
- int frame_index,
- VpxVideoWriter *writer) {
+static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
+ int frame_index, VpxVideoWriter *writer) {
int got_pkts = 0;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
- const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0,
- VPX_DL_GOOD_QUALITY);
- if (res != VPX_CODEC_OK)
- die_codec(codec, "Failed to encode frame");
+ const vpx_codec_err_t res =
+ vpx_codec_encode(codec, img, frame_index, 1, 0, VPX_DL_GOOD_QUALITY);
+ if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1;
@@ -81,8 +77,7 @@
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
- if (!vpx_video_writer_write_frame(writer,
- pkt->data.frame.buf,
+ if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
pkt->data.frame.sz,
pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame");
@@ -98,31 +93,28 @@
int main(int argc, char **argv) {
FILE *infile = NULL;
- vpx_codec_ctx_t codec = {0};
- vpx_codec_enc_cfg_t cfg = {0};
+ vpx_codec_ctx_t codec = { 0 };
+ vpx_codec_enc_cfg_t cfg = { 0 };
int frame_count = 0;
vpx_image_t raw;
vpx_codec_err_t res;
- VpxVideoInfo info = {0};
+ VpxVideoInfo info = { 0 };
VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL;
int update_frame_num = 0;
- const int fps = 30; // TODO(dkovalev) add command line argument
- const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
+ const int fps = 30; // TODO(dkovalev) add command line argument
+ const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
exec_name = argv[0];
- if (argc != 6)
- die("Invalid number of arguments");
+ if (argc != 6) die("Invalid number of arguments");
// TODO(dkovalev): add vp9 support and rename the file accordingly
encoder = get_vpx_encoder_by_name("vp8");
- if (!encoder)
- die("Unsupported codec.");
+ if (!encoder) die("Unsupported codec.");
update_frame_num = atoi(argv[5]);
- if (!update_frame_num)
- die("Couldn't parse frame number '%s'\n", argv[5]);
+ if (!update_frame_num) die("Couldn't parse frame number '%s'\n", argv[5]);
info.codec_fourcc = encoder->fourcc;
info.frame_width = strtol(argv[1], NULL, 0);
@@ -130,15 +122,13 @@
info.time_base.numerator = 1;
info.time_base.denominator = fps;
- if (info.frame_width <= 0 ||
- info.frame_height <= 0 ||
- (info.frame_width % 2) != 0 ||
- (info.frame_height % 2) != 0) {
+ if (info.frame_width <= 0 || info.frame_height <= 0 ||
+ (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
}
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
- info.frame_height, 1)) {
+ info.frame_height, 1)) {
die("Failed to allocate image.");
}
@@ -145,8 +135,7 @@
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
- if (res)
- die_codec(&codec, "Failed to get default codec config.");
+ if (res) die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height;
@@ -155,8 +144,7 @@
cfg.rc_target_bitrate = bitrate;
writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
- if (!writer)
- die("Failed to open %s for writing.", argv[4]);
+ if (!writer) die("Failed to open %s for writing.", argv[4]);
if (!(infile = fopen(argv[3], "rb")))
die("Failed to open %s for reading.", argv[3]);
@@ -178,7 +166,8 @@
}
// Flush encoder.
- while (encode_frame(&codec, NULL, -1, writer)) {}
+ while (encode_frame(&codec, NULL, -1, writer)) {
+ }
printf("\n");
fclose(infile);
@@ -185,8 +174,7 @@
printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer);
--- a/examples/vp9_lossless_encoder.c
+++ b/examples/vp9_lossless_encoder.c
@@ -21,24 +21,21 @@
static const char *exec_name;
void usage_exit(void) {
- fprintf(stderr, "vp9_lossless_encoder: Example demonstrating VP9 lossless "
- "encoding feature. Supports raw input only.\n");
+ fprintf(stderr,
+ "vp9_lossless_encoder: Example demonstrating VP9 lossless "
+ "encoding feature. Supports raw input only.\n");
fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile>\n", exec_name);
exit(EXIT_FAILURE);
}
-static int encode_frame(vpx_codec_ctx_t *codec,
- vpx_image_t *img,
- int frame_index,
- int flags,
- VpxVideoWriter *writer) {
+static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
+ int frame_index, int flags, VpxVideoWriter *writer) {
int got_pkts = 0;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
- const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1,
- flags, VPX_DL_GOOD_QUALITY);
- if (res != VPX_CODEC_OK)
- die_codec(codec, "Failed to encode frame");
+ const vpx_codec_err_t res =
+ vpx_codec_encode(codec, img, frame_index, 1, flags, VPX_DL_GOOD_QUALITY);
+ if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
got_pkts = 1;
@@ -45,8 +42,7 @@
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
- if (!vpx_video_writer_write_frame(writer,
- pkt->data.frame.buf,
+ if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
pkt->data.frame.sz,
pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame");
@@ -66,7 +62,7 @@
int frame_count = 0;
vpx_image_t raw;
vpx_codec_err_t res;
- VpxVideoInfo info = {0};
+ VpxVideoInfo info = { 0 };
VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL;
const int fps = 30;
@@ -73,12 +69,10 @@
exec_name = argv[0];
- if (argc < 5)
- die("Invalid number of arguments");
+ if (argc < 5) die("Invalid number of arguments");
encoder = get_vpx_encoder_by_name("vp9");
- if (!encoder)
- die("Unsupported codec.");
+ if (!encoder) die("Unsupported codec.");
info.codec_fourcc = encoder->fourcc;
info.frame_width = strtol(argv[1], NULL, 0);
@@ -86,15 +80,13 @@
info.time_base.numerator = 1;
info.time_base.denominator = fps;
- if (info.frame_width <= 0 ||
- info.frame_height <= 0 ||
- (info.frame_width % 2) != 0 ||
- (info.frame_height % 2) != 0) {
+ if (info.frame_width <= 0 || info.frame_height <= 0 ||
+ (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
}
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
- info.frame_height, 1)) {
+ info.frame_height, 1)) {
die("Failed to allocate image.");
}
@@ -101,8 +93,7 @@
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
- if (res)
- die_codec(&codec, "Failed to get default codec config.");
+ if (res) die_codec(&codec, "Failed to get default codec config.");
cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height;
@@ -110,8 +101,7 @@
cfg.g_timebase.den = info.time_base.denominator;
writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
- if (!writer)
- die("Failed to open %s for writing.", argv[4]);
+ if (!writer) die("Failed to open %s for writing.", argv[4]);
if (!(infile = fopen(argv[3], "rb")))
die("Failed to open %s for reading.", argv[3]);
@@ -128,7 +118,8 @@
}
// Flush encoder.
- while (encode_frame(&codec, NULL, -1, 0, writer)) {}
+ while (encode_frame(&codec, NULL, -1, 0, writer)) {
+ }
printf("\n");
fclose(infile);
@@ -135,8 +126,7 @@
printf("Processed %d frames.\n", frame_count);
vpx_img_free(&raw);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec.");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
vpx_video_writer_close(writer);
--- a/examples/vp9_spatial_svc_encoder.c
+++ b/examples/vp9_spatial_svc_encoder.c
@@ -20,7 +20,6 @@
#include <string.h>
#include <time.h>
-
#include "../args.h"
#include "../tools_common.h"
#include "../video_writer.h"
@@ -54,8 +53,9 @@
static const arg_def_t temporal_layers_arg =
ARG_DEF("tl", "temporal-layers", 1, "number of temporal SVC layers");
static const arg_def_t temporal_layering_mode_arg =
- ARG_DEF("tlm", "temporal-layering-mode", 1, "temporal layering scheme."
- "VP9E_TEMPORAL_LAYERING_MODE");
+ ARG_DEF("tlm", "temporal-layering-mode", 1,
+ "temporal layering scheme."
+ "VP9E_TEMPORAL_LAYERING_MODE");
static const arg_def_t kf_dist_arg =
ARG_DEF("k", "kf-dist", 1, "number of frames between keyframes");
static const arg_def_t scale_factors_arg =
@@ -75,8 +75,9 @@
static const arg_def_t max_bitrate_arg =
ARG_DEF(NULL, "max-bitrate", 1, "Maximum bitrate");
static const arg_def_t lag_in_frame_arg =
- ARG_DEF(NULL, "lag-in-frames", 1, "Number of frame to input before "
- "generating any outputs");
+ ARG_DEF(NULL, "lag-in-frames", 1,
+ "Number of frame to input before "
+ "generating any outputs");
static const arg_def_t rc_end_usage_arg =
ARG_DEF(NULL, "rc-end-usage", 1, "0 - 3: VBR, CBR, CQ, Q");
static const arg_def_t speed_arg =
@@ -86,35 +87,44 @@
#if CONFIG_VP9_HIGHBITDEPTH
static const struct arg_enum_list bitdepth_enum[] = {
- {"8", VPX_BITS_8},
- {"10", VPX_BITS_10},
- {"12", VPX_BITS_12},
- {NULL, 0}
+ { "8", VPX_BITS_8 }, { "10", VPX_BITS_10 }, { "12", VPX_BITS_12 }, { NULL, 0 }
};
-static const arg_def_t bitdepth_arg =
- ARG_DEF_ENUM("d", "bit-depth", 1, "Bit depth for codec 8, 10 or 12. ",
- bitdepth_enum);
+static const arg_def_t bitdepth_arg = ARG_DEF_ENUM(
+ "d", "bit-depth", 1, "Bit depth for codec 8, 10 or 12. ", bitdepth_enum);
#endif // CONFIG_VP9_HIGHBITDEPTH
-
-static const arg_def_t *svc_args[] = {
- &frames_arg, &width_arg, &height_arg,
- &timebase_arg, &bitrate_arg, &skip_frames_arg, &spatial_layers_arg,
- &kf_dist_arg, &scale_factors_arg, &passes_arg, &pass_arg,
- &fpf_name_arg, &min_q_arg, &max_q_arg, &min_bitrate_arg,
- &max_bitrate_arg, &temporal_layers_arg, &temporal_layering_mode_arg,
- &lag_in_frame_arg, &threads_arg, &aqmode_arg,
+static const arg_def_t *svc_args[] = { &frames_arg,
+ &width_arg,
+ &height_arg,
+ &timebase_arg,
+ &bitrate_arg,
+ &skip_frames_arg,
+ &spatial_layers_arg,
+ &kf_dist_arg,
+ &scale_factors_arg,
+ &passes_arg,
+ &pass_arg,
+ &fpf_name_arg,
+ &min_q_arg,
+ &max_q_arg,
+ &min_bitrate_arg,
+ &max_bitrate_arg,
+ &temporal_layers_arg,
+ &temporal_layering_mode_arg,
+ &lag_in_frame_arg,
+ &threads_arg,
+ &aqmode_arg,
#if OUTPUT_RC_STATS
- &output_rc_stats_arg,
+ &output_rc_stats_arg,
#endif
#if CONFIG_VP9_HIGHBITDEPTH
- &bitdepth_arg,
+ &bitdepth_arg,
#endif
- &speed_arg,
- &rc_end_usage_arg, NULL
-};
+ &speed_arg,
+ &rc_end_usage_arg,
+ NULL };
static const uint32_t default_frames_to_skip = 0;
static const uint32_t default_frames_to_code = 60 * 60;
@@ -128,7 +138,7 @@
static const uint32_t default_kf_dist = 100;
static const uint32_t default_temporal_layering_mode = 0;
static const uint32_t default_output_rc_stats = 0;
-static const int32_t default_speed = -1; // -1 means use library default.
+static const int32_t default_speed = -1; // -1 means use library default.
static const uint32_t default_threads = 0; // zero means use library default.
typedef struct {
@@ -155,7 +165,7 @@
static void parse_command_line(int argc, const char **argv_,
AppInput *app_input, SvcContext *svc_ctx,
vpx_codec_enc_cfg_t *enc_cfg) {
- struct arg arg = {0};
+ struct arg arg = { 0 };
char **argv = NULL;
char **argi = NULL;
char **argj = NULL;
@@ -165,7 +175,7 @@
const char *fpf_file_name = NULL;
unsigned int min_bitrate = 0;
unsigned int max_bitrate = 0;
- char string_options[1024] = {0};
+ char string_options[1024] = { 0 };
// initialize SvcContext with parameters that will be passed to vpx_svc_init
svc_ctx->log_level = SVC_LOG_DEBUG;
@@ -229,8 +239,8 @@
} else if (arg_match(&arg, &threads_arg, argi)) {
svc_ctx->threads = arg_parse_uint(&arg);
} else if (arg_match(&arg, &temporal_layering_mode_arg, argi)) {
- svc_ctx->temporal_layering_mode =
- enc_cfg->temporal_layering_mode = arg_parse_int(&arg);
+ svc_ctx->temporal_layering_mode = enc_cfg->temporal_layering_mode =
+ arg_parse_int(&arg);
if (svc_ctx->temporal_layering_mode) {
enc_cfg->g_error_resilient = 1;
}
@@ -278,7 +288,7 @@
enc_cfg->g_input_bit_depth = 10;
enc_cfg->g_profile = 2;
break;
- case VPX_BITS_12:
+ case VPX_BITS_12:
enc_cfg->g_input_bit_depth = 12;
enc_cfg->g_profile = 2;
break;
@@ -360,9 +370,8 @@
"num: %d, den: %d, bitrate: %d,\n"
"gop size: %d\n",
vpx_codec_iface_name(vpx_codec_vp9_cx()), app_input->frames_to_code,
- app_input->frames_to_skip,
- svc_ctx->spatial_layers, enc_cfg->g_w, enc_cfg->g_h,
- enc_cfg->g_timebase.num, enc_cfg->g_timebase.den,
+ app_input->frames_to_skip, svc_ctx->spatial_layers, enc_cfg->g_w,
+ enc_cfg->g_h, enc_cfg->g_timebase.num, enc_cfg->g_timebase.den,
enc_cfg->rc_target_bitrate, enc_cfg->kf_max_dist);
}
@@ -399,7 +408,7 @@
// Note: these rate control stats assume only 1 key frame in the
// sequence (i.e., first frame only).
static void set_rate_control_stats(struct RateControlStats *rc,
- vpx_codec_enc_cfg_t *cfg) {
+ vpx_codec_enc_cfg_t *cfg) {
unsigned int sl, tl;
// Set the layer (cumulative) framerate and the target layer (non-cumulative)
// per-frame-bandwidth, for the rate control encoding stats below.
@@ -412,18 +421,15 @@
if (cfg->ts_number_layers == 1)
rc->layer_framerate[layer] = framerate;
else
- rc->layer_framerate[layer] =
- framerate / cfg->ts_rate_decimator[tl];
+ rc->layer_framerate[layer] = framerate / cfg->ts_rate_decimator[tl];
if (tl > 0) {
- rc->layer_pfb[layer] = 1000.0 *
- (cfg->layer_target_bitrate[layer] -
- cfg->layer_target_bitrate[layer - 1]) /
- (rc->layer_framerate[layer] -
- rc->layer_framerate[layer - 1]);
+ rc->layer_pfb[layer] =
+ 1000.0 * (cfg->layer_target_bitrate[layer] -
+ cfg->layer_target_bitrate[layer - 1]) /
+ (rc->layer_framerate[layer] - rc->layer_framerate[layer - 1]);
} else {
- rc->layer_pfb[tlayer0] = 1000.0 *
- cfg->layer_target_bitrate[tlayer0] /
- rc->layer_framerate[tlayer0];
+ rc->layer_pfb[tlayer0] = 1000.0 * cfg->layer_target_bitrate[tlayer0] /
+ rc->layer_framerate[tlayer0];
}
rc->layer_input_frames[layer] = 0;
rc->layer_enc_frames[layer] = 0;
@@ -447,22 +453,24 @@
double perc_fluctuation = 0.0;
printf("Total number of processed frames: %d\n\n", frame_cnt - 1);
printf("Rate control layer stats for sl%d tl%d layer(s):\n\n",
- cfg->ss_number_layers, cfg->ts_number_layers);
+ cfg->ss_number_layers, cfg->ts_number_layers);
for (sl = 0; sl < cfg->ss_number_layers; ++sl) {
for (tl = 0; tl < cfg->ts_number_layers; ++tl) {
const int layer = sl * cfg->ts_number_layers + tl;
- const int num_dropped = (tl > 0) ?
- (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer]) :
- (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer] - 1);
- if (!sl)
- tot_num_frames += rc->layer_input_frames[layer];
+ const int num_dropped =
+ (tl > 0)
+ ? (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer])
+ : (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer] -
+ 1);
+ if (!sl) tot_num_frames += rc->layer_input_frames[layer];
rc->layer_encoding_bitrate[layer] = 0.001 * rc->layer_framerate[layer] *
- rc->layer_encoding_bitrate[layer] / tot_num_frames;
- rc->layer_avg_frame_size[layer] = rc->layer_avg_frame_size[layer] /
- rc->layer_enc_frames[layer];
- rc->layer_avg_rate_mismatch[layer] =
- 100.0 * rc->layer_avg_rate_mismatch[layer] /
- rc->layer_enc_frames[layer];
+ rc->layer_encoding_bitrate[layer] /
+ tot_num_frames;
+ rc->layer_avg_frame_size[layer] =
+ rc->layer_avg_frame_size[layer] / rc->layer_enc_frames[layer];
+ rc->layer_avg_rate_mismatch[layer] = 100.0 *
+ rc->layer_avg_rate_mismatch[layer] /
+ rc->layer_enc_frames[layer];
printf("For layer#: sl%d tl%d \n", sl, tl);
printf("Bitrate (target vs actual): %d %f.0 kbps\n",
cfg->layer_target_bitrate[layer],
@@ -469,9 +477,9 @@
rc->layer_encoding_bitrate[layer]);
printf("Average frame size (target vs actual): %f %f bits\n",
rc->layer_pfb[layer], rc->layer_avg_frame_size[layer]);
- printf("Average rate_mismatch: %f\n",
- rc->layer_avg_rate_mismatch[layer]);
- printf("Number of input frames, encoded (non-key) frames, "
+ printf("Average rate_mismatch: %f\n", rc->layer_avg_rate_mismatch[layer]);
+ printf(
+ "Number of input frames, encoded (non-key) frames, "
"and percent dropped frames: %d %d %f.0 \n",
rc->layer_input_frames[layer], rc->layer_enc_frames[layer],
100.0 * num_dropped / rc->layer_input_frames[layer]);
@@ -483,19 +491,19 @@
rc->variance_st_encoding_bitrate / rc->window_count -
(rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
- rc->avg_st_encoding_bitrate;
+ rc->avg_st_encoding_bitrate;
printf("Short-time stats, for window of %d frames: \n", rc->window_size);
printf("Average, rms-variance, and percent-fluct: %f %f %f \n",
- rc->avg_st_encoding_bitrate,
- sqrt(rc->variance_st_encoding_bitrate),
+ rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
perc_fluctuation);
if (frame_cnt != tot_num_frames)
- die("Error: Number of input frames not equal to output encoded frames != "
- "%d tot_num_frames = %d\n", frame_cnt, tot_num_frames);
+ die(
+ "Error: Number of input frames not equal to output encoded frames != "
+ "%d tot_num_frames = %d\n",
+ frame_cnt, tot_num_frames);
}
-vpx_codec_err_t parse_superframe_index(const uint8_t *data,
- size_t data_sz,
+vpx_codec_err_t parse_superframe_index(const uint8_t *data, size_t data_sz,
uint32_t sizes[8], int *count) {
// A chunk ending with a byte matching 0xc0 is an invalid chunk unless
// it is a super frame index. If the last byte of real video compression
@@ -508,7 +516,6 @@
marker = *(data + data_sz - 1);
*count = 0;
-
if ((marker & 0xe0) == 0xc0) {
const uint32_t frames = (marker & 0x7) + 1;
const uint32_t mag = ((marker >> 3) & 0x3) + 1;
@@ -516,8 +523,7 @@
// This chunk is marked as having a superframe index but doesn't have
// enough data for it, thus it's an invalid superframe index.
- if (data_sz < index_sz)
- return VPX_CODEC_CORRUPT_FRAME;
+ if (data_sz < index_sz) return VPX_CODEC_CORRUPT_FRAME;
{
const uint8_t marker2 = *(data + data_sz - index_sz);
@@ -525,8 +531,7 @@
// This chunk is marked as having a superframe index but doesn't have
// the matching marker byte at the front of the index therefore it's an
// invalid chunk.
- if (marker != marker2)
- return VPX_CODEC_CORRUPT_FRAME;
+ if (marker != marker2) return VPX_CODEC_CORRUPT_FRAME;
}
{
@@ -537,8 +542,7 @@
for (i = 0; i < frames; ++i) {
uint32_t this_sz = 0;
- for (j = 0; j < mag; ++j)
- this_sz |= (*x++) << (j * 8);
+ for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
sizes[i] = this_sz;
}
*count = frames;
@@ -558,32 +562,27 @@
for (sl = 0; sl < num_spatial_layers; ++sl) {
if (!tl) {
if (!sl) {
- ref_frame_config->frame_flags[sl] = VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ ref_frame_config->frame_flags[sl] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
} else {
if (is_key_frame) {
- ref_frame_config->frame_flags[sl] = VP8_EFLAG_NO_REF_LAST |
- VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ ref_frame_config->frame_flags[sl] =
+ VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_ARF |
+ VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
} else {
- ref_frame_config->frame_flags[sl] = VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ ref_frame_config->frame_flags[sl] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
}
}
} else if (tl == 1) {
if (!sl) {
- ref_frame_config->frame_flags[sl] = VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_GF;
+ ref_frame_config->frame_flags[sl] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST |
+ VP8_EFLAG_NO_UPD_GF;
} else {
- ref_frame_config->frame_flags[sl] = VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_GF;
+ ref_frame_config->frame_flags[sl] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
}
}
if (tl == 0) {
@@ -602,9 +601,9 @@
}
int main(int argc, const char **argv) {
- AppInput app_input = {0};
+ AppInput app_input = { 0 };
VpxVideoWriter *writer = NULL;
- VpxVideoInfo info = {0};
+ VpxVideoInfo info = { 0 };
vpx_codec_ctx_t codec;
vpx_codec_enc_cfg_t enc_cfg;
SvcContext svc_ctx;
@@ -618,7 +617,7 @@
int end_of_stream = 0;
int frames_received = 0;
#if OUTPUT_RC_STATS
- VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS] = {NULL};
+ VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS] = { NULL };
struct RateControlStats rc;
vpx_svc_layer_id_t layer_id;
vpx_svc_ref_frame_config_t ref_frame_config;
@@ -625,7 +624,7 @@
int sl, tl;
double sum_bitrate = 0.0;
double sum_bitrate2 = 0.0;
- double framerate = 30.0;
+ double framerate = 30.0;
#endif
struct vpx_usec_timer timer;
int64_t cx_time = 0;
@@ -634,10 +633,10 @@
exec_name = argv[0];
parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
- // Allocate image buffer
+// Allocate image buffer
#if CONFIG_VP9_HIGHBITDEPTH
- if (!vpx_img_alloc(&raw, enc_cfg.g_input_bit_depth == 8 ?
- VPX_IMG_FMT_I420 : VPX_IMG_FMT_I42016,
+ if (!vpx_img_alloc(&raw, enc_cfg.g_input_bit_depth == 8 ? VPX_IMG_FMT_I420
+ : VPX_IMG_FMT_I42016,
enc_cfg.g_w, enc_cfg.g_h, 32)) {
die("Failed to allocate image %dx%d\n", enc_cfg.g_w, enc_cfg.g_h);
}
@@ -668,8 +667,8 @@
if (!(app_input.passes == 2 && app_input.pass == 1)) {
// We don't save the bitstream for the 1st pass on two pass rate control
- writer = vpx_video_writer_open(app_input.output_filename, kContainerIVF,
- &info);
+ writer =
+ vpx_video_writer_open(app_input.output_filename, kContainerIVF, &info);
if (!writer)
die("Failed to open %s for writing\n", app_input.output_filename);
}
@@ -683,15 +682,13 @@
snprintf(file_name, sizeof(file_name), "%s_t%d.ivf",
app_input.output_filename, tl);
outfile[tl] = vpx_video_writer_open(file_name, kContainerIVF, &info);
- if (!outfile[tl])
- die("Failed to open %s for writing", file_name);
+ if (!outfile[tl]) die("Failed to open %s for writing", file_name);
}
}
#endif
// skip initial frames
- for (i = 0; i < app_input.frames_to_skip; ++i)
- vpx_img_read(&raw, infile);
+ for (i = 0; i < app_input.frames_to_skip; ++i) vpx_img_read(&raw, infile);
if (svc_ctx.speed != -1)
vpx_codec_control(&codec, VP8E_SET_CPUUSED, svc_ctx.speed);
@@ -700,7 +697,6 @@
if (svc_ctx.speed >= 5 && svc_ctx.aqmode == 1)
vpx_codec_control(&codec, VP9E_SET_AQ_MODE, 3);
-
// Encode frames
while (!end_of_stream) {
vpx_codec_iter_t iter = NULL;
@@ -729,8 +725,7 @@
// over all the spatial layers for the current superframe.
vpx_codec_control(&codec, VP9E_SET_SVC_LAYER_ID, &layer_id);
set_frame_flags_bypass_mode(sl, layer_id.temporal_layer_id,
- svc_ctx.spatial_layers,
- frame_cnt == 0,
+ svc_ctx.spatial_layers, frame_cnt == 0,
&ref_frame_config);
vpx_codec_control(&codec, VP9E_SET_SVC_REF_FRAME_CONFIG,
&ref_frame_config);
@@ -743,9 +738,9 @@
}
vpx_usec_timer_start(&timer);
- res = vpx_svc_encode(&svc_ctx, &codec, (end_of_stream ? NULL : &raw),
- pts, frame_duration, svc_ctx.speed >= 5 ?
- VPX_DL_REALTIME : VPX_DL_GOOD_QUALITY);
+ res = vpx_svc_encode(
+ &svc_ctx, &codec, (end_of_stream ? NULL : &raw), pts, frame_duration,
+ svc_ctx.speed >= 5 ? VPX_DL_REALTIME : VPX_DL_GOOD_QUALITY);
vpx_usec_timer_mark(&timer);
cx_time += vpx_usec_timer_elapsed(&timer);
@@ -764,8 +759,7 @@
uint32_t sizes[8];
int count = 0;
#endif
- vpx_video_writer_write_frame(writer,
- cx_pkt->data.frame.buf,
+ vpx_video_writer_write_frame(writer, cx_pkt->data.frame.buf,
cx_pkt->data.frame.sz,
cx_pkt->data.frame.pts);
#if OUTPUT_RC_STATS
@@ -782,20 +776,19 @@
VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
++rc.layer_input_frames[sl * enc_cfg.ts_number_layers +
- layer_id.temporal_layer_id];
+ layer_id.temporal_layer_id];
}
}
for (tl = layer_id.temporal_layer_id;
- tl < enc_cfg.ts_number_layers; ++tl) {
- vpx_video_writer_write_frame(outfile[tl],
- cx_pkt->data.frame.buf,
- cx_pkt->data.frame.sz,
- cx_pkt->data.frame.pts);
+ tl < enc_cfg.ts_number_layers; ++tl) {
+ vpx_video_writer_write_frame(
+ outfile[tl], cx_pkt->data.frame.buf, cx_pkt->data.frame.sz,
+ cx_pkt->data.frame.pts);
}
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
for (tl = layer_id.temporal_layer_id;
- tl < enc_cfg.ts_number_layers; ++tl) {
+ tl < enc_cfg.ts_number_layers; ++tl) {
const int layer = sl * enc_cfg.ts_number_layers + tl;
++rc.layer_tot_enc_frames[layer];
rc.layer_encoding_bitrate[layer] += 8.0 * sizes[sl];
@@ -832,20 +825,20 @@
// Second shifted window.
if (frame_cnt > rc.window_size + rc.window_size / 2) {
- tl = layer_id.temporal_layer_id;
- for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
- sum_bitrate2 += 0.001 * 8.0 * sizes[sl] * framerate;
- }
+ tl = layer_id.temporal_layer_id;
+ for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
+ sum_bitrate2 += 0.001 * 8.0 * sizes[sl] * framerate;
+ }
- if (frame_cnt > 2 * rc.window_size &&
- frame_cnt % rc.window_size == 0) {
- rc.window_count += 1;
- rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
- rc.variance_st_encoding_bitrate +=
- (sum_bitrate2 / rc.window_size) *
- (sum_bitrate2 / rc.window_size);
- sum_bitrate2 = 0.0;
- }
+ if (frame_cnt > 2 * rc.window_size &&
+ frame_cnt % rc.window_size == 0) {
+ rc.window_count += 1;
+ rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
+ rc.variance_st_encoding_bitrate +=
+ (sum_bitrate2 / rc.window_size) *
+ (sum_bitrate2 / rc.window_size);
+ sum_bitrate2 = 0.0;
+ }
}
}
#endif
@@ -860,14 +853,11 @@
break;
}
case VPX_CODEC_STATS_PKT: {
- stats_write(&app_input.rc_stats,
- cx_pkt->data.twopass_stats.buf,
+ stats_write(&app_input.rc_stats, cx_pkt->data.twopass_stats.buf,
cx_pkt->data.twopass_stats.sz);
break;
}
- default: {
- break;
- }
+ default: { break; }
}
}
@@ -880,8 +870,8 @@
// Compensate for the extra frame count for the bypass mode.
if (svc_ctx.temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
- const int layer = sl * enc_cfg.ts_number_layers +
- layer_id.temporal_layer_id;
+ const int layer =
+ sl * enc_cfg.ts_number_layers + layer_id.temporal_layer_id;
--rc.layer_input_frames[layer];
}
}
@@ -895,8 +885,7 @@
}
#endif
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
- if (app_input.passes == 2)
- stats_close(&app_input.rc_stats, 1);
+ if (app_input.passes == 2) stats_close(&app_input.rc_stats, 1);
if (writer) {
vpx_video_writer_close(writer);
}
@@ -908,8 +897,7 @@
}
#endif
printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
- frame_cnt,
- 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
+ frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
1000000 * (double)frame_cnt / (double)cx_time);
vpx_img_free(&raw);
// display average size, psnr
--- a/examples/vp9cx_set_ref.c
+++ b/examples/vp9cx_set_ref.c
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
// VP9 Set Reference Frame
// ============================
//
@@ -61,7 +60,8 @@
static const char *exec_name;
void usage_exit() {
- fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile> "
+ fprintf(stderr,
+ "Usage: %s <width> <height> <infile> <outfile> "
"<frame> <limit(optional)>\n",
exec_name);
exit(EXIT_FAILURE);
@@ -70,8 +70,7 @@
static int compare_img(const vpx_image_t *const img1,
const vpx_image_t *const img2) {
uint32_t l_w = img1->d_w;
- uint32_t c_w =
- (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift;
+ uint32_t c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift;
const uint32_t c_h =
(img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift;
uint32_t i;
@@ -99,10 +98,10 @@
return match;
}
-#define mmin(a, b) ((a) < (b) ? (a) : (b))
+#define mmin(a, b) ((a) < (b) ? (a) : (b))
static void find_mismatch(const vpx_image_t *const img1,
- const vpx_image_t *const img2,
- int yloc[4], int uloc[4], int vloc[4]) {
+ const vpx_image_t *const img2, int yloc[4],
+ int uloc[4], int vloc[4]) {
const uint32_t bsize = 64;
const uint32_t bsizey = bsize >> img1->y_chroma_shift;
const uint32_t bsizex = bsize >> img1->x_chroma_shift;
@@ -190,21 +189,18 @@
}
}
-static void testing_decode(vpx_codec_ctx_t *encoder,
- vpx_codec_ctx_t *decoder,
- vpx_codec_enc_cfg_t *cfg,
- unsigned int frame_out,
+static void testing_decode(vpx_codec_ctx_t *encoder, vpx_codec_ctx_t *decoder,
+ vpx_codec_enc_cfg_t *cfg, unsigned int frame_out,
int *mismatch_seen) {
vpx_image_t enc_img, dec_img;
struct vp9_ref_frame ref_enc, ref_dec;
- if (*mismatch_seen)
- return;
+ if (*mismatch_seen) return;
ref_enc.idx = 0;
ref_dec.idx = 0;
if (vpx_codec_control(encoder, VP9_GET_REFERENCE, &ref_enc))
- die_codec(encoder, "Failed to get encoder reference frame");
+ die_codec(encoder, "Failed to get encoder reference frame");
enc_img = ref_enc.img;
if (vpx_codec_control(decoder, VP9_GET_REFERENCE, &ref_dec))
die_codec(decoder, "Failed to get decoder reference frame");
@@ -216,14 +212,13 @@
*mismatch_seen = 1;
find_mismatch(&enc_img, &dec_img, y, u, v);
- printf("Encode/decode mismatch on frame %d at"
- " Y[%d, %d] {%d/%d},"
- " U[%d, %d] {%d/%d},"
- " V[%d, %d] {%d/%d}",
- frame_out,
- y[0], y[1], y[2], y[3],
- u[0], u[1], u[2], u[3],
- v[0], v[1], v[2], v[3]);
+ printf(
+ "Encode/decode mismatch on frame %d at"
+ " Y[%d, %d] {%d/%d},"
+ " U[%d, %d] {%d/%d},"
+ " V[%d, %d] {%d/%d}",
+ frame_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0], v[1],
+ v[2], v[3]);
}
vpx_img_free(&enc_img);
@@ -230,23 +225,18 @@
vpx_img_free(&dec_img);
}
-static int encode_frame(vpx_codec_ctx_t *ecodec,
- vpx_codec_enc_cfg_t *cfg,
- vpx_image_t *img,
- unsigned int frame_in,
- VpxVideoWriter *writer,
- int test_decode,
- vpx_codec_ctx_t *dcodec,
- unsigned int *frame_out,
+static int encode_frame(vpx_codec_ctx_t *ecodec, vpx_codec_enc_cfg_t *cfg,
+ vpx_image_t *img, unsigned int frame_in,
+ VpxVideoWriter *writer, int test_decode,
+ vpx_codec_ctx_t *dcodec, unsigned int *frame_out,
int *mismatch_seen) {
int got_pkts = 0;
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
int got_data;
- const vpx_codec_err_t res = vpx_codec_encode(ecodec, img, frame_in, 1,
- 0, VPX_DL_GOOD_QUALITY);
- if (res != VPX_CODEC_OK)
- die_codec(ecodec, "Failed to encode frame");
+ const vpx_codec_err_t res =
+ vpx_codec_encode(ecodec, img, frame_in, 1, 0, VPX_DL_GOOD_QUALITY);
+ if (res != VPX_CODEC_OK) die_codec(ecodec, "Failed to encode frame");
got_data = 0;
@@ -257,11 +247,10 @@
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) {
- *frame_out += 1;
- }
+ *frame_out += 1;
+ }
- if (!vpx_video_writer_write_frame(writer,
- pkt->data.frame.buf,
+ if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
pkt->data.frame.sz,
pkt->data.frame.pts)) {
die_codec(ecodec, "Failed to write compressed frame");
@@ -290,12 +279,12 @@
int main(int argc, char **argv) {
FILE *infile = NULL;
// Encoder
- vpx_codec_ctx_t ecodec = {0};
- vpx_codec_enc_cfg_t cfg = {0};
+ vpx_codec_ctx_t ecodec = { 0 };
+ vpx_codec_enc_cfg_t cfg = { 0 };
unsigned int frame_in = 0;
vpx_image_t raw;
vpx_codec_err_t res;
- VpxVideoInfo info = {0};
+ VpxVideoInfo info = { 0 };
VpxVideoWriter *writer = NULL;
const VpxInterface *encoder = NULL;
@@ -319,8 +308,7 @@
unsigned int limit = 0;
exec_name = argv[0];
- if (argc < 6)
- die("Invalid number of arguments");
+ if (argc < 6) die("Invalid number of arguments");
width_arg = argv[1];
height_arg = argv[2];
@@ -328,15 +316,13 @@
outfile_arg = argv[4];
encoder = get_vpx_encoder_by_name("vp9");
- if (!encoder)
- die("Unsupported codec.");
+ if (!encoder) die("Unsupported codec.");
update_frame_num = atoi(argv[5]);
// In VP9, the reference buffers (cm->buffer_pool->frame_bufs[i].buf) are
// allocated while calling vpx_codec_encode(), thus, setting reference for
// 1st frame isn't supported.
- if (update_frame_num <= 1)
- die("Couldn't parse frame number '%s'\n", argv[5]);
+ if (update_frame_num <= 1) die("Couldn't parse frame number '%s'\n", argv[5]);
if (argc > 6) {
limit = atoi(argv[6]);
@@ -350,15 +336,13 @@
info.time_base.numerator = 1;
info.time_base.denominator = fps;
- if (info.frame_width <= 0 ||
- info.frame_height <= 0 ||
- (info.frame_width % 2) != 0 ||
- (info.frame_height % 2) != 0) {
+ if (info.frame_width <= 0 || info.frame_height <= 0 ||
+ (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
}
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
- info.frame_height, 1)) {
+ info.frame_height, 1)) {
die("Failed to allocate image.");
}
@@ -365,8 +349,7 @@
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
- if (res)
- die_codec(&ecodec, "Failed to get default codec config.");
+ if (res) die_codec(&ecodec, "Failed to get default codec config.");
cfg.g_w = info.frame_width;
cfg.g_h = info.frame_height;
@@ -376,8 +359,7 @@
cfg.g_lag_in_frames = 3;
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
- if (!writer)
- die("Failed to open %s for writing.", outfile_arg);
+ if (!writer) die("Failed to open %s for writing.", outfile_arg);
if (!(infile = fopen(infile_arg, "rb")))
die("Failed to open %s for reading.", infile_arg);
@@ -390,15 +372,14 @@
die_codec(&ecodec, "Failed to set enable auto alt ref");
if (test_decode) {
- const VpxInterface *decoder = get_vpx_decoder_by_name("vp9");
- if (vpx_codec_dec_init(&dcodec, decoder->codec_interface(), NULL, 0))
- die_codec(&dcodec, "Failed to initialize decoder.");
+ const VpxInterface *decoder = get_vpx_decoder_by_name("vp9");
+ if (vpx_codec_dec_init(&dcodec, decoder->codec_interface(), NULL, 0))
+ die_codec(&dcodec, "Failed to initialize decoder.");
}
// Encode frames.
while (vpx_img_read(&raw, infile)) {
- if (limit && frame_in >= limit)
- break;
+ if (limit && frame_in >= limit) break;
if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
vpx_ref_frame_t ref;
ref.frame_type = VP8_LAST_FRAME;
@@ -416,17 +397,17 @@
}
}
- encode_frame(&ecodec, &cfg, &raw, frame_in, writer, test_decode,
- &dcodec, &frame_out, &mismatch_seen);
+ encode_frame(&ecodec, &cfg, &raw, frame_in, writer, test_decode, &dcodec,
+ &frame_out, &mismatch_seen);
frame_in++;
- if (mismatch_seen)
- break;
+ if (mismatch_seen) break;
}
// Flush encoder.
if (!mismatch_seen)
while (encode_frame(&ecodec, &cfg, NULL, frame_in, writer, test_decode,
- &dcodec, &frame_out, &mismatch_seen)) {}
+ &dcodec, &frame_out, &mismatch_seen)) {
+ }
printf("\n");
fclose(infile);
--- a/examples/vpx_temporal_svc_encoder.c
+++ b/examples/vpx_temporal_svc_encoder.c
@@ -28,9 +28,7 @@
static const char *exec_name;
-void usage_exit(void) {
- exit(EXIT_FAILURE);
-}
+void usage_exit(void) { exit(EXIT_FAILURE); }
// Denoiser states, for temporal denoising.
enum denoiserState {
@@ -41,7 +39,7 @@
kDenoiserOnAdaptive
};
-static int mode_to_num_layers[13] = {1, 2, 2, 3, 3, 3, 3, 5, 2, 3, 3, 3, 3};
+static int mode_to_num_layers[13] = { 1, 2, 2, 3, 3, 3, 3, 5, 2, 3, 3, 3, 3 };
// For rate control encoding stats.
struct RateControlMetrics {
@@ -86,14 +84,14 @@
// per-frame-bandwidth, for the rate control encoding stats below.
const double framerate = cfg->g_timebase.den / cfg->g_timebase.num;
rc->layer_framerate[0] = framerate / cfg->ts_rate_decimator[0];
- rc->layer_pfb[0] = 1000.0 * rc->layer_target_bitrate[0] /
- rc->layer_framerate[0];
+ rc->layer_pfb[0] =
+ 1000.0 * rc->layer_target_bitrate[0] / rc->layer_framerate[0];
for (i = 0; i < cfg->ts_number_layers; ++i) {
if (i > 0) {
rc->layer_framerate[i] = framerate / cfg->ts_rate_decimator[i];
- rc->layer_pfb[i] = 1000.0 *
- (rc->layer_target_bitrate[i] - rc->layer_target_bitrate[i - 1]) /
- (rc->layer_framerate[i] - rc->layer_framerate[i - 1]);
+ rc->layer_pfb[i] = 1000.0 * (rc->layer_target_bitrate[i] -
+ rc->layer_target_bitrate[i - 1]) /
+ (rc->layer_framerate[i] - rc->layer_framerate[i - 1]);
}
rc->layer_input_frames[i] = 0;
rc->layer_enc_frames[i] = 0;
@@ -114,20 +112,21 @@
unsigned int i = 0;
int tot_num_frames = 0;
double perc_fluctuation = 0.0;
- printf("Total number of processed frames: %d\n\n", frame_cnt -1);
+ printf("Total number of processed frames: %d\n\n", frame_cnt - 1);
printf("Rate control layer stats for %d layer(s):\n\n",
- cfg->ts_number_layers);
+ cfg->ts_number_layers);
for (i = 0; i < cfg->ts_number_layers; ++i) {
- const int num_dropped = (i > 0) ?
- (rc->layer_input_frames[i] - rc->layer_enc_frames[i]) :
- (rc->layer_input_frames[i] - rc->layer_enc_frames[i] - 1);
+ const int num_dropped =
+ (i > 0) ? (rc->layer_input_frames[i] - rc->layer_enc_frames[i])
+ : (rc->layer_input_frames[i] - rc->layer_enc_frames[i] - 1);
tot_num_frames += rc->layer_input_frames[i];
rc->layer_encoding_bitrate[i] = 0.001 * rc->layer_framerate[i] *
- rc->layer_encoding_bitrate[i] / tot_num_frames;
- rc->layer_avg_frame_size[i] = rc->layer_avg_frame_size[i] /
- rc->layer_enc_frames[i];
- rc->layer_avg_rate_mismatch[i] = 100.0 * rc->layer_avg_rate_mismatch[i] /
- rc->layer_enc_frames[i];
+ rc->layer_encoding_bitrate[i] /
+ tot_num_frames;
+ rc->layer_avg_frame_size[i] =
+ rc->layer_avg_frame_size[i] / rc->layer_enc_frames[i];
+ rc->layer_avg_rate_mismatch[i] =
+ 100.0 * rc->layer_avg_rate_mismatch[i] / rc->layer_enc_frames[i];
printf("For layer#: %d \n", i);
printf("Bitrate (target vs actual): %d %f \n", rc->layer_target_bitrate[i],
rc->layer_encoding_bitrate[i]);
@@ -134,9 +133,10 @@
printf("Average frame size (target vs actual): %f %f \n", rc->layer_pfb[i],
rc->layer_avg_frame_size[i]);
printf("Average rate_mismatch: %f \n", rc->layer_avg_rate_mismatch[i]);
- printf("Number of input frames, encoded (non-key) frames, "
- "and perc dropped frames: %d %d %f \n", rc->layer_input_frames[i],
- rc->layer_enc_frames[i],
+ printf(
+ "Number of input frames, encoded (non-key) frames, "
+ "and perc dropped frames: %d %d %f \n",
+ rc->layer_input_frames[i], rc->layer_enc_frames[i],
100.0 * num_dropped / rc->layer_input_frames[i]);
printf("\n");
}
@@ -145,11 +145,10 @@
rc->variance_st_encoding_bitrate / rc->window_count -
(rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
- rc->avg_st_encoding_bitrate;
- printf("Short-time stats, for window of %d frames: \n",rc->window_size);
+ rc->avg_st_encoding_bitrate;
+ printf("Short-time stats, for window of %d frames: \n", rc->window_size);
printf("Average, rms-variance, and percent-fluct: %f %f %f \n",
- rc->avg_st_encoding_bitrate,
- sqrt(rc->variance_st_encoding_bitrate),
+ rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
perc_fluctuation);
if ((frame_cnt - 1) != tot_num_frames)
die("Error: Number of input frames not equal to output! \n");
@@ -167,7 +166,7 @@
switch (layering_mode) {
case 0: {
// 1-layer.
- int ids[1] = {0};
+ int ids[1] = { 0 };
cfg->ts_periodicity = 1;
*flag_periodicity = 1;
cfg->ts_number_layers = 1;
@@ -174,13 +173,13 @@
cfg->ts_rate_decimator[0] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// Update L only.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[0] =
+ VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
break;
}
case 1: {
// 2-layers, 2-frame period.
- int ids[2] = {0, 1};
+ int ids[2] = { 0, 1 };
cfg->ts_periodicity = 2;
*flag_periodicity = 2;
cfg->ts_number_layers = 2;
@@ -189,22 +188,24 @@
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
#if 1
// 0=L, 1=GF, Intra-layer prediction enabled.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF;
- layer_flags[1] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_REF_ARF;
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF;
+ layer_flags[1] =
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_REF_ARF;
#else
- // 0=L, 1=GF, Intra-layer prediction disabled.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF;
+ // 0=L, 1=GF, Intra-layer prediction disabled.
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF;
layer_flags[1] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_LAST;
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_LAST;
#endif
break;
}
case 2: {
// 2-layers, 3-frame period.
- int ids[3] = {0, 1, 1};
+ int ids[3] = { 0, 1, 1 };
cfg->ts_periodicity = 3;
*flag_periodicity = 3;
cfg->ts_number_layers = 2;
@@ -212,16 +213,17 @@
cfg->ts_rate_decimator[1] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, Intra-layer prediction enabled.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
- layer_flags[1] =
- layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[1] = layer_flags[2] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF |
+ VP8_EFLAG_NO_UPD_LAST;
break;
}
case 3: {
// 3-layers, 6-frame period.
- int ids[6] = {0, 2, 2, 1, 2, 2};
+ int ids[6] = { 0, 2, 2, 1, 2, 2 };
cfg->ts_periodicity = 6;
*flag_periodicity = 6;
cfg->ts_number_layers = 3;
@@ -230,19 +232,18 @@
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
- layer_flags[3] = VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST;
- layer_flags[1] =
- layer_flags[2] =
- layer_flags[4] =
- layer_flags[5] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_LAST;
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[3] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
+ layer_flags[1] = layer_flags[2] = layer_flags[4] = layer_flags[5] =
+ VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_LAST;
break;
}
case 4: {
// 3-layers, 4-frame period.
- int ids[4] = {0, 2, 1, 2};
+ int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
cfg->ts_number_layers = 3;
@@ -251,21 +252,22 @@
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
- layer_flags[1] =
- layer_flags[3] = VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
+ layer_flags[1] = layer_flags[3] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
break;
}
case 5: {
// 3-layers, 4-frame period.
- int ids[4] = {0, 2, 1, 2};
+ int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
- cfg->ts_number_layers = 3;
+ cfg->ts_number_layers = 3;
cfg->ts_rate_decimator[0] = 4;
cfg->ts_rate_decimator[1] = 2;
cfg->ts_rate_decimator[2] = 1;
@@ -272,18 +274,19 @@
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled in layer 1, disabled
// in layer 2.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
- layer_flags[2] = VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST |
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[2] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[1] = layer_flags[3] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
VP8_EFLAG_NO_UPD_ARF;
- layer_flags[1] =
- layer_flags[3] = VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
break;
}
case 6: {
// 3-layers, 4-frame period.
- int ids[4] = {0, 2, 1, 2};
+ int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
cfg->ts_number_layers = 3;
@@ -292,18 +295,19 @@
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
- layer_flags[2] = VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ARF;
- layer_flags[1] =
- layer_flags[3] = VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[2] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[1] = layer_flags[3] =
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
break;
}
case 7: {
// NOTE: Probably of academic interest only.
// 5-layers, 16-frame period.
- int ids[16] = {0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4};
+ int ids[16] = { 0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4 };
cfg->ts_periodicity = 16;
*flag_periodicity = 16;
cfg->ts_number_layers = 5;
@@ -313,28 +317,21 @@
cfg->ts_rate_decimator[3] = 2;
cfg->ts_rate_decimator[4] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
- layer_flags[0] = VPX_EFLAG_FORCE_KF;
- layer_flags[1] =
- layer_flags[3] =
- layer_flags[5] =
- layer_flags[7] =
- layer_flags[9] =
- layer_flags[11] =
- layer_flags[13] =
- layer_flags[15] = VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF;
- layer_flags[2] =
- layer_flags[6] =
- layer_flags[10] =
- layer_flags[14] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF;
- layer_flags[4] =
- layer_flags[12] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_UPD_ARF;
- layer_flags[8] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF;
+ layer_flags[0] = VPX_EFLAG_FORCE_KF;
+ layer_flags[1] = layer_flags[3] = layer_flags[5] = layer_flags[7] =
+ layer_flags[9] = layer_flags[11] = layer_flags[13] = layer_flags[15] =
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[2] = layer_flags[6] = layer_flags[10] = layer_flags[14] =
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF;
+ layer_flags[4] = layer_flags[12] =
+ VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[8] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF;
break;
}
case 8: {
// 2-layers, with sync point at first frame of layer 1.
- int ids[2] = {0, 1};
+ int ids[2] = { 0, 1 };
cfg->ts_periodicity = 2;
*flag_periodicity = 8;
cfg->ts_number_layers = 2;
@@ -346,17 +343,17 @@
// key frame. Sync point every 8 frames.
// Layer 0: predict from L and ARF, update L and G.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[0] =
+ VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF;
// Layer 1: sync point: predict from L and ARF, and update G.
- layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[1] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
// Layer 0, predict from L and ARF, update L.
- layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[2] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
// Layer 1: predict from L, G and ARF, and update G.
layer_flags[3] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ENTROPY;
+ VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 0.
layer_flags[4] = layer_flags[2];
// Layer 1.
@@ -365,11 +362,11 @@
layer_flags[6] = layer_flags[4];
// Layer 1.
layer_flags[7] = layer_flags[5];
- break;
+ break;
}
case 9: {
// 3-layers: Sync points for layer 1 and 2 every 8 frames.
- int ids[4] = {0, 2, 1, 2};
+ int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 8;
cfg->ts_number_layers = 3;
@@ -378,20 +375,21 @@
cfg->ts_rate_decimator[2] = 1;
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
- VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_GF |
+ VP8_EFLAG_NO_UPD_ARF;
layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
+ layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[3] = layer_flags[5] =
VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
- layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
- layer_flags[3] =
- layer_flags[5] = VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
layer_flags[4] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
- layer_flags[6] = VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ARF;
+ VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
+ layer_flags[6] =
+ VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF;
layer_flags[7] = VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_ENTROPY;
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_ENTROPY;
break;
}
case 10: {
@@ -399,7 +397,7 @@
// and is only updated on key frame.
// Sync points for layer 1 and 2 every 8 frames.
- int ids[4] = {0, 2, 1, 2};
+ int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 8;
cfg->ts_number_layers = 3;
@@ -409,21 +407,21 @@
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF.
// Layer 0: predict from L and ARF; update L and G.
- layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_REF_GF;
+ layer_flags[0] =
+ VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
// Layer 2: sync point: predict from L and ARF; update none.
layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF |
- VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
- VP8_EFLAG_NO_UPD_ENTROPY;
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
+ VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 1: sync point: predict from L and ARF; update G.
- layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST;
+ layer_flags[2] =
+ VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[3] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
// Layer 0: predict from L and ARF; update L.
- layer_flags[4] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_REF_GF;
+ layer_flags[4] =
+ VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
// Layer 2: predict from L, G, ARF; update none.
layer_flags[5] = layer_flags[3];
// Layer 1: predict from L, G, ARF; update G.
@@ -438,7 +436,7 @@
// This was added to compare with vp9_spatial_svc_encoder.
// 3-layers, 4-frame period.
- int ids[4] = {0, 2, 1, 2};
+ int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 4;
cfg->ts_number_layers = 3;
@@ -448,13 +446,13 @@
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled.
layer_flags[0] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
+ VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
+ VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
layer_flags[3] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_ARF |
- VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
break;
}
case 12:
@@ -461,7 +459,7 @@
default: {
// 3-layers structure as in case 10, but no sync/refresh points for
// layer 1 and 2.
- int ids[4] = {0, 2, 1, 2};
+ int ids[4] = { 0, 2, 1, 2 };
cfg->ts_periodicity = 4;
*flag_periodicity = 8;
cfg->ts_number_layers = 3;
@@ -471,8 +469,8 @@
memcpy(cfg->ts_layer_id, ids, sizeof(ids));
// 0=L, 1=GF, 2=ARF.
// Layer 0: predict from L and ARF; update L.
- layer_flags[0] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_REF_GF;
+ layer_flags[0] =
+ VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF;
layer_flags[4] = layer_flags[0];
// Layer 1: predict from L, G, ARF; update G.
layer_flags[2] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
@@ -479,7 +477,7 @@
layer_flags[6] = layer_flags[2];
// Layer 2: predict from L, G, ARF; update none.
layer_flags[1] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
- VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
+ VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ENTROPY;
layer_flags[3] = layer_flags[1];
layer_flags[5] = layer_flags[1];
layer_flags[7] = layer_flags[1];
@@ -489,7 +487,7 @@
}
int main(int argc, char **argv) {
- VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS] = {NULL};
+ VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS] = { NULL };
vpx_codec_ctx_t codec;
vpx_codec_enc_cfg_t cfg;
int frame_cnt = 0;
@@ -502,15 +500,15 @@
int got_data;
int flags = 0;
unsigned int i;
- int pts = 0; // PTS starts at 0.
+ int pts = 0; // PTS starts at 0.
int frame_duration = 1; // 1 timebase tick per frame.
int layering_mode = 0;
- int layer_flags[VPX_TS_MAX_PERIODICITY] = {0};
+ int layer_flags[VPX_TS_MAX_PERIODICITY] = { 0 };
int flag_periodicity = 1;
#if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION)
- vpx_svc_layer_id_t layer_id = {0, 0};
+ vpx_svc_layer_id_t layer_id = { 0, 0 };
#else
- vpx_svc_layer_id_t layer_id = {0};
+ vpx_svc_layer_id_t layer_id = { 0 };
#endif
const VpxInterface *encoder = NULL;
FILE *infile = NULL;
@@ -526,25 +524,28 @@
#endif // CONFIG_VP9_HIGHBITDEPTH
double sum_bitrate = 0.0;
double sum_bitrate2 = 0.0;
- double framerate = 30.0;
+ double framerate = 30.0;
exec_name = argv[0];
// Check usage and arguments.
if (argc < min_args) {
#if CONFIG_VP9_HIGHBITDEPTH
- die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
+ die(
+ "Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
"<rate_num> <rate_den> <speed> <frame_drop_threshold> <mode> "
- "<Rate_0> ... <Rate_nlayers-1> <bit-depth> \n", argv[0]);
+ "<Rate_0> ... <Rate_nlayers-1> <bit-depth> \n",
+ argv[0]);
#else
- die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
+ die(
+ "Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
"<rate_num> <rate_den> <speed> <frame_drop_threshold> <mode> "
- "<Rate_0> ... <Rate_nlayers-1> \n", argv[0]);
+ "<Rate_0> ... <Rate_nlayers-1> \n",
+ argv[0]);
#endif // CONFIG_VP9_HIGHBITDEPTH
}
encoder = get_vpx_encoder_by_name(argv[3]);
- if (!encoder)
- die("Unsupported codec.");
+ if (!encoder) die("Unsupported codec.");
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
@@ -564,7 +565,7 @@
}
#if CONFIG_VP9_HIGHBITDEPTH
- switch (strtol(argv[argc-1], NULL, 0)) {
+ switch (strtol(argv[argc - 1], NULL, 0)) {
case 8:
bit_depth = VPX_BITS_8;
input_bit_depth = 8;
@@ -577,13 +578,11 @@
bit_depth = VPX_BITS_12;
input_bit_depth = 12;
break;
- default:
- die("Invalid bit depth (8, 10, 12) %s", argv[argc-1]);
+ default: die("Invalid bit depth (8, 10, 12) %s", argv[argc - 1]);
}
- if (!vpx_img_alloc(&raw,
- bit_depth == VPX_BITS_8 ? VPX_IMG_FMT_I420 :
- VPX_IMG_FMT_I42016,
- width, height, 32)) {
+ if (!vpx_img_alloc(
+ &raw, bit_depth == VPX_BITS_8 ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_I42016,
+ width, height, 32)) {
die("Failed to allocate image", width, height);
}
#else
@@ -621,8 +620,7 @@
}
for (i = min_args_base;
- (int)i < min_args_base + mode_to_num_layers[layering_mode];
- ++i) {
+ (int)i < min_args_base + mode_to_num_layers[layering_mode]; ++i) {
rc.layer_target_bitrate[i - 11] = strtol(argv[i], NULL, 0);
if (strncmp(encoder->name, "vp8", 3) == 0)
cfg.ts_target_bitrate[i - 11] = rc.layer_target_bitrate[i - 11];
@@ -635,8 +633,7 @@
cfg.rc_end_usage = VPX_CBR;
cfg.rc_min_quantizer = 2;
cfg.rc_max_quantizer = 56;
- if (strncmp(encoder->name, "vp9", 3) == 0)
- cfg.rc_max_quantizer = 52;
+ if (strncmp(encoder->name, "vp9", 3) == 0) cfg.rc_max_quantizer = 52;
cfg.rc_undershoot_pct = 50;
cfg.rc_overshoot_pct = 50;
cfg.rc_buf_initial_sz = 500;
@@ -651,7 +648,7 @@
// Enable error resilient mode.
cfg.g_error_resilient = 1;
- cfg.g_lag_in_frames = 0;
+ cfg.g_lag_in_frames = 0;
cfg.kf_mode = VPX_KF_AUTO;
// Disable automatic keyframe placement.
@@ -659,9 +656,7 @@
cfg.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
- set_temporal_layer_pattern(layering_mode,
- &cfg,
- layer_flags,
+ set_temporal_layer_pattern(layering_mode, &cfg, layer_flags,
&flag_periodicity);
set_rate_control_metrics(&rc, &cfg);
@@ -688,8 +683,7 @@
snprintf(file_name, sizeof(file_name), "%s_%d.ivf", argv[2], i);
outfile[i] = vpx_video_writer_open(file_name, kContainerIVF, &info);
- if (!outfile[i])
- die("Failed to open %s for writing", file_name);
+ if (!outfile[i]) die("Failed to open %s for writing", file_name);
assert(outfile[i] != NULL);
}
@@ -696,7 +690,7 @@
// No spatial layers in this encoder.
cfg.ss_number_layers = 1;
- // Initialize codec.
+// Initialize codec.
#if CONFIG_VP9_HIGHBITDEPTH
if (vpx_codec_enc_init(
&codec, encoder->codec_interface(), &cfg,
@@ -719,7 +713,7 @@
vpx_codec_control(&codec, VP8E_SET_STATIC_THRESHOLD, 1);
vpx_codec_control(&codec, VP9E_SET_TUNE_CONTENT, 0);
vpx_codec_control(&codec, VP9E_SET_TILE_COLUMNS, (cfg.g_threads >> 1));
- if (vpx_codec_control(&codec, VP9E_SET_SVC, layering_mode > 0 ? 1: 0))
+ if (vpx_codec_control(&codec, VP9E_SET_SVC, layering_mode > 0 ? 1 : 0))
die_codec(&codec, "Failed to set SVC");
for (i = 0; i < cfg.ts_number_layers; ++i) {
svc_params.max_quantizers[i] = cfg.rc_max_quantizer;
@@ -760,14 +754,12 @@
layer_id.temporal_layer_id);
}
flags = layer_flags[frame_cnt % flag_periodicity];
- if (layering_mode == 0)
- flags = 0;
+ if (layering_mode == 0) flags = 0;
frame_avail = vpx_img_read(&raw, infile);
- if (frame_avail)
- ++rc.layer_input_frames[layer_id.temporal_layer_id];
+ if (frame_avail) ++rc.layer_input_frames[layer_id.temporal_layer_id];
vpx_usec_timer_start(&timer);
- if (vpx_codec_encode(&codec, frame_avail? &raw : NULL, pts, 1, flags,
- VPX_DL_REALTIME)) {
+ if (vpx_codec_encode(&codec, frame_avail ? &raw : NULL, pts, 1, flags,
+ VPX_DL_REALTIME)) {
die_codec(&codec, "Failed to encode frame");
}
vpx_usec_timer_mark(&timer);
@@ -777,12 +769,12 @@
layer_flags[0] &= ~VPX_EFLAG_FORCE_KF;
}
got_data = 0;
- while ( (pkt = vpx_codec_get_cx_data(&codec, &iter)) ) {
+ while ((pkt = vpx_codec_get_cx_data(&codec, &iter))) {
got_data = 1;
switch (pkt->kind) {
case VPX_CODEC_CX_FRAME_PKT:
for (i = cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity];
- i < cfg.ts_number_layers; ++i) {
+ i < cfg.ts_number_layers; ++i) {
vpx_video_writer_write_frame(outfile[i], pkt->data.frame.buf,
pkt->data.frame.sz, pts);
++rc.layer_tot_enc_frames[i];
@@ -825,8 +817,7 @@
}
}
break;
- default:
- break;
+ default: break;
}
}
++frame_cnt;
@@ -836,16 +827,13 @@
printout_rate_control_summary(&rc, &cfg, frame_cnt);
printf("\n");
printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
- frame_cnt,
- 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
- 1000000 * (double)frame_cnt / (double)cx_time);
+ frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
+ 1000000 * (double)frame_cnt / (double)cx_time);
- if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec");
+ if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
// Try to rewrite the output file headers with the actual frame count.
- for (i = 0; i < cfg.ts_number_layers; ++i)
- vpx_video_writer_close(outfile[i]);
+ for (i = 0; i < cfg.ts_number_layers; ++i) vpx_video_writer_close(outfile[i]);
vpx_img_free(&raw);
return EXIT_SUCCESS;