Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions bin/verify_scores
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import mpeg_settings
import encoder
import optimizer
import pick_codec

import score_tools

def ClassifyScoreRelation(old_score, new_score):
if not old_score:
Expand All @@ -45,19 +45,22 @@ def ClassifyScoreRelation(old_score, new_score):
return 'improved'
return 'worsened'

def VerifyOneTarget(codec_names, rate, videofile, old_scores, score):
def VerifyOneTarget(codec_names, rate, videofile, scorer_function,
old_scores, score):
# pylint: disable=too-many-arguments, too-many-locals
change_counts = collections.Counter()
for codec_name in codec_names:
codec = pick_codec.PickCodec(codec_name)
old_optimizer = optimizer.Optimizer(codec, scoredir=old_scores)
new_optimizer = optimizer.Optimizer(codec)
bestsofar = new_optimizer.RebaseEncoding(
old_optimizer.BestEncoding(rate, videofile))
old_optimizer = optimizer.Optimizer(codec, score_function=scorer_function,
scoredir=old_scores)
new_optimizer = optimizer.Optimizer(codec, score_function=scorer_function)
old_best_run = old_optimizer.BestEncoding(rate, videofile)
bestsofar = new_optimizer.RebaseEncoding(old_best_run)
bestsofar.Recover()
if score:
bestsofar.Execute().Store()
try:
old_score = old_optimizer.Score(bestsofar)
old_score = old_optimizer.Score(old_best_run)
except encoder.Error:
print 'No old score for %s %d %s, continuing' % \
(bestsofar.encoder.Hashname(), rate, videofile.filename)
Expand All @@ -71,15 +74,30 @@ def VerifyOneTarget(codec_names, rate, videofile, old_scores, score):
result,
old_score if old_score else float('-inf'),
new_score if new_score else float('-inf'))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again reminder to consider making this function testable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

print 'Command line:', old_best_run.EncodeCommandLine()
if 'encoder_version' in old_best_run.Result():
print 'Old version:', old_best_run.Result()['encoder_version']
else:
print 'Old version unknown'
print 'New version:', bestsofar.Result()['encoder_version']
print 'PSNR: %5.3f -> %5.3f' % (old_best_run.Result()['psnr'],
bestsofar.Result()['psnr'])
print 'Bitrate: %d -> %d' % (old_best_run.Result()['bitrate'],
bestsofar.Result()['bitrate'])
print 'Encode time: %5.3f -> %5.3f' % (
old_best_run.Result()['encode_cputime'],
bestsofar.Result()['encode_cputime'])
print

return change_counts

def VerifyResults(codec_names, old_scores, score):
def VerifyResults(codec_names, scorer_function, old_scores, score):
change_counts = collections.Counter()
for rate, filename in mpeg_settings.MpegFiles().AllFilesAndRates():
videofile = encoder.Videofile(filename)
change_counts.update(VerifyOneTarget(codec_names, rate,
videofile, old_scores, score))
videofile, scorer_function,
old_scores, score))
print 'Result so far:', dict(change_counts)
return change_counts

Expand All @@ -88,9 +106,12 @@ def main():
parser.add_argument('codec_names', nargs='*',
default=pick_codec.AllCodecNames())
parser.add_argument('--score', action='store_true', default=False)
parser.add_argument('--criterion', default='psnr')
parser.add_argument('--old_scores', default='snapshot')
args = parser.parse_args()
change_count = VerifyResults(args.codec_names, old_scores=args.old_scores,
scorer_function = score_tools.PickScorer(args.criterion)
change_count = VerifyResults(args.codec_names,
scorer_function, old_scores=args.old_scores,
score=args.score)
print 'Change evaluations: ', dict(change_count)
return 0
Expand Down
5 changes: 3 additions & 2 deletions compile_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ cd $WORKDIR/third_party
build_vpxenc() {
# Build the vpxenc and vpxdec binaries
if [ ! -d libvpx ]; then
git clone http://git.chromium.org/webm/libvpx.git
git clone https://chromium.googlesource.com/webm/libvpx
fi
cd libvpx
# Ensure we check out exactly a consistent version.
git checkout -f master
#git checkout v1.3.0
# Check out the Oct 20 2014 version of libvpx.
git checkout 9c98fb2bab6125a0614576bf7635981163b1cc79
# git checkout 9c98fb2bab6125a0614576bf7635981163b1cc79
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about cleaning up these comments and commented out lines?

git checkout v1.6.0
./configure
# Leftovers from previous compilations may be troublesome.
make clean
Expand Down
12 changes: 8 additions & 4 deletions lib/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,14 @@ def _FilesToEncodings(self, files, videofile, bitrate=None,
encoder=None):
candidates = []
for full_filename in files:
candidate = Encoding(
encoder or self._FileNameToEncoder(full_filename),
bitrate or _FileNameToBitrate(full_filename),
videofile or _FileNameToVideofile(full_filename))
try:
candidate = Encoding(
encoder or self._FileNameToEncoder(full_filename),
bitrate or _FileNameToBitrate(full_filename),
videofile or _FileNameToVideofile(full_filename))
except ParseError as err:
self.bad_encodings[full_filename] = err
continue
try:
candidate.Recover()
candidates.append(candidate)
Expand Down
4 changes: 3 additions & 1 deletion lib/vp9.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def __init__(self, name='vp9'):
super(Vp9Codec, self).__init__(name)
self.extension = 'webm'
self.option_set = encoder.OptionSet(
encoder.IntegerOption('cpu-used', 0, 16),
encoder.IntegerOption('cpu-used', 0, 8),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this cpu-used change mean? The description in http://www.webmproject.org/docs/encoder-parameters/ seems a bit cryptic to me. Which is fancy words for that I don't understand it. :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They used to use the range 9..16 for experimental speedups. Now I think they use -8..-1 for the same purpose. I've cut off the upper numbers (which will invalidate the parameter sets that use those numbers).

# The "best" option gives encodes that are too slow to be useful.
encoder.ChoiceOption(['good', 'rt']).Mandatory(),
encoder.IntegerOption('passes', 1, 2),
encoder.IntegerOption('aq-mode', 0, 4),
encoder.Option('end-usage', ['cbr', 'vbr', 'cq', 'q']),
)

def StartEncoder(self, context):
Expand Down
38 changes: 18 additions & 20 deletions third_party/vp8_fixed_q.patch
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ Change-Id: Ic0000f50d5edf6351dad4ed0d398f7a88922bece
5 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 3cceb5a..c737d3c 100644
index d5a0fff..4487ab4 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -1578,7 +1578,8 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
@@ -1615,7 +1615,8 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
if (oxcf->worst_allowed_q < 0)
cpi->oxcf.fixed_q = q_trans[0];
else
Expand All @@ -51,12 +51,12 @@ index 3cceb5a..c737d3c 100644
if (oxcf->alt_q < 0)
cpi->oxcf.alt_q = q_trans[0];
diff --git a/vp8/vp8_cx_iface.c b/vp8/vp8_cx_iface.c
index b1b079c..b6bef48 100644
index 22a82b7..0c75011 100644
--- a/vp8/vp8_cx_iface.c
+++ b/vp8/vp8_cx_iface.c
@@ -132,8 +132,19 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
@@ -139,8 +139,19 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000);
RANGE_CHECK(cfg, g_timebase.num, 1, cfg->g_timebase.den);
RANGE_CHECK(cfg, g_timebase.num, 1, 1000000000);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes in vp8_fixed_q.patch are made by:

  • Applying the previous version of the patch
  • Finding out were the patch failed to apply
  • Adjusting the code until the non-applying part worked again

So this shouldn't be a change that I wrote, it should be a change from 1.3 to 1.6 in the file being patched. But I need to read the file really carefully to be sure that's the case!

RANGE_CHECK_HI(cfg, g_profile, 3);
- RANGE_CHECK_HI(cfg, rc_max_quantizer, 63);
- RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer);
Expand All @@ -76,7 +76,7 @@ index b1b079c..b6bef48 100644
RANGE_CHECK_HI(cfg, g_threads, 64);
#if CONFIG_REALTIME_ONLY
RANGE_CHECK_HI(cfg, g_lag_in_frames, 0);
@@ -333,7 +344,11 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
@@ -342,7 +353,11 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf,
oxcf->best_allowed_q = cfg.rc_min_quantizer;
oxcf->worst_allowed_q = cfg.rc_max_quantizer;
oxcf->cq_level = vp8_cfg.cq_level;
Expand All @@ -89,7 +89,7 @@ index b1b079c..b6bef48 100644

oxcf->under_shoot_pct = cfg.rc_undershoot_pct;
oxcf->over_shoot_pct = cfg.rc_overshoot_pct;
@@ -1271,6 +1286,10 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] =
@@ -1315,6 +1330,10 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] =
256, /* rc_target_bandwidth */
4, /* rc_min_quantizer */
63, /* rc_max_quantizer */
Expand All @@ -101,10 +101,10 @@ index b1b079c..b6bef48 100644
100, /* rc_overshoot_pct */

diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c
index d3c2a13..7cb89b4 100644
index 10d6893..03b84d6 100644
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -1344,6 +1344,12 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
@@ -1596,6 +1596,12 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
256, // rc_target_bandwidth
0, // rc_min_quantizer
63, // rc_max_quantizer
Expand All @@ -113,15 +113,15 @@ index d3c2a13..7cb89b4 100644
+ -1,
+ -1,
+ -1,
+
100, // rc_undershoot_pct
100, // rc_overshoot_pct
+
25, // rc_undershoot_pct
25, // rc_overshoot_pct

diff --git a/vpx/vpx_encoder.h b/vpx/vpx_encoder.h
index 044243d..41a6b3c 100644
index 955e873..c7939e4 100644
--- a/vpx/vpx_encoder.h
+++ b/vpx/vpx_encoder.h
@@ -519,6 +519,11 @@ extern "C" {
@@ -538,6 +538,11 @@ extern "C" {
*/
unsigned int rc_max_quantizer;

Expand All @@ -134,10 +134,10 @@ index 044243d..41a6b3c 100644
/*
* bitrate tolerance
diff --git a/vpxenc.c b/vpxenc.c
index 2b89fc1..b9364e6 100644
index efcf064..d34ad7a 100644
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -282,6 +282,14 @@ static const arg_def_t min_quantizer = ARG_DEF(
@@ -284,6 +284,14 @@ static const arg_def_t min_quantizer = ARG_DEF(
NULL, "min-q", 1, "Minimum (best) quantizer");
static const arg_def_t max_quantizer = ARG_DEF(
NULL, "max-q", 1, "Maximum (worst) quantizer");
Expand All @@ -152,7 +152,7 @@ index 2b89fc1..b9364e6 100644
static const arg_def_t undershoot_pct = ARG_DEF(
NULL, "undershoot-pct", 1, "Datarate undershoot (min) target (%)");
static const arg_def_t overshoot_pct = ARG_DEF(
@@ -295,7 +303,8 @@ static const arg_def_t buf_optimal_sz = ARG_DEF(
@@ -297,7 +305,8 @@ static const arg_def_t buf_optimal_sz = ARG_DEF(
static const arg_def_t *rc_args[] = {
&dropframe_thresh, &resize_allowed, &resize_width, &resize_height,
&resize_up_thresh, &resize_down_thresh, &end_usage, &target_bitrate,
Expand All @@ -162,7 +162,7 @@ index 2b89fc1..b9364e6 100644
&buf_initial_sz, &buf_optimal_sz, NULL
};

@@ -1105,6 +1114,14 @@ static int parse_stream_params(struct VpxEncoderConfig *global,
@@ -1159,6 +1168,14 @@ static int parse_stream_params(struct VpxEncoderConfig *global,
config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
} else if (arg_match(&arg, &max_quantizer, argi)) {
config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
Expand All @@ -177,6 +177,4 @@ index 2b89fc1..b9364e6 100644
} else if (arg_match(&arg, &undershoot_pct, argi)) {
config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
} else if (arg_match(&arg, &overshoot_pct, argi)) {
--
1.8.2.3