summaryrefslogtreecommitdiff
path: root/examples/twopass_encoder.c
diff options
context:
space:
mode:
authorclang-format <noreply@google.com>2016-07-18 19:04:56 -0700
committerJames Zern <jzern@google.com>2016-07-18 19:04:56 -0700
commitef4554092702629d4a6d5144935fbdab3b49518a (patch)
tree061039d1c53acd2412b2c7331d40f91d34eb1c67 /examples/twopass_encoder.c
parentc69cc4ce1f384827d0a0aef349b9c6396b07014f (diff)
downloadlibvpx-ef4554092702629d4a6d5144935fbdab3b49518a.tar
libvpx-ef4554092702629d4a6d5144935fbdab3b49518a.tar.gz
libvpx-ef4554092702629d4a6d5144935fbdab3b49518a.tar.bz2
libvpx-ef4554092702629d4a6d5144935fbdab3b49518a.zip
examples: apply clang-format
Change-Id: Icc3bbb07c99a31a70030baec7e51b881902a7b5e
Diffstat (limited to 'examples/twopass_encoder.c')
-rw-r--r--examples/twopass_encoder.c101
1 files changed, 40 insertions, 61 deletions
diff --git a/examples/twopass_encoder.c b/examples/twopass_encoder.c
index 15a6617cd..4c130ec18 100644
--- a/examples/twopass_encoder.c
+++ b/examples/twopass_encoder.c
@@ -61,25 +61,21 @@ static const char *exec_name;
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 @@ static int get_frame_stats(vpx_codec_ctx_t *ctx,
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 @@ static int encode_frame(vpx_codec_ctx_t *ctx,
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 @@ static int encode_frame(vpx_codec_ctx_t *ctx,
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 @@ static vpx_fixed_buf_t pass0(vpx_image_t *raw,
++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 @@ static void pass1(vpx_image_t *raw,
++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 @@ int main(int argc, char **argv) {
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 main(int argc, char **argv) {
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 @@ int main(int argc, char **argv) {
// 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;