summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJerome Jiang <jianj@google.com>2019-01-28 15:49:42 -0800
committerJerome Jiang <jianj@google.com>2019-01-30 12:47:10 -0800
commit7199f7878371c3d38e77896aa3d3bcf6c08ce764 (patch)
tree484629b45b6dfc1534f00c969a8816c9e9c34d10 /examples
parent5e5f6db6570112cd14098408dc07e8130f345ab0 (diff)
downloadlibvpx-7199f7878371c3d38e77896aa3d3bcf6c08ce764.tar
libvpx-7199f7878371c3d38e77896aa3d3bcf6c08ce764.tar.gz
libvpx-7199f7878371c3d38e77896aa3d3bcf6c08ce764.tar.bz2
libvpx-7199f7878371c3d38e77896aa3d3bcf6c08ce764.zip
add y4m support to vp9 example encoders.
vp9_spatial_svc_encoder and vpx_temporal_svc_encoder. Change-Id: I8dfa1dfad83c83a26ddac4e7c57b5f1ff161e588
Diffstat (limited to 'examples')
-rw-r--r--examples/vp8_multi_resolution_encoder.c8
-rw-r--r--examples/vp9_spatial_svc_encoder.c32
-rw-r--r--examples/vpx_temporal_svc_encoder.c29
3 files changed, 50 insertions, 19 deletions
diff --git a/examples/vp8_multi_resolution_encoder.c b/examples/vp8_multi_resolution_encoder.c
index b14b1ff39..e72f8a019 100644
--- a/examples/vp8_multi_resolution_encoder.c
+++ b/examples/vp8_multi_resolution_encoder.c
@@ -61,7 +61,7 @@ void usage_exit(void) { exit(EXIT_FAILURE); }
int (*read_frame_p)(FILE *f, vpx_image_t *img);
-static int read_frame(FILE *f, vpx_image_t *img) {
+static int mulres_read_frame(FILE *f, vpx_image_t *img) {
size_t nbytes, to_read;
int res = 1;
@@ -75,7 +75,7 @@ static int read_frame(FILE *f, vpx_image_t *img) {
return res;
}
-static int read_frame_by_row(FILE *f, vpx_image_t *img) {
+static int mulres_read_frame_by_row(FILE *f, vpx_image_t *img) {
size_t nbytes, to_read;
int res = 1;
int plane;
@@ -471,9 +471,9 @@ int main(int argc, char **argv) {
die("Failed to allocate image", cfg[i].g_w, cfg[i].g_h);
if (raw[0].stride[VPX_PLANE_Y] == (int)raw[0].d_w)
- read_frame_p = read_frame;
+ read_frame_p = mulres_read_frame;
else
- read_frame_p = read_frame_by_row;
+ read_frame_p = mulres_read_frame_by_row;
for (i = 0; i < NUM_ENCODERS; i++)
if (outfile[i]) write_ivf_file_header(outfile[i], &cfg[i], 0);
diff --git a/examples/vp9_spatial_svc_encoder.c b/examples/vp9_spatial_svc_encoder.c
index f8093e1bf..92b310684 100644
--- a/examples/vp9_spatial_svc_encoder.c
+++ b/examples/vp9_spatial_svc_encoder.c
@@ -30,6 +30,8 @@
#include "vpx/vpx_encoder.h"
#include "../vpxstats.h"
#include "vp9/encoder/vp9_encoder.h"
+#include "./y4minput.h"
+
#define OUTPUT_RC_STATS 1
static const arg_def_t skip_frames_arg =
@@ -161,7 +163,6 @@ 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 {
- const char *input_filename;
const char *output_filename;
uint32_t frames_to_code;
uint32_t frames_to_skip;
@@ -393,10 +394,16 @@ static void parse_command_line(int argc, const char **argv_,
if (argv[0] == NULL || argv[1] == 0) {
usage_exit();
}
- app_input->input_filename = argv[0];
+ app_input->input_ctx.filename = argv[0];
app_input->output_filename = argv[1];
free(argv);
+ open_input_file(&app_input->input_ctx);
+ if (app_input->input_ctx.file_type == FILE_TYPE_Y4M) {
+ enc_cfg->g_w = app_input->input_ctx.width;
+ enc_cfg->g_h = app_input->input_ctx.height;
+ }
+
if (enc_cfg->g_w < 16 || enc_cfg->g_w % 2 || enc_cfg->g_h < 16 ||
enc_cfg->g_h % 2)
die("Invalid resolution: %d x %d\n", enc_cfg->g_w, enc_cfg->g_h);
@@ -752,7 +759,6 @@ int main(int argc, const char **argv) {
vpx_codec_err_t res;
int pts = 0; /* PTS starts at 0 */
int frame_duration = 1; /* 1 timebase tick per frame */
- FILE *infile = NULL;
int end_of_stream = 0;
int frames_received = 0;
#if OUTPUT_RC_STATS
@@ -773,6 +779,13 @@ int main(int argc, const char **argv) {
memset(&layer_id, 0, sizeof(vpx_svc_layer_id_t));
memset(&rc, 0, sizeof(struct RateControlStats));
exec_name = argv[0];
+
+ /* Setup default input stream settings */
+ app_input.input_ctx.framerate.numerator = 30;
+ app_input.input_ctx.framerate.denominator = 1;
+ app_input.input_ctx.only_i420 = 1;
+ app_input.input_ctx.bit_depth = 0;
+
parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
// Allocate image buffer
@@ -789,9 +802,6 @@ int main(int argc, const char **argv) {
}
#endif // CONFIG_VP9_HIGHBITDEPTH
- if (!(infile = fopen(app_input.input_filename, "rb")))
- die("Failed to open %s for reading\n", app_input.input_filename);
-
// Initialize codec
if (vpx_svc_init(&svc_ctx, &codec, vpx_codec_vp9_cx(), &enc_cfg) !=
VPX_CODEC_OK)
@@ -835,7 +845,8 @@ int main(int argc, const char **argv) {
#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)
+ read_frame(&app_input.input_ctx, &raw);
if (svc_ctx.speed != -1)
vpx_codec_control(&codec, VP8E_SET_CPUUSED, svc_ctx.speed);
@@ -875,7 +886,8 @@ int main(int argc, const char **argv) {
// layers, with SL0 only has TL0, and SL1 has both TL0 and TL1. This example
// uses the extended API.
int example_pattern = 0;
- if (frame_cnt >= app_input.frames_to_code || !vpx_img_read(&raw, infile)) {
+ if (frame_cnt >= app_input.frames_to_code ||
+ !read_frame(&app_input.input_ctx, &raw)) {
// We need one extra vpx_svc_encode call at end of stream to flush
// encoder and get remaining data
end_of_stream = 1;
@@ -1091,7 +1103,9 @@ int main(int argc, const char **argv) {
}
printf("Processed %d frames\n", frame_cnt);
- fclose(infile);
+
+ close_input_file(&app_input.input_ctx);
+
#if OUTPUT_RC_STATS
if (svc_ctx.output_rc_stat) {
printout_rate_control_summary(&rc, &enc_cfg, frame_cnt);
diff --git a/examples/vpx_temporal_svc_encoder.c b/examples/vpx_temporal_svc_encoder.c
index f49ef7b1d..aa2213a5b 100644
--- a/examples/vpx_temporal_svc_encoder.c
+++ b/examples/vpx_temporal_svc_encoder.c
@@ -19,6 +19,7 @@
#include <string.h>
#include "./vpx_config.h"
+#include "./y4minput.h"
#include "../vpx_ports/vpx_timer.h"
#include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h"
@@ -594,7 +595,7 @@ int main(int argc, char **argv) {
#endif
vpx_svc_layer_id_t layer_id;
const VpxInterface *encoder = NULL;
- FILE *infile = NULL;
+ struct VpxInputContext input_ctx;
struct RateControlMetrics rc;
int64_t cx_time = 0;
const int min_args_base = 13;
@@ -611,6 +612,13 @@ int main(int argc, char **argv) {
zero(rc.layer_target_bitrate);
memset(&layer_id, 0, sizeof(vpx_svc_layer_id_t));
+ memset(&input_ctx, 0, sizeof(input_ctx));
+ /* Setup default input stream settings */
+ input_ctx.framerate.numerator = 30;
+ input_ctx.framerate.denominator = 1;
+ input_ctx.only_i420 = 1;
+ input_ctx.bit_depth = 0;
+
exec_name = argv[0];
// Check usage and arguments.
if (argc < min_args) {
@@ -754,9 +762,18 @@ int main(int argc, char **argv) {
// Set to layer_target_bitrate for highest layer (total bitrate).
cfg.rc_target_bitrate = rc.layer_target_bitrate[cfg.ts_number_layers - 1];
- // Open input file.
- if (!(infile = fopen(argv[1], "rb"))) {
- die("Failed to open %s for reading", argv[1]);
+ input_ctx.filename = argv[1];
+ open_input_file(&input_ctx);
+
+ if (input_ctx.file_type == FILE_TYPE_Y4M) {
+ if (input_ctx.width != cfg.g_w || input_ctx.height != cfg.g_h) {
+ die("Incorrect width or height: %d x %d", cfg.g_w, cfg.g_h);
+ }
+ if (input_ctx.framerate.numerator != cfg.g_timebase.den ||
+ input_ctx.framerate.denominator != cfg.g_timebase.num) {
+ die("Incorrect framerate: numerator %d denominator %d",
+ cfg.g_timebase.num, cfg.g_timebase.den);
+ }
}
framerate = cfg.g_timebase.den / cfg.g_timebase.num;
@@ -865,7 +882,7 @@ int main(int argc, char **argv) {
}
flags = layer_flags[frame_cnt % flag_periodicity];
if (layering_mode == 0) flags = 0;
- frame_avail = vpx_img_read(&raw, infile);
+ frame_avail = read_frame(&input_ctx, &raw);
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,
@@ -933,7 +950,7 @@ int main(int argc, char **argv) {
++frame_cnt;
pts += frame_duration;
}
- fclose(infile);
+ close_input_file(&input_ctx);
printout_rate_control_summary(&rc, &cfg, frame_cnt);
printf("\n");
printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",