summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmkv/EbmlIDs.h2
-rw-r--r--vp8/common/onyx.h4
-rw-r--r--vp8/encoder/onyx_if.c65
-rw-r--r--vp8/encoder/ratectrl.c90
-rw-r--r--vp8/vp8_cx_iface.c13
-rw-r--r--vpx/vpx_encoder.h39
-rw-r--r--vpxenc.c37
7 files changed, 129 insertions, 121 deletions
diff --git a/libmkv/EbmlIDs.h b/libmkv/EbmlIDs.h
index 429747063..3418e3655 100644
--- a/libmkv/EbmlIDs.h
+++ b/libmkv/EbmlIDs.h
@@ -120,7 +120,7 @@ enum mkv
//video
Video = 0xE0,
FlagInterlaced = 0x9A,
-// StereoMode = 0x53B8,
+ StereoMode = 0x53B8,
PixelWidth = 0xB0,
PixelHeight = 0xBA,
PixelCropBottom = 0x54AA,
diff --git a/vp8/common/onyx.h b/vp8/common/onyx.h
index 426b8fc2b..a05951933 100644
--- a/vp8/common/onyx.h
+++ b/vp8/common/onyx.h
@@ -109,6 +109,7 @@ extern "C"
int noise_sensitivity; // parameter used for applying pre processing blur: recommendation 0
int Sharpness; // parameter used for sharpening output: recommendation 0:
int cpu_used;
+ unsigned int rc_max_intra_bitrate_pct;
// mode ->
//(0)=Realtime/Live Encoding. This mode is optimized for realtim encoding (for example, capturing
@@ -139,8 +140,9 @@ extern "C"
int end_usage; // vbr or cbr
- // shoot to keep buffer full at all times by undershooting a bit 95 recommended
+ // buffer targeting aggressiveness
int under_shoot_pct;
+ int over_shoot_pct;
// buffering parameters
int starting_buffer_level; // in seconds
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index d4a7de2b5..c7579e83a 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -1459,10 +1459,6 @@ static void init_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
cpi->avg_frame_qindex = cpi->oxcf.worst_allowed_q;
// Initialise the starting buffer levels
- cpi->oxcf.starting_buffer_level =
- rescale(cpi->oxcf.starting_buffer_level,
- cpi->oxcf.target_bandwidth, 1000);
-
cpi->buffer_level = cpi->oxcf.starting_buffer_level;
cpi->bits_off_target = cpi->oxcf.starting_buffer_level;
@@ -1635,6 +1631,10 @@ void vp8_change_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
// Convert target bandwidth from Kbit/s to Bit/s
cpi->oxcf.target_bandwidth *= 1000;
+ cpi->oxcf.starting_buffer_level =
+ rescale(cpi->oxcf.starting_buffer_level,
+ cpi->oxcf.target_bandwidth, 1000);
+
// Set or reset optimal and maximum buffer levels.
if (cpi->oxcf.optimal_buffer_level == 0)
cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
@@ -2659,16 +2659,17 @@ static int pick_frame_size(VP8_COMP *cpi)
if (cpi->pass == 2)
vp8_calc_auto_iframe_target_size(cpi);
- // 1 Pass there is no information on which to base size so use bandwidth per second * fixed fraction
else
#endif
- cpi->this_frame_target = cpi->oxcf.target_bandwidth / 2;
-
- // in error resilient mode the first frame is bigger since it likely contains
- // all the static background
- if (cpi->oxcf.error_resilient_mode == 1 || (cpi->compressor_speed == 2))
{
- cpi->this_frame_target *= 3; // 5;
+ /* 1 Pass there is no information on which to base size so use
+ * bandwidth per second * fraction of the initial buffer
+ * level
+ */
+ cpi->this_frame_target = cpi->oxcf.starting_buffer_level / 2;
+
+ if(cpi->this_frame_target > cpi->oxcf.target_bandwidth * 3 / 2)
+ cpi->this_frame_target = cpi->oxcf.target_bandwidth * 3 / 2;
}
// Key frame from VFW/auto-keyframe/first frame
@@ -2702,6 +2703,19 @@ static int pick_frame_size(VP8_COMP *cpi)
}
}
+ /* Apply limits on keyframe target.
+ *
+ * TODO: move this after consolidating
+ * vp8_calc_iframe_target_size() and vp8_calc_auto_iframe_target_size()
+ */
+ if (cm->frame_type == KEY_FRAME && cpi->oxcf.rc_max_intra_bitrate_pct)
+ {
+ unsigned int max_rate = cpi->av_per_frame_bandwidth
+ * cpi->oxcf.rc_max_intra_bitrate_pct / 100;
+
+ if (cpi->this_frame_target > max_rate)
+ cpi->this_frame_target = max_rate;
+ }
return 1;
}
@@ -5173,35 +5187,6 @@ int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, const
}
-static int calc_low_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, const vp8_variance_rtcd_vtable_t *rtcd)
-{
- int i, j;
- int Total = 0;
-
- unsigned char *src = source->y_buffer;
- unsigned char *dst = dest->y_buffer;
- (void)rtcd;
-
- // Loop through the Y plane raw and reconstruction data summing (square differences)
- for (i = 0; i < source->y_height; i += 16)
- {
- for (j = 0; j < source->y_width; j += 16)
- {
- unsigned int sse;
- VARIANCE_INVOKE(rtcd, mse16x16)(src + j, source->y_stride, dst + j, dest->y_stride, &sse);
-
- if (sse < 8096)
- Total += sse;
- }
-
- src += 16 * source->y_stride;
- dst += 16 * dest->y_stride;
- }
-
- return Total;
-}
-
-
int vp8_get_quantizer(VP8_PTR c)
{
VP8_COMP *cpi = (VP8_COMP *) c;
diff --git a/vp8/encoder/ratectrl.c b/vp8/encoder/ratectrl.c
index 9c8e86bb4..09a69bc71 100644
--- a/vp8/encoder/ratectrl.c
+++ b/vp8/encoder/ratectrl.c
@@ -662,8 +662,6 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
int min_frame_target;
int Adjustment;
- // Set the min frame bandwidth.
- //min_frame_target = estimate_min_frame_size( cpi );
min_frame_target = 0;
if (cpi->pass == 2)
@@ -817,11 +815,6 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
}
}
- // Set a reduced data rate target for our initial Q calculation.
- // This should help to save bits during earier sections.
- if ((cpi->oxcf.under_shoot_pct > 0) && (cpi->oxcf.under_shoot_pct <= 100))
- cpi->this_frame_target = (cpi->this_frame_target * cpi->oxcf.under_shoot_pct) / 100;
-
// Sanity check that the total sum of adjustments is not above the maximum allowed
// That is that having allowed for KF and GF penalties we have not pushed the
// current interframe target to low. If the adjustment we apply here is not capable of recovering
@@ -858,11 +851,6 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
percent_low =
(cpi->oxcf.optimal_buffer_level - cpi->buffer_level) /
one_percent_bits;
-
- if (percent_low > 100)
- percent_low = 100;
- else if (percent_low < 0)
- percent_low = 0;
}
// Are we overshooting the long term clip data rate...
else if (cpi->bits_off_target < 0)
@@ -870,16 +858,16 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
// Adjust per frame data target downwards to compensate.
percent_low = (int)(100 * -cpi->bits_off_target /
(cpi->total_byte_count * 8));
-
- if (percent_low > 100)
- percent_low = 100;
- else if (percent_low < 0)
- percent_low = 0;
}
+ if (percent_low > cpi->oxcf.under_shoot_pct)
+ percent_low = cpi->oxcf.under_shoot_pct;
+ else if (percent_low < 0)
+ percent_low = 0;
+
// lower the target bandwidth for this frame.
- cpi->this_frame_target =
- (cpi->this_frame_target * (100 - (percent_low / 2))) / 100;
+ cpi->this_frame_target -= (cpi->this_frame_target * percent_low)
+ / 200;
// Are we using allowing control of active_worst_allowed_q
// according to buffer level.
@@ -950,20 +938,29 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
}
else
{
- int percent_high;
+ int percent_high = 0;
- if (cpi->bits_off_target > cpi->oxcf.optimal_buffer_level)
+ if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
+ && (cpi->buffer_level > cpi->oxcf.optimal_buffer_level))
{
- percent_high = (int)(100 * (cpi->bits_off_target - cpi->oxcf.optimal_buffer_level) / (cpi->total_byte_count * 8));
+ percent_high = (cpi->buffer_level
+ - cpi->oxcf.optimal_buffer_level)
+ / one_percent_bits;
+ }
+ else if (cpi->bits_off_target > cpi->oxcf.optimal_buffer_level)
+ {
+ percent_high = (int)((100 * cpi->bits_off_target)
+ / (cpi->total_byte_count * 8));
+ }
- if (percent_high > 100)
- percent_high = 100;
- else if (percent_high < 0)
- percent_high = 0;
+ if (percent_high > cpi->oxcf.over_shoot_pct)
+ percent_high = cpi->oxcf.over_shoot_pct;
+ else if (percent_high < 0)
+ percent_high = 0;
- cpi->this_frame_target = (cpi->this_frame_target * (100 + (percent_high / 2))) / 100;
+ cpi->this_frame_target += (cpi->this_frame_target *
+ percent_high) / 200;
- }
// Are we allowing control of active_worst_allowed_q according to bufferl level.
if (cpi->auto_worst_q)
@@ -1419,39 +1416,6 @@ int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame)
return Q;
}
-static int estimate_min_frame_size(VP8_COMP *cpi)
-{
- double correction_factor;
- int bits_per_mb_at_max_q;
-
- // This funtion returns a default value for the first few frames untill the correction factor has had time to adapt.
- if (cpi->common.current_video_frame < 10)
- {
- if (cpi->pass == 2)
- return (cpi->min_frame_bandwidth);
- else
- return cpi->per_frame_bandwidth / 3;
- }
-
- /* // Select the appropriate correction factor based upon type of frame.
- if ( cpi->common.frame_type == KEY_FRAME )
- correction_factor = cpi->key_frame_rate_correction_factor;
- else
- {
- if ( cpi->common.refresh_alt_ref_frame || cpi->common.refresh_golden_frame )
- correction_factor = cpi->gf_rate_correction_factor;
- else
- correction_factor = cpi->rate_correction_factor;
- }*/
-
- // We estimate at half the value we get from vp8_bits_per_mb
- correction_factor = cpi->rate_correction_factor / 2.0;
-
- bits_per_mb_at_max_q = (int)(.5 + correction_factor * vp8_bits_per_mb[cpi->common.frame_type][MAXQ]);
-
- return (bits_per_mb_at_max_q * cpi->common.MBs) >> BPER_MB_NORMBITS;
-}
-
static int estimate_keyframe_frequency(VP8_COMP *cpi)
{
@@ -1468,8 +1432,10 @@ static int estimate_keyframe_frequency(VP8_COMP *cpi)
/* Assume a default of 1 kf every 2 seconds, or the max kf interval,
* whichever is smaller.
*/
+ int key_freq = cpi->oxcf.key_freq>0 ? cpi->oxcf.key_freq : 1;
av_key_frame_frequency = (int)cpi->output_frame_rate * 2;
- if (av_key_frame_frequency > cpi->oxcf.key_freq)
+
+ if (cpi->oxcf.auto_key && av_key_frame_frequency > key_freq)
av_key_frame_frequency = cpi->oxcf.key_freq;
cpi->prior_key_frame_distance[KEY_FRAME_CONTEXT - 1]
diff --git a/vp8/vp8_cx_iface.c b/vp8/vp8_cx_iface.c
index 973265c2e..db60bfe4f 100644
--- a/vp8/vp8_cx_iface.c
+++ b/vp8/vp8_cx_iface.c
@@ -151,7 +151,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
RANGE_CHECK_HI(cfg, g_lag_in_frames, 0);
#endif
RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_CQ);
- RANGE_CHECK_HI(cfg, rc_undershoot_pct, 100);
+ RANGE_CHECK_HI(cfg, rc_undershoot_pct, 1000);
+ RANGE_CHECK_HI(cfg, rc_overshoot_pct, 1000);
RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
RANGE_CHECK(cfg, kf_mode, VPX_KF_DISABLED, VPX_KF_AUTO);
//RANGE_CHECK_BOOL(cfg, g_delete_firstpassfile);
@@ -304,6 +305,7 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
}
oxcf->target_bandwidth = cfg.rc_target_bitrate;
+ oxcf->rc_max_intra_bitrate_pct = cfg.rc_max_intra_bitrate_pct;
oxcf->best_allowed_q = cfg.rc_min_quantizer;
oxcf->worst_allowed_q = cfg.rc_max_quantizer;
@@ -311,7 +313,7 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
oxcf->fixed_q = -1;
oxcf->under_shoot_pct = cfg.rc_undershoot_pct;
- //oxcf->over_shoot_pct = cfg.rc_overshoot_pct;
+ oxcf->over_shoot_pct = cfg.rc_overshoot_pct;
oxcf->maximum_buffer_size = cfg.rc_buf_sz;
oxcf->starting_buffer_level = cfg.rc_buf_initial_sz;
@@ -357,6 +359,7 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
printf("key_freq: %d\n", oxcf->key_freq);
printf("end_usage: %d\n", oxcf->end_usage);
printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct);
+ printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct);
printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level);
printf("optimal_buffer_level: %d\n", oxcf->optimal_buffer_level);
printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size);
@@ -1083,11 +1086,11 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] =
{0}, /* rc_twopass_stats_in */
#endif
256, /* rc_target_bandwidth */
-
+ 0, /* rc_max_intra_bitrate_pct */
4, /* rc_min_quantizer */
63, /* rc_max_quantizer */
- 95, /* rc_undershoot_pct */
- 200, /* rc_overshoot_pct */
+ 100, /* rc_undershoot_pct */
+ 100, /* rc_overshoot_pct */
6000, /* rc_max_buffer_size */
4000, /* rc_buffer_initial_size; */
diff --git a/vpx/vpx_encoder.h b/vpx/vpx_encoder.h
index 9c44414b2..6dbce0d56 100644
--- a/vpx/vpx_encoder.h
+++ b/vpx/vpx_encoder.h
@@ -398,6 +398,21 @@ extern "C" {
unsigned int rc_target_bitrate;
+ /*!\brief Max data rate for Intra frames
+ *
+ * This value controls additional clamping on the maximum size of a
+ * keyframe. It is expressed as a percentage of the average
+ * per-frame bitrate, with the special (and default) value 0 meaning
+ * unlimited, or no additional clamping beyond the codec's built-in
+ * algorithm.
+ *
+ * For example, to allocate no more than 4.5 frames worth of bitrate
+ * to a keyframe, set this to 450.
+ *
+ */
+ unsigned int rc_max_intra_bitrate_pct;
+
+
/*
* quantizer settings
*/
@@ -430,20 +445,28 @@ extern "C" {
*/
- /*!\brief Rate control undershoot tolerance
+ /*!\brief Rate control adaptation undershoot control
*
- * This value, expressed as a percentage of the target bitrate, describes
- * the target bitrate for easier frames, allowing bits to be saved for
- * harder frames. Set to zero to use the codec default.
+ * This value, expressed as a percentage of the target bitrate,
+ * controls the maximum allowed adaptation speed of the codec.
+ * This factor controls the maximum amount of bits that can
+ * be subtracted from the target bitrate in order to compensate
+ * for prior overshoot.
+ *
+ * Valid values in the range 0-1000.
*/
unsigned int rc_undershoot_pct;
- /*!\brief Rate control overshoot tolerance
+ /*!\brief Rate control adaptation overshoot control
+ *
+ * This value, expressed as a percentage of the target bitrate,
+ * controls the maximum allowed adaptation speed of the codec.
+ * This factor controls the maximum amount of bits that can
+ * be added to the target bitrate in order to compensate for
+ * prior undershoot.
*
- * This value, expressed as a percentage of the target bitrate, describes
- * the maximum allowed bitrate for a given frame. Set to zero to use the
- * codec default.
+ * Valid values in the range 0-1000.
*/
unsigned int rc_overshoot_pct;
diff --git a/vpxenc.c b/vpxenc.c
index 39256b665..6ea83fb56 100644
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -256,6 +256,16 @@ vpx_fixed_buf_t stats_get(stats_io_t *stats)
return stats->buf;
}
+/* Stereo 3D packed frame format */
+typedef enum stereo_format
+{
+ STEREO_FORMAT_MONO = 0,
+ STEREO_FORMAT_LEFT_RIGHT = 1,
+ STEREO_FORMAT_BOTTOM_TOP = 2,
+ STEREO_FORMAT_TOP_BOTTOM = 3,
+ STEREO_FORMAT_RIGHT_LEFT = 11
+} stereo_format_t;
+
enum video_file_type
{
FILE_TYPE_RAW,
@@ -606,7 +616,8 @@ write_webm_seek_info(EbmlGlobal *ebml)
static void
write_webm_file_header(EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,
- const struct vpx_rational *fps)
+ const struct vpx_rational *fps,
+ stereo_format_t stereo_fmt)
{
{
EbmlLoc start;
@@ -650,6 +661,7 @@ write_webm_file_header(EbmlGlobal *glob,
Ebml_StartSubElement(glob, &videoStart, Video);
Ebml_SerializeUnsigned(glob, PixelWidth, pixelWidth);
Ebml_SerializeUnsigned(glob, PixelHeight, pixelHeight);
+ Ebml_SerializeUnsigned(glob, StereoMode, stereo_fmt);
Ebml_SerializeFloat(glob, FrameRate, frameRate);
Ebml_EndSubElement(glob, &videoStart); //Video
}
@@ -916,6 +928,16 @@ static const arg_def_t width = ARG_DEF("w", "width", 1,
"Frame width");
static const arg_def_t height = ARG_DEF("h", "height", 1,
"Frame height");
+static const struct arg_enum_list stereo_mode_enum[] = {
+ {"mono" , STEREO_FORMAT_MONO},
+ {"left-right", STEREO_FORMAT_LEFT_RIGHT},
+ {"bottom-top", STEREO_FORMAT_BOTTOM_TOP},
+ {"top-bottom", STEREO_FORMAT_TOP_BOTTOM},
+ {"right-left", STEREO_FORMAT_RIGHT_LEFT},
+ {NULL, 0}
+};
+static const arg_def_t stereo_mode = ARG_DEF_ENUM(NULL, "stereo-mode", 1,
+ "Stereo 3D video format", stereo_mode_enum);
static const arg_def_t timebase = ARG_DEF(NULL, "timebase", 1,
"Stream timebase (frame duration)");
static const arg_def_t error_resilient = ARG_DEF(NULL, "error-resilient", 1,
@@ -926,7 +948,7 @@ static const arg_def_t lag_in_frames = ARG_DEF(NULL, "lag-in-frames", 1,
static const arg_def_t *global_args[] =
{
&use_yv12, &use_i420, &usage, &threads, &profile,
- &width, &height, &timebase, &framerate, &error_resilient,
+ &width, &height, &stereo_mode, &timebase, &framerate, &error_resilient,
&lag_in_frames, NULL
};
@@ -962,11 +984,14 @@ static const arg_def_t buf_initial_sz = ARG_DEF(NULL, "buf-initial-sz", 1,
"Client initial buffer size (ms)");
static const arg_def_t buf_optimal_sz = ARG_DEF(NULL, "buf-optimal-sz", 1,
"Client optimal buffer size (ms)");
+static const arg_def_t max_intra_rate_pct = ARG_DEF(NULL, "max-intra-rate", 1,
+ "Max I-frame bitrate (pct)");
static const arg_def_t *rc_args[] =
{
&dropframe_thresh, &resize_allowed, &resize_up_thresh, &resize_down_thresh,
&end_usage, &target_bitrate, &min_quantizer, &max_quantizer,
&undershoot_pct, &overshoot_pct, &buf_sz, &buf_initial_sz, &buf_optimal_sz,
+ &max_intra_rate_pct,
NULL
};
@@ -1084,7 +1109,6 @@ static void usage_exit()
#define ARG_CTRL_CNT_MAX 10
-
int main(int argc, const char **argv_)
{
vpx_codec_ctx_t encoder;
@@ -1120,6 +1144,7 @@ int main(int argc, const char **argv_)
uint64_t psnr_samples_total = 0;
double psnr_totals[4] = {0, 0, 0, 0};
int psnr_count = 0;
+ stereo_format_t stereo_fmt = STEREO_FORMAT_MONO;
exec_name = argv_[0];
ebml.last_pts_ms = -1;
@@ -1259,6 +1284,8 @@ int main(int argc, const char **argv_)
cfg.g_w = arg_parse_uint(&arg);
else if (arg_match(&arg, &height, argi))
cfg.g_h = arg_parse_uint(&arg);
+ else if (arg_match(&arg, &stereo_mode, argi))
+ stereo_fmt = arg_parse_enum_or_int(&arg);
else if (arg_match(&arg, &timebase, argi))
cfg.g_timebase = arg_parse_rational(&arg);
else if (arg_match(&arg, &error_resilient, argi))
@@ -1279,6 +1306,8 @@ int main(int argc, const char **argv_)
cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
else if (arg_match(&arg, &target_bitrate, argi))
cfg.rc_target_bitrate = arg_parse_uint(&arg);
+ else if (arg_match(&arg, &max_intra_rate_pct, argi))
+ cfg.rc_max_intra_bitrate_pct = arg_parse_uint(&arg);
else if (arg_match(&arg, &min_quantizer, argi))
cfg.rc_min_quantizer = arg_parse_uint(&arg);
else if (arg_match(&arg, &max_quantizer, argi))
@@ -1557,7 +1586,7 @@ int main(int argc, const char **argv_)
if(write_webm)
{
ebml.stream = outfile;
- write_webm_file_header(&ebml, &cfg, &arg_framerate);
+ write_webm_file_header(&ebml, &cfg, &arg_framerate, stereo_fmt);
}
else
write_ivf_file_header(outfile, &cfg, codec->fourcc, 0);