Commit 6ad3b74a authored by John Koleszar's avatar John Koleszar

vpxenc: merge with master

Change-Id: Ic3e3559384a0e72abdc9b66a19865474c2a41b38
parent 3707c348
......@@ -10,9 +10,6 @@
#include "vpx_config.h"
/* This is a simple program that encodes YV12 files and generates ivf
* files using the new interface.
*/
#if defined(_WIN32) || !CONFIG_OS_SUPPORT
#define USE_POSIX_MMAP 0
#else
......@@ -26,6 +23,7 @@
#include <limits.h>
#include <assert.h>
#include "vpx/vpx_encoder.h"
#include "vpx/vpx_decoder.h"
#if USE_POSIX_MMAP
#include <sys/types.h>
#include <sys/stat.h>
......@@ -33,11 +31,14 @@
#include <fcntl.h>
#include <unistd.h>
#endif
#include "vpx_config.h"
#include "vpx_version.h"
#if CONFIG_VP9_ENCODER
#include "vpx/vp8cx.h"
#endif
#if CONFIG_VP9_DECODER
#include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h"
#endif
#include "vpx_ports/mem_ops.h"
#include "vpx_ports/vpx_timer.h"
#include "tools_common.h"
......@@ -52,16 +53,14 @@ typedef __int64 off_t;
#define fseeko _fseeki64
#define ftello _ftelli64
#elif defined(_WIN32)
/* MinGW defines off_t, and uses f{seek,tell}o64 */
/* MinGW defines off_t as long
and uses f{seek,tell}o64/off64_t for large files */
#define fseeko fseeko64
#define ftello ftello64
#define off_t off64_t
#endif
#if defined(_MSC_VER)
#define LITERALU64(n) n
#else
#define LITERALU64(n) n##LLU
#endif
#define LITERALU64(hi,lo) ((((uint64_t)hi)<<32)|lo)
/* We should use 32-bit file operations in WebM file format
* when building ARM executable file (.axf) with RVCT */
......@@ -71,49 +70,76 @@ typedef long off_t;
#define ftello ftell
#endif
static const char *exec_name;
/* Swallow warnings about unused results of fread/fwrite */
static size_t wrap_fread(void *ptr, size_t size, size_t nmemb,
FILE *stream) {
return fread(ptr, size, nmemb, stream);
}
#define fread wrap_fread
static size_t wrap_fwrite(const void *ptr, size_t size, size_t nmemb,
FILE *stream) {
return fwrite(ptr, size, nmemb, stream);
}
#define fwrite wrap_fwrite
#define VP8_FOURCC (0x78385056)
static const struct {
char const *name;
const vpx_codec_iface_t *(*iface)(void);
unsigned int fourcc;
unsigned int fourcc_mask;
} ifaces[] = {
#if CONFIG_VP9_DECODER
{"vp9", &vpx_codec_vp8_dx, VP8_FOURCC, 0x00FFFFFF},
#endif
};
static const char *exec_name;
static const struct codec_item {
char const *name;
char const *name;
const vpx_codec_iface_t *(*iface)(void);
const vpx_codec_iface_t *(*dx_iface)(void);
unsigned int fourcc;
unsigned int fourcc_mask;
} codecs[] = {
#if CONFIG_VP9_ENCODER
{"vp9", vpx_codec_vp8x_cx, VP8_FOURCC, 0x00FFFFFF},
#if CONFIG_VP9_ENCODER && CONFIG_VP9_DECODER
{"vp9", &vpx_codec_vp8_cx, &vpx_codec_vp8_dx, 0x30385056},
#endif
#if CONFIG_VP9_ENCODER && !CONFIG_VP9_DECODER
{"vp9", &vpx_codec_vp8_cx, NULL, 0x30385056},
#endif
};
static void usage_exit();
#define LOG_ERROR(label) do \
{\
const char *l=label;\
va_list ap;\
va_start(ap, fmt);\
if(l)\
fprintf(stderr, "%s: ", l);\
vfprintf(stderr, fmt, ap);\
fprintf(stderr, "\n");\
va_end(ap);\
} while(0)
void die(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
LOG_ERROR(NULL);
usage_exit();
}
static void ctx_exit_on_error(vpx_codec_ctx_t *ctx, const char *s) {
void fatal(const char *fmt, ...) {
LOG_ERROR("Fatal");
exit(EXIT_FAILURE);
}
void warn(const char *fmt, ...) {
LOG_ERROR("Warning");
}
static void ctx_exit_on_error(vpx_codec_ctx_t *ctx, const char *s, ...) {
va_list ap;
va_start(ap, s);
if (ctx->err) {
const char *detail = vpx_codec_error_detail(ctx);
fprintf(stderr, "%s: %s\n", s, vpx_codec_error(ctx));
vfprintf(stderr, s, ap);
fprintf(stderr, ": %s\n", vpx_codec_error(ctx));
if (detail)
fprintf(stderr, " %s\n", detail);
......@@ -161,21 +187,17 @@ int stats_open_file(stats_io_t *stats, const char *fpf, int pass) {
stats->file = fopen(fpf, "rb");
if (fseek(stats->file, 0, SEEK_END)) {
fprintf(stderr, "First-pass stats file must be seekable!\n");
exit(EXIT_FAILURE);
}
if (fseek(stats->file, 0, SEEK_END))
fatal("First-pass stats file must be seekable!");
stats->buf.sz = stats->buf_alloc_sz = ftell(stats->file);
rewind(stats->file);
stats->buf.buf = malloc(stats->buf_alloc_sz);
if (!stats->buf.buf) {
fprintf(stderr, "Failed to allocate first-pass stats buffer (%lu bytes)\n",
(unsigned long)stats->buf_alloc_sz);
exit(EXIT_FAILURE);
}
if (!stats->buf.buf)
fatal("Failed to allocate first-pass stats buffer (%lu bytes)",
(unsigned long)stats->buf_alloc_sz);
nbytes = fread(stats->buf.buf, 1, stats->buf.sz, stats->file);
res = (nbytes == stats->buf.sz);
......@@ -222,7 +244,7 @@ void stats_close(stats_io_t *stats, int last_pass) {
void stats_write(stats_io_t *stats, const void *pkt, size_t len) {
if (stats->file) {
if (fwrite(pkt, 1, len, stats->file));
(void) fwrite(pkt, 1, len, stats->file);
} else {
if (stats->buf.sz + len > stats->buf_alloc_sz) {
size_t new_sz = stats->buf_alloc_sz + 64 * 1024;
......@@ -232,11 +254,8 @@ void stats_write(stats_io_t *stats, const void *pkt, size_t len) {
stats->buf_ptr = new_ptr + (stats->buf_ptr - (char *)stats->buf.buf);
stats->buf.buf = new_ptr;
stats->buf_alloc_sz = new_sz;
} else {
fprintf(stderr,
"\nFailed to realloc firstpass stats buffer.\n");
exit(EXIT_FAILURE);
}
} else
fatal("Failed to realloc firstpass stats buffer.");
}
memcpy(stats->buf_ptr, pkt, len);
......@@ -271,9 +290,25 @@ struct detect_buffer {
};
struct input_state {
char *fn;
FILE *file;
y4m_input y4m;
struct detect_buffer detect;
enum video_file_type file_type;
unsigned int w;
unsigned int h;
struct vpx_rational framerate;
int use_i420;
};
#define IVF_FRAME_HDR_SZ (4+8) /* 4 byte size + 8 byte timestamp */
static int read_frame(FILE *f, vpx_image_t *img, unsigned int file_type,
y4m_input *y4m, struct detect_buffer *detect) {
static int read_frame(struct input_state *input, vpx_image_t *img) {
FILE *f = input->file;
enum video_file_type file_type = input->file_type;
y4m_input *y4m = &input->y4m;
struct detect_buffer *detect = &input->detect;
int plane = 0;
int shortread = 0;
......@@ -288,7 +323,7 @@ static int read_frame(FILE *f, vpx_image_t *img, unsigned int file_type,
* write_ivf_frame_header() for documentation on the frame header
* layout.
*/
if (fread(junk, 1, IVF_FRAME_HDR_SZ, f));
(void) fread(junk, 1, IVF_FRAME_HDR_SZ, f);
}
for (plane = 0; plane < 3; plane++) {
......@@ -346,13 +381,14 @@ unsigned int file_is_y4m(FILE *infile,
}
#define IVF_FILE_HDR_SZ (32)
unsigned int file_is_ivf(FILE *infile,
unsigned int *fourcc,
unsigned int *width,
unsigned int *height,
struct detect_buffer *detect) {
unsigned int file_is_ivf(struct input_state *input,
unsigned int *fourcc) {
char raw_hdr[IVF_FILE_HDR_SZ];
int is_ivf = 0;
FILE *infile = input->file;
unsigned int *width = &input->w;
unsigned int *height = &input->h;
struct detect_buffer *detect = &input->detect;
if (memcmp(detect->buf, "DKIF", 4) != 0)
return 0;
......@@ -366,8 +402,8 @@ unsigned int file_is_ivf(FILE *infile,
is_ivf = 1;
if (mem_get_le16(raw_hdr + 4) != 0)
fprintf(stderr, "Error: Unrecognized IVF version! This file may not"
" decode properly.");
warn("Unrecognized IVF version! This file may not decode "
"properly.");
*fourcc = mem_get_le32(raw_hdr + 8);
}
......@@ -406,7 +442,7 @@ static void write_ivf_file_header(FILE *outfile,
mem_put_le32(header + 24, frame_cnt); /* length */
mem_put_le32(header + 28, 0); /* unused */
if (fwrite(header, 1, 32, outfile));
(void) fwrite(header, 1, 32, outfile);
}
......@@ -419,11 +455,17 @@ static void write_ivf_frame_header(FILE *outfile,
return;
pts = pkt->data.frame.pts;
mem_put_le32(header, pkt->data.frame.sz);
mem_put_le32(header, (int)pkt->data.frame.sz);
mem_put_le32(header + 4, pts & 0xFFFFFFFF);
mem_put_le32(header + 8, pts >> 32);
if (fwrite(header, 1, 12, outfile));
(void) fwrite(header, 1, 12, outfile);
}
static void write_ivf_frame_size(FILE *outfile, size_t size) {
char header[4];
mem_put_le32(header, (int)size);
(void) fwrite(header, 1, 4, outfile);
}
......@@ -468,13 +510,13 @@ struct EbmlGlobal {
void Ebml_Write(EbmlGlobal *glob, const void *buffer_in, unsigned long len) {
if (fwrite(buffer_in, 1, len, glob->stream));
(void) fwrite(buffer_in, 1, len, glob->stream);
}
#define WRITE_BUFFER(s) \
for(i = len-1; i>=0; i--)\
{ \
x = *(const s *)buffer_in >> (i * CHAR_BIT); \
x = (char)(*(const s *)buffer_in >> (i * CHAR_BIT)); \
Ebml_Write(glob, &x, 1); \
}
void Ebml_Serialize(EbmlGlobal *glob, const void *buffer_in, int buffer_size, unsigned long len) {
......@@ -520,9 +562,9 @@ static void Ebml_SerializeUnsigned32(EbmlGlobal *glob, unsigned long class_id, u
static void
Ebml_StartSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc,
unsigned long class_id) {
// todo this is always taking 8 bytes, this may need later optimization
// this is a key that says length unknown
uint64_t unknownLen = LITERALU64(0x01FFFFFFFFFFFFFF);
/* todo this is always taking 8 bytes, this may need later optimization */
/* this is a key that says length unknown */
uint64_t unknownLen = LITERALU64(0x01FFFFFF, 0xFFFFFFFF);
Ebml_WriteID(glob, class_id);
*ebmlLoc = ftello(glob->stream);
......@@ -539,7 +581,7 @@ Ebml_EndSubElement(EbmlGlobal *glob, EbmlLoc *ebmlLoc) {
/* Calculate the size of this element */
size = pos - *ebmlLoc - 8;
size |= LITERALU64(0x0100000000000000);
size |= LITERALU64(0x01000000, 0x00000000);
/* Seek back to the beginning of the element and write the new size */
fseeko(glob->stream, *ebmlLoc, SEEK_SET);
......@@ -584,9 +626,20 @@ write_webm_seek_info(EbmlGlobal *ebml) {
Ebml_EndSubElement(ebml, &start);
}
{
// segment info
/* segment info */
EbmlLoc startInfo;
uint64_t frame_time;
char version_string[64];
/* Assemble version string */
if (ebml->debug)
strcpy(version_string, "vpxenc");
else {
strcpy(version_string, "vpxenc ");
strncat(version_string,
vpx_codec_version_str(),
sizeof(version_string) - 1 - strlen(version_string));
}
frame_time = (uint64_t)1000 * ebml->framerate.den
/ ebml->framerate.num;
......@@ -594,11 +647,9 @@ write_webm_seek_info(EbmlGlobal *ebml) {
Ebml_StartSubElement(ebml, &startInfo, Info);
Ebml_SerializeUnsigned(ebml, TimecodeScale, 1000000);
Ebml_SerializeFloat(ebml, Segment_Duration,
ebml->last_pts_ms + frame_time);
Ebml_SerializeString(ebml, 0x4D80,
ebml->debug ? "vpxenc" : "vpxenc" VERSION_STRING);
Ebml_SerializeString(ebml, 0x5741,
ebml->debug ? "vpxenc" : "vpxenc" VERSION_STRING);
(double)(ebml->last_pts_ms + frame_time));
Ebml_SerializeString(ebml, 0x4D80, version_string);
Ebml_SerializeString(ebml, 0x5741, version_string);
Ebml_EndSubElement(ebml, &startInfo);
}
}
......@@ -613,16 +664,16 @@ write_webm_file_header(EbmlGlobal *glob,
EbmlLoc start;
Ebml_StartSubElement(glob, &start, EBML);
Ebml_SerializeUnsigned(glob, EBMLVersion, 1);
Ebml_SerializeUnsigned(glob, EBMLReadVersion, 1); // EBML Read Version
Ebml_SerializeUnsigned(glob, EBMLMaxIDLength, 4); // EBML Max ID Length
Ebml_SerializeUnsigned(glob, EBMLMaxSizeLength, 8); // EBML Max Size Length
Ebml_SerializeString(glob, DocType, "webm"); // Doc Type
Ebml_SerializeUnsigned(glob, DocTypeVersion, 2); // Doc Type Version
Ebml_SerializeUnsigned(glob, DocTypeReadVersion, 2); // Doc Type Read Version
Ebml_SerializeUnsigned(glob, EBMLReadVersion, 1);
Ebml_SerializeUnsigned(glob, EBMLMaxIDLength, 4);
Ebml_SerializeUnsigned(glob, EBMLMaxSizeLength, 8);
Ebml_SerializeString(glob, DocType, "webm");
Ebml_SerializeUnsigned(glob, DocTypeVersion, 2);
Ebml_SerializeUnsigned(glob, DocTypeReadVersion, 2);
Ebml_EndSubElement(glob, &start);
}
{
Ebml_StartSubElement(glob, &glob->startSegment, Segment); // segment
Ebml_StartSubElement(glob, &glob->startSegment, Segment);
glob->position_reference = ftello(glob->stream);
glob->framerate = *fps;
write_webm_seek_info(glob);
......@@ -640,7 +691,7 @@ write_webm_file_header(EbmlGlobal *glob,
Ebml_SerializeUnsigned(glob, TrackNumber, trackNumber);
glob->track_id_pos = ftello(glob->stream);
Ebml_SerializeUnsigned32(glob, TrackUID, trackID);
Ebml_SerializeUnsigned(glob, TrackType, 1); // video is always 1
Ebml_SerializeUnsigned(glob, TrackType, 1);
Ebml_SerializeString(glob, CodecID, "V_VP8");
{
unsigned int pixelWidth = cfg->g_w;
......@@ -653,13 +704,13 @@ write_webm_file_header(EbmlGlobal *glob,
Ebml_SerializeUnsigned(glob, PixelHeight, pixelHeight);
Ebml_SerializeUnsigned(glob, StereoMode, stereo_fmt);
Ebml_SerializeFloat(glob, FrameRate, frameRate);
Ebml_EndSubElement(glob, &videoStart); // Video
Ebml_EndSubElement(glob, &videoStart);
}
Ebml_EndSubElement(glob, &start); // Track Entry
Ebml_EndSubElement(glob, &start); /* Track Entry */
}
Ebml_EndSubElement(glob, &trackStart);
}
// segment element is open
/* segment element is open */
}
}
......@@ -686,7 +737,7 @@ write_webm_block(EbmlGlobal *glob,
if (pts_ms - glob->cluster_timecode > SHRT_MAX)
start_cluster = 1;
else
block_timecode = pts_ms - glob->cluster_timecode;
block_timecode = (unsigned short)pts_ms - glob->cluster_timecode;
is_keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY);
if (start_cluster || is_keyframe) {
......@@ -696,9 +747,9 @@ write_webm_block(EbmlGlobal *glob,
/* Open the new cluster */
block_timecode = 0;
glob->cluster_open = 1;
glob->cluster_timecode = pts_ms;
glob->cluster_timecode = (uint32_t)pts_ms;
glob->cluster_pos = ftello(glob->stream);
Ebml_StartSubElement(glob, &glob->startCluster, Cluster); // cluster
Ebml_StartSubElement(glob, &glob->startCluster, Cluster); /* cluster */
Ebml_SerializeUnsigned(glob, Timecode, glob->cluster_timecode);
/* Save a cue point if this is a keyframe. */
......@@ -709,10 +760,8 @@ write_webm_block(EbmlGlobal *glob,
(glob->cues + 1) * sizeof(struct cue_entry));
if (new_cue_list)
glob->cue_list = new_cue_list;
else {
fprintf(stderr, "\nFailed to realloc cue list.\n");
exit(EXIT_FAILURE);
}
else
fatal("Failed to realloc cue list.");
cue = &glob->cue_list[glob->cues];
cue->time = glob->cluster_timecode;
......@@ -724,7 +773,7 @@ write_webm_block(EbmlGlobal *glob,
/* Write the Simple Block */
Ebml_WriteID(glob, SimpleBlock);
block_length = pkt->data.frame.sz + 4;
block_length = (unsigned long)pkt->data.frame.sz + 4;
block_length |= 0x10000000;
Ebml_Serialize(glob, &block_length, sizeof(block_length), 4);
......@@ -741,7 +790,7 @@ write_webm_block(EbmlGlobal *glob,
flags |= 0x08;
Ebml_Write(glob, &flags, 1);
Ebml_Write(glob, pkt->data.frame.buf, pkt->data.frame.sz);
Ebml_Write(glob, pkt->data.frame.buf, (unsigned long)pkt->data.frame.sz);
}
......@@ -753,7 +802,7 @@ write_webm_file_footer(EbmlGlobal *glob, long hash) {
{
EbmlLoc start;
int i;
unsigned int i;
glob->cue_pos = ftello(glob->stream);
Ebml_StartSubElement(glob, &start, Cues);
......@@ -771,7 +820,6 @@ write_webm_file_footer(EbmlGlobal *glob, long hash) {
Ebml_SerializeUnsigned(glob, CueTrack, 1);
Ebml_SerializeUnsigned64(glob, CueClusterPosition,
cue->loc - glob->position_reference);
// Ebml_SerializeUnsigned(glob, CueBlockNumber, cue->blockNumber);
Ebml_EndSubElement(glob, &start);
}
Ebml_EndSubElement(glob, &start);
......@@ -847,7 +895,7 @@ static double vp8_mse2psnr(double Samples, double Peak, double Mse) {
if ((double)Mse > 0.0)
psnr = 10.0 * log10(Peak * Peak * Samples / Mse);
else
psnr = MAX_PSNR; // Limit to prevent / 0
psnr = MAX_PSNR; /* Limit to prevent / 0 */
if (psnr > MAX_PSNR)
psnr = MAX_PSNR;
......@@ -857,7 +905,6 @@ static double vp8_mse2psnr(double Samples, double Peak, double Mse) {
#include "args.h"
static const arg_def_t debugmode = ARG_DEF("D", "debug", 0,
"Debug mode (makes output deterministic)");
static const arg_def_t outputfile = ARG_DEF("o", "output", 1,
......@@ -886,33 +933,29 @@ static const arg_def_t good_dl = ARG_DEF(NULL, "good", 0,
"Use Good Quality Deadline");
static const arg_def_t rt_dl = ARG_DEF(NULL, "rt", 0,
"Use Realtime Quality Deadline");
static const arg_def_t quietarg = ARG_DEF("q", "quiet", 0,
"Do not print encode progress");
static const arg_def_t verbosearg = ARG_DEF("v", "verbose", 0,
"Show encoder parameters");
static const arg_def_t psnrarg = ARG_DEF(NULL, "psnr", 0,
"Show PSNR in status line");
static const arg_def_t recontest = ARG_DEF(NULL, "test-decode", 0,
"Test enocde/decode have machted recon buffer");
"Test encode/decode mismatch");
static const arg_def_t framerate = ARG_DEF(NULL, "fps", 1,
"Stream frame rate (rate/scale)");
static const arg_def_t use_ivf = ARG_DEF(NULL, "ivf", 0,
"Output IVF (default is WebM)");
static const arg_def_t out_part = ARG_DEF("P", "output-partitions", 0,
"Makes encoder output partitions. Requires IVF output!");
static const arg_def_t q_hist_n = ARG_DEF(NULL, "q-hist", 1,
"Show quantizer histogram (n-buckets)");
static const arg_def_t rate_hist_n = ARG_DEF(NULL, "rate-hist", 1,
"Show rate histogram (n-buckets)");
#if CONFIG_LOSSLESS
static const arg_def_t lossless_enabled = ARG_DEF(NULL, "lossless", 0,
"Enable lossless compression");
#endif
static const arg_def_t *main_args[] = {
&debugmode,
&outputfile, &codecarg, &passes, &pass_arg, &fpf_name, &limit, &skip,
&deadline,
&best_dl, &good_dl, &rt_dl,
&verbosearg, &psnrarg, &recontest, &use_ivf, &q_hist_n, &rate_hist_n,
#if CONFIG_LOSSLESS
&lossless_enabled,
#endif
&deadline, &best_dl, &good_dl, &rt_dl,
&quietarg, &verbosearg, &psnrarg, &use_ivf, &out_part, &q_hist_n, &rate_hist_n,
NULL
};
......@@ -1048,13 +1091,16 @@ static const arg_def_t cq_level = ARG_DEF(NULL, "cq-level", 1,
"Constrained Quality Level");
static const arg_def_t max_intra_rate_pct = ARG_DEF(NULL, "max-intra-rate", 1,
"Max I-frame bitrate (pct)");
#if CONFIG_LOSSLESS
static const arg_def_t lossless = ARG_DEF(NULL, "lossless", 1, "Lossless mode");
#endif
static const arg_def_t *vp8_args[] = {
&cpu_used, &auto_altref, &noise_sens, &sharpness, &static_thresh,
&token_parts, &arnr_maxframes, &arnr_strength, &arnr_type,
&tune_ssim, &cq_level, &max_intra_rate_pct,
#if CONFIG_LOSSLESS
&lossless_enabled,
&lossless,
#endif
NULL
};
......@@ -1137,7 +1183,7 @@ static int merge_hist_buckets(struct hist_bucket *bucket,
while (buckets > max_buckets) {
int last_bucket = buckets - 1;
// merge the small bucket with an adjacent one.
/* merge the small bucket with an adjacent one. */
if (small_bucket == 0)
merge_bucket = 1;
else if (small_bucket == last_bucket)
......@@ -1230,7 +1276,7 @@ static void show_histogram(const struct hist_bucket *bucket,
int j;
float pct;
pct = 100.0 * (float)bucket[i].count / (float)total;
pct = (float)(100.0 * bucket[i].count / total);
len = HIST_BAR_MAX * bucket[i].count / scale;
if (len < 1)
len = 1;
......@@ -1293,7 +1339,7 @@ static void init_rate_histogram(struct rate_hist *hist,
*/
hist->samples = cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000;
// prevent division by zero
/* prevent division by zero */
if (hist->samples == 0)
hist->samples = 1;
......@@ -1324,7 +1370,7 @@ static void update_rate_histogram(struct rate_hist *hist,
idx = hist->frames++ % hist->samples;
hist->pts[idx] = now;
hist->sz[idx] = pkt->data.frame.sz;
hist->sz[idx] = (int)pkt->data.frame.sz;
if (now < cfg->rc_buf_initial_sz)
return;
......@@ -1345,15 +1391,15 @@ static void update_rate_histogram(struct rate_hist *hist,
return;
avg_bitrate = sum_sz * 8 * 1000 / (now - then);
idx = avg_bitrate * (RATE_BINS / 2) / (cfg->rc_target_bitrate * 1000);
idx = (int)(avg_bitrate * (RATE_BINS / 2) / (cfg->rc_target_bitrate * 1000));
if (idx < 0)
idx = 0;
if (idx > RATE_BINS - 1)
idx = RATE_BINS - 1;
if (hist->bucket[idx].low > avg_bitrate)
hist->bucket[idx].low = avg_bitrate;
hist->bucket[idx].low = (int)avg_bitrate;
if (hist->bucket[idx].high < avg_bitrate)
hist->bucket[idx].high = avg_bitrate;
hist->bucket[idx].high = (int)avg_bitrate;
hist->bucket[idx].count++;
hist->total++;
}
......@@ -1377,7 +1423,8 @@ static void show_rate_histogram(struct rate_hist *hist,
}
static int compare_img(vpx_image_t *img1, vpx_image_t *img2) {
static int compare_img(vpx_image_t *img1, vpx_image_t *img2)
{
int match = 1;
int i;
......@@ -1386,86 +1433,113 @@ static int compare_img(vpx_image_t *img1, vpx_image_t *img2) {
match &= (img1->h == img2->h);
for (i = 0; i < img1->d_h; i++)
match &= (memcmp(img1->planes[VPX_PLANE_Y] + i * img1->stride[VPX_PLANE_Y],
img2->planes[VPX_PLANE_Y] + i * img2->stride[VPX_PLANE_Y],
match &= (memcmp(img1->planes[VPX_PLANE_Y]+i*img1->stride[VPX_PLANE_Y],
img2->planes[VPX_PLANE_Y]+i*img2->stride[VPX_PLANE_Y],
img1->d_w) == 0);
for (i = 0; i < img1->d_h / 2; i++)
match &= (memcmp(img1->planes[VPX_PLANE_U] + i * img1->stride[VPX_PLANE_U],
img2->planes[VPX_PLANE_U] + i * img2->stride[VPX_PLANE_U],
img1->d_w / 2) == 0);
for (i = 0; i < img1->d_h/2; i++)
match &= (memcmp(img1->planes[VPX_PLANE_U]+i*img1->stride[VPX_PLANE_U],
img2->planes[VPX_PLANE_U]+i*img2->stride[VPX_PLANE_U],
(img1->d_w + 1) / 2) == 0);
for (i = 0; i < img1->d_h / 2; i++)
match &= (memcmp(img1->planes[VPX_PLANE_V] + i * img1->stride[VPX_PLANE_U],
img2->planes[VPX_PLANE_V] + i * img2->stride[VPX_PLANE_U],
img1->d_w / 2) == 0);
for (i = 0; i < img1->d_h/2; i++)
match &= (memcmp(img1->planes[VPX_PLANE_V]+i*img1->stride[VPX_PLANE_U],
img2->planes[VPX_PLANE_V]+i*img2->stride[VPX_PLANE_U],
(img1->d_w + 1) / 2) == 0);
return match;
}
#define ARG_CTRL_CNT_MAX 10
#define NELEMENTS(x) (sizeof(x)/sizeof(x[0]))
#define ARG_CTRL_CNT_MAX NELEMENTS(vp8_arg_ctrl_map)
/* Configuration elements common to all streams */
struct global_config {
const struct codec_item *codec;
int passes;
int pass;
int usage;
int deadline;
int use_i420;
int quiet;
int verbose;
int limit;
int skip_frames;
int show_psnr;
int test_decode;
int have_framerate;
struct vpx_rational framerate;
int out_part;
int debug;
int show_q_hist_buckets;
int show_rate_hist_buckets;
};
int main(int argc, const char **argv_) {
vpx_codec_ctx_t encoder;
const char *in_fn = NULL, *out_fn = NULL, *stats_fn = NULL;
int i;
FILE *infile, *outfile;
vpx_codec_enc_cfg_t cfg;
vpx_codec_err_t res;
int pass, one_pass_only = 0;
stats_io_t stats;
vpx_image_t raw;
const struct codec_item *codec = codecs;
int frame_avail, got_data;
struct arg arg;
char **argv, **argi, **argj;