summaryrefslogtreecommitdiff
path: root/vpxenc.c
diff options
context:
space:
mode:
Diffstat (limited to 'vpxenc.c')
-rw-r--r--vpxenc.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/vpxenc.c b/vpxenc.c
index 2f3b6356d..2f3ae0f8c 100644
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -47,6 +47,7 @@
#include "y4minput.h"
#include "libmkv/EbmlWriter.h"
#include "libmkv/EbmlIDs.h"
+#include "third_party/libyuv/include/libyuv/scale.h"
/* Need special handling of these functions on Windows */
#if defined(_MSC_VER)
@@ -1642,6 +1643,7 @@ struct stream_state {
uint64_t cx_time;
size_t nbytes;
stats_io_t stats;
+ struct vpx_image *img;
vpx_codec_ctx_t decoder;
vpx_ref_frame_t ref_enc;
vpx_ref_frame_t ref_dec;
@@ -2061,11 +2063,15 @@ static void validate_stream_config(struct stream_state *stream) {
static void set_stream_dimensions(struct stream_state *stream,
unsigned int w,
unsigned int h) {
- if ((stream->config.cfg.g_w && stream->config.cfg.g_w != w)
- || (stream->config.cfg.g_h && stream->config.cfg.g_h != h))
- fatal("Stream %d: Resizing not yet supported", stream->index);
- stream->config.cfg.g_w = w;
- stream->config.cfg.g_h = h;
+ if (!stream->config.cfg.g_w) {
+ if (!stream->config.cfg.g_h)
+ stream->config.cfg.g_w = w;
+ else
+ stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
+ }
+ if (!stream->config.cfg.g_h) {
+ stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
+ }
}
@@ -2258,6 +2264,28 @@ static void encode_frame(struct stream_state *stream,
next_frame_start = (cfg->g_timebase.den * (int64_t)(frames_in)
* global->framerate.den)
/ cfg->g_timebase.num / global->framerate.num;
+
+ /* Scale if necessary */
+ if (img && (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) {
+ if (!stream->img)
+ stream->img = vpx_img_alloc(NULL, VPX_IMG_FMT_I420,
+ cfg->g_w, cfg->g_h, 16);
+ I420Scale(img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y],
+ img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U],
+ img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V],
+ img->d_w, img->d_h,
+ stream->img->planes[VPX_PLANE_Y],
+ stream->img->stride[VPX_PLANE_Y],
+ stream->img->planes[VPX_PLANE_U],
+ stream->img->stride[VPX_PLANE_U],
+ stream->img->planes[VPX_PLANE_V],
+ stream->img->stride[VPX_PLANE_V],
+ stream->img->d_w, stream->img->d_h,
+ kFilterBox);
+
+ img = stream->img;
+ }
+
vpx_usec_timer_start(&timer);
vpx_codec_encode(&stream->encoder, img, frame_start,
(unsigned long)(next_frame_start - frame_start),
@@ -2450,7 +2478,7 @@ int main(int argc, const char **argv_) {
struct global_config global;
struct stream_state *streams = NULL;
char **argv, **argi;
- unsigned long cx_time = 0;
+ uint64_t cx_time = 0;
int stream_cnt = 0;
int res = 0;
@@ -2518,6 +2546,9 @@ int main(int argc, const char **argv_) {
});
/* Update stream configurations from the input file's parameters */
+ if (!input.w || !input.h)
+ fatal("Specify stream dimensions with --width (-w) "
+ " and --height (-h)");
FOREACH_STREAM(set_stream_dimensions(stream, input.w, input.h));
FOREACH_STREAM(validate_stream_config(stream));
@@ -2587,7 +2618,7 @@ int main(int argc, const char **argv_) {
else
fprintf(stderr, "frame %4d ", frames_in);
- fprintf(stderr, "%7lu %s %.2f %s ",
+ fprintf(stderr, "%7"PRId64" %s %.2f %s ",
cx_time > 9999999 ? cx_time / 1000 : cx_time,
cx_time > 9999999 ? "ms" : "us",
fps >= 1.0 ? fps : 1000.0 / fps,
@@ -2605,7 +2636,7 @@ int main(int argc, const char **argv_) {
frame_avail ? &raw : NULL,
frames_in));
vpx_usec_timer_mark(&timer);
- cx_time += (unsigned long)vpx_usec_timer_elapsed(&timer);
+ cx_time += vpx_usec_timer_elapsed(&timer);
FOREACH_STREAM(update_quantizer_histogram(stream));
@@ -2614,7 +2645,7 @@ int main(int argc, const char **argv_) {
if (!got_data && input.length && !streams->frames_out) {
lagged_count = global.limit ? frames_in : ftello(input.file);
- } else if (got_data && input.length) {
+ } else if (input.length) {
int64_t remaining;
int64_t rate;