Yaowu Xu [Fri, 13 Jan 2012 22:37:17 +0000 (14:37 -0800)]
new loop filter functions for macroblock boundaries
The commit adds a new set of loop filter for macroblock edge filtering.
The new loop filter has a mask to detect so-called "flat" regions. The
detection checks 5 pixels of each side of an edge. If the all pixels
have value with +/-1 from the edge pixel on the same side, the region
is treated as a "flat" region. For such case, a 7 tap filter is used
to change 3 pixel values on each side. The 7 taps are:
[1, 1, 1, 2, 1, 1, 1]/8
The furthest away pixels used as input are +/-5 away from edge. For
non-flat region, we fall back to old filtering. It should be noted
here that the thresholds and filter taps may require more optimization
for best possible results.
Tests on a set of hd clips showed consistent gains:
http://www.corp.google.com/~yaowu/no_crawl/mblpf_hd.html
(avg psnr: .83% glb psnr: .77% ssim: .82%)
Tests on derf set also showed consistent gains:
http://www.corp.google.com/~yaowu/no_crawl/mblpf_derf.html
(avg psnr: .24% glb psnr: .22% ssim: .48%)
Paul Wilkins [Wed, 11 Jan 2012 14:05:57 +0000 (14:05 +0000)]
Rate control on static scenes plus Y2dc delta Q fix.
A problem can arise on static clips with force key frames where
attempts to avoid popping lead to a progressive reduction in key
frame Q that ultimately may lead to unexpected overspend against
the rate target.
The changes in this patch help to insure that in such clips the
quality of the key frames across the clip is more uniform (rather
than starting bad and getting better - especially at low target rates).
This patch also includes a fix that removes a delta on the Y2DC
when the baseline q index < 4 as this is no longer needed.
There is also a fix to try and prevent repeat single step Q adjustment in
the recode loop leading to lots of recodes, especially where the use
of forced skips as part of segmentation has made the impact of Q on
the number of bits generated much smaller.
Patch 2: Amend "last_boosted_qindex" calculation for arf overlay frames.
Yaowu Xu [Thu, 5 Jan 2012 19:22:06 +0000 (11:22 -0800)]
Added an emms to prevent invalid stats output
In certain hardware configuration, where mmx code is enabled and
other simd (sse2/sse3) disabled, lacking of this emms caused invalid
internal stats outputs.
Yaowu Xu [Wed, 21 Dec 2011 20:05:10 +0000 (12:05 -0800)]
changed mode_context update strategy
Previously, the mode context is always udpated based on stats of current
frame, when there is no count, 50% is used for both left and right branch.
However, it is observed that with such strategy, a small count or no count
at all can skew the probability distribution significantly. This commmit
changed the mode_context update strategy to prevent small counts from
skewing the probability distributions.
Tests on derf set showed a small gain: .06% in psnr and .09% in ssim
Paul Wilkins [Fri, 16 Dec 2011 10:23:01 +0000 (10:23 +0000)]
Extend to 256 Q steps.
This commit extends the number of Q steps to 256 from 128.
The q_trans[] array has been altered to distribute available Q index values
(using the current 64 steps available as input parameters) evenly across the
available range. This is coupled with the fact that each Q step where possible
now equates to a fixed % change in the quantizer. This may want refinement
later especially in terms of the granularity at the high quality end but is a
reasonable starting point.
Paul Wilkins [Mon, 12 Dec 2011 18:27:25 +0000 (18:27 +0000)]
Further QIndex realted Fixes:
Added code to support 256 index steps instead of 128 but disabled for now.
Replace hard wired table vp8cx_base_skip_false_prob[128]
Observed Qindex problem with setting minimum loop filter value.
(Experiment code using real Q in place but for now just returning 0. This has a big
beneficial effect on some clips, particularly waterfall which shows 5% ssim gain)
Adrian Grange [Fri, 16 Dec 2011 22:00:36 +0000 (14:00 -0800)]
Reset segment_id to 0 when segmentation is disabled
Whilst the encoder explicitly set the segment_id to 0
when segmentation is diabled, the decoder would allow
the segment_id to persist from the previous frame.
This fix attempts to make the decoder behave the same
as the encoder by explicitly setting the segment_id to
0 in this case.
Adrian Grange [Thu, 15 Dec 2011 18:00:46 +0000 (10:00 -0800)]
Fixed bug to use mode_info_stride rather than mb_cols
Both encoder & decoder were using mb_cols to
offset from one row of MODE_INFO structures to the next
when they should have been using mode_info_stride.
Fixing this in both encoder and decoder gives around
a 3KB size saving and 0.025dB PSNR improvement on the one
720P clip I tried.
(Also removed "index" which was being updated but not used)
Yaowu Xu [Thu, 8 Dec 2011 19:43:09 +0000 (11:43 -0800)]
Enabled adaptive UV intra coding for inter frames
Previously, Y-adaptive UV intra coding only enabled on key frames in
UVINTRA experiment. This commit enabled the same coding for inter
frames, so the encoding of UV intra modes are consistent cross all
frame types. Tests on derf set showed a very small overall gain around
.04%:
Yaowu Xu [Thu, 8 Dec 2011 19:43:09 +0000 (11:43 -0800)]
Revised coding using adaptive mode context to depend on frame type
A previous commit 76feb965 made the vp8_mode_context adaptive on a frame
frame basis, this commit further made the coding context adaptive to two
frame types separately. Tests on derf set showed a further small gain on
all metrics: avg psnr 0.10%, glb psnr: 0.11%, ssim: 0.08%
Yaowu Xu [Thu, 8 Dec 2011 04:08:31 +0000 (20:08 -0800)]
fixed a crash caused invalid Q choice
The commit fixed a problem by capping cpi->active_best_quality to be
smaller than cpi->worst_quality. Also fixed a few line of code that
was misplaced.
Yaowu Xu [Wed, 7 Dec 2011 21:55:58 +0000 (13:55 -0800)]
Removed #if CONFIG_MULCONTEXT
This commit removed the macro CONFIG_MULCONTEXT, which was used to
indicate the experiment code for using separate context for altref
and normal frames. This commit made the change fully merged in.
Yaowu Xu [Tue, 6 Dec 2011 20:03:42 +0000 (12:03 -0800)]
made vp8_mode_context adaptive
vp8_mode_contexts[] is an entropy table used to code inter mode
choices. It was a fixed constant table. This commit made the entropy
context adaptive. Tests on derf set showed very good consistent gains
on all metrics: avg psnr .47%, overall psnr .46% and ssim .40%.
Yaowu Xu [Tue, 6 Dec 2011 15:37:39 +0000 (07:37 -0800)]
fixed a crash when MODE_STATS is enabled
The MODE_STATS macro was used to #ifdef around code for mode entropy
stats collection, this commit fixed a crash when MODE_STATS is on.
The commit also changed a number of array definitions to use defined
macros instead of hard-coded numbers.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Paul Wilkins [Tue, 6 Dec 2011 14:48:52 +0000 (14:48 +0000)]
Some further QIndex issues with extended Q
Resolved or factored out some further issues with Q index.
Put in a 3rd order polynomial instead of less accurate power function
as the best fit on gf and kf boost adjustment.
Added avg_q value to use instead of ni_av_qi.
Compute segment delta Q values based on avg_q.
Fixed bug in adjust_maxq_qrange().
The extended range Q on the derf set, using standard data rates
(which do not extend high enough to get big benefits) still show
a shortfall of between 0.5 and 1% though so there would appear to
be further issues that need to be tracked down.
Yaowu Xu [Fri, 2 Dec 2011 23:32:46 +0000 (15:32 -0800)]
changed configure script to enable new experimental options
Added two experimental options to the configure script:
1. newnear:
new scheme of doing mv encoding that include a motion vector from
last frame in nearest and near mv search
2. mulcontext:
tracks entropy context separately for regular frames and alt ref
frames.
Yaowu Xu [Thu, 1 Dec 2011 00:36:46 +0000 (16:36 -0800)]
added separate entropy context for alt_ref
This commit added code to keep track of separate entropy contexts for
normal frames and alt ref frames. The underly assumption was that the
two type of frames have different entropy characteristics given they
typically have quite different quantization levels. By keeping entropy
contexts separate, it helps the entropy context distribution to be more
closely adapted to each frame type.
Tests on derf set showed a good and very consistent gain on all clips
on all metrics, avg psnr: 0.89%, overall psnr: 0.84% and ssim 0.93%.
Yaowu Xu [Thu, 1 Dec 2011 00:25:00 +0000 (16:25 -0800)]
enabled 8x8 intra prediction modes on inter frames
This commit enabled the usage of 8x8 intra prediction modes on inter
frames. There are a few TODO items related to this: 1)baseline entropy
need be calibrated; 2)cost of UV need to be done more properly rather
than using decision only relying on Y; 3)Threshold for allowing picking
8x8 intra prediction should be lowered to lower than the B_PRED.
Even with all the TODOs, tests showed consistent gain on derf set ~0.1%
(PSNR:0.08% and SSIM:0.14%). It is assumed that 8x8 intra prediction
will help more on large resolution clips, especially with above TODOs
addressed.
Paul Wilkins [Fri, 2 Dec 2011 14:57:21 +0000 (14:57 +0000)]
Further work on extended Q range.
Fixed some further QIndex related issues and replaced some tables
(eg zbin and rounding)
Also Added function (currently disabled by default) to populate the
main AC and DC quantizer tables. Using the original AC range the
resulting computed DC values give behavior broadly comparable
on the DERF set. That is not to say that the equations will hold good
over a more extended range. The purpose of this code is to make it
easier to experiment with further alterations to the Q range and distribution
of Q values plus the relative weights given to AC and DC.
The function find_fp_qindex() ensures that changes to the Q tables
are reflected in the value passed in to the first pass code.
Slight experimental adjustment to static segment Q offset.
Yaowu Xu [Fri, 18 Nov 2011 02:31:00 +0000 (18:31 -0800)]
added transform type to MB_MODE_INFO
this commit is to add an variable in the macroblock level mode
info structure to track the transform size used in each MB, so
the information can be used later in the loop filter to change
how loop filter works on MBs with different transform sizes.
Paul Wilkins [Thu, 24 Nov 2011 18:25:03 +0000 (18:25 +0000)]
Further work on extended Q range.
Fixed bug in firspass.c call to vp8_initialize_rd_consts()
This was passing in vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q)
instead of (cm->base_qindex + cm->y1dc_delta_q).
It just so happens that for the value 26 used for cm->base_qindex in the
unextended Q case, the two give similar results. However, when using
the extended Q range the two are very different.
Also added more stats output and partly disabled another broken feature.
Yaowu Xu [Wed, 16 Nov 2011 00:16:30 +0000 (16:16 -0800)]
changed find_near_mvs search to include a mb from last frame
This is an experiment to include a mv contribution from last frame to
nearest and near mv definition. Initial test showed some small though
consistent gain.
latest patch slightly better result ~.13%-~.18%.
TODO: the entropy used to encode the mode choice, i.e. the mv counts
based conditional distribution of modes should be re-collected to
reflect this change, it is expected that there is some further gain
from that.
Paul Wilkins [Wed, 23 Nov 2011 17:18:31 +0000 (17:18 +0000)]
Two pass rate control code changes.
This comitt brings accross changes from the public branch
commit number Icf74d13af77437c08602571dc7a97e747cce5066.
The main puurpose of this comit relates to CQ mode but it
also includes some refactoring of the two pass code which
I hope will make tuning the experimental branch for the new
quantizer range a little less painfull.
Paul Wilkins [Wed, 23 Nov 2011 11:32:20 +0000 (11:32 +0000)]
Further resolution of QIndex LUTS;
This commit resolves further QIndex look up tables to facilitate
experimentation with the quantizer range.
In some cases rather than remove the look up tables completely
I have created functions that are called once to populate them
using a formulaic approach base on the actual quantizer.
The use of these functions based on best fit of data from the original
tables does affect the results on some clips but across the derf test
set the effect was broadly neutral.
Paul Wilkins [Mon, 21 Nov 2011 15:45:10 +0000 (15:45 +0000)]
Removal of Qindex LUTS.
One of the problems arising when tweaking or adjusting the quantizer
tables is that there are a lot of look up tables that depend on the QINDEX.
Any adjustment to the link between QINDEX and real quantizer therefore tends
to break aspects of for example the rate control.
In this check in I have replaced several of the look up tables with functions that
approximate the same results as the old Q luts but use a formulaic approach
based on real Q values rather than QIndex. This should hopefully make it easier
to experiment with changes to the Q tables without always having to go through
and hand optimize a set of look up tables. Once things stabilize we may choose
to re-instate luts for the sake of performance.
Patch 2:
Addressed Ronald's comments.
vp8_init_me_luts() Added so luts only initialized once.
Yaowu Xu [Fri, 11 Nov 2011 05:14:45 +0000 (21:14 -0800)]
fixed the scaling in 8x8 trellis quant
This commit has a few minor fixes to the 8x8 trellis quant, so to
make it work regardless if extend_qrange is enabled or not. It also
borrowed adaptive RDMULT constants from 4x4 trellis that was missed
in the 8x8 trellis quant.
Paul Wilkins [Tue, 15 Nov 2011 16:15:23 +0000 (16:15 +0000)]
Merge CONFIGURE_SEGMENTATION experiment.
Removal of CONFIGURE_SEGMENTATION ifdefs.
Removal of legacy support code fo the old coding mechanism.
Use local reference "xd" for MACROBLOCKD structure in
encode_frame_to_data_rate()
Moved call to choose_segmap_coding_method() out of encode
loop as the cost of segmentation is not properly accounted
in the loop anyway. If this is desirable in the future it
can be moved back. The use of this function to do all the
analysis and set the probabilities also removes the need
to track segment useage in threading code.
Paul Wilkins [Tue, 15 Nov 2011 15:22:26 +0000 (15:22 +0000)]
Further clean up of Segmentation experiment code
Changed name and sense of segment_flag to "seg_id_predicted"
Added some additional comments and retested.
I also did some experimentation with a spatial prediction option
using a similar strategy to the temporal mode implemented.
This helps in some cases where temporal prediction is bad but
I suspect there is more overlap here with work on a larger scale
block structure and spatial correlation will likely be better
handled through that mechanism.
Next check in will remove #ifdefs and legacy mode code.
Paul Wilkins [Tue, 15 Nov 2011 11:13:33 +0000 (11:13 +0000)]
Further work on Segmentation Experiment:
This check in includes quite a lot of clean up and refactoring.
Most of the analysis and set up for the different coding options for the
segment map (currently simple distribution based coding or temporaly
predicted coding), has been moved to one location (the function
choose_segmap_coding_method() in segmenation.c). This code was previously
scattered around in various locations making integration with other
experiments and modification / debug more difficult.
Currently the functionality is as it was with the exception that the
prediction probabilities are now only transmitted when the temporal
prediction mode is selected.
There is still quite a bit more clean up work that will be possible
when the #ifdef is removed. Also at that time I may rename and alter
the sense of macroblock based variable "segment_flag" which indicates
(1 that the segmnet id is not predicted vs 0 that it is predicted).
I also intend to experiment with a spatial prediction mode that can be
used when coding a key frame segment map or in cases where temporal
prediction does not work well but there is spatial correlation.
In a later check in when the ifdefs have gone I may also move the call
to choose_segmap_coding_method() to just before where the bitsream is
packed (currently it is in vp8_encode_frame()) to further reduce the
possibility of clashes with other experiments and prevent it being called
on each itteration of the recode loop.
Paul Wilkins [Fri, 11 Nov 2011 18:08:06 +0000 (18:08 +0000)]
Segmentation experiment:
Added last_segmentation_map[] structure
to keep track of what we had before when
doing temporal prediction. With this change
the existing code does once again appear to
be giving a decodable bitstream for both
temporal and standard prediction modes.
However, it is still somewhat messy and
confused and there is no option to take
advantage of spatial prediction so it could
do with further work.
Paul Wilkins [Fri, 11 Nov 2011 10:10:06 +0000 (10:10 +0000)]
SEGMENTATION experiment:
Some initial cleanup to aid testing and debug.
Pull code to choose temporal or spatial encoding
out of encodeframe.c into a dedicated function
in segmentation.c.
For now disable broken temporal mode.
Move the coding of "temporal_update" flag and
only transmit if segment map update is indicated.
Rename the functions read_mb_features() and
write_mb_features() to read_mb_segid() and
read_mb_segid() as they only read and write
the macroblock segment id not any of the
features.
Yaowu Xu [Thu, 10 Nov 2011 20:54:22 +0000 (12:54 -0800)]
Make 8x8 and extend_qrange to work together
This commit added scaling factors to 8x8 transform, quant, dequant and
inverse transform pipeline to make 8x8 transform to work when configed
with enable-extend_qrange. This commit also disabled the trellis-quant
when extend_qrange is configured.
Yaowu Xu [Fri, 11 Nov 2011 01:15:06 +0000 (17:15 -0800)]
fixed the decoder when using 8x8 transform
updated the decode_macroblock logic to reflect that 8x8 transform is
not used for "SPLITMV". Also fixed an issue where 2nd order haar block
has wrong dequant/idct process.
Paul Wilkins [Wed, 9 Nov 2011 14:05:28 +0000 (14:05 +0000)]
T8x8 experiment merge.
For ease of testing and merging experiments I have
removed in line code in encode_frame() that assigns
MBs to be t8x8 or t4x4 coded segments and have
moved the decision point and segment setup to
the init_seg_features0 test function.
Keeping everything in one place helps make sure
for now that experiments using segmentation are
not fighting each other.
Also made sure mode selection code can't choose 4x4
modes if t8x8 is selected.
Patch2: In init_seg_features() add checks
for SEG_LVL_TRANSFORM active.
Paul Wilkins [Tue, 8 Nov 2011 15:40:32 +0000 (15:40 +0000)]
Merging and testing of SEGMENTATION experiment.
Removed code in #if CONFIG_SEGMENTATION that
enables segmentation and creates a test segmentation
map, to avoid conflicts with the other segmentation test
code,
Yaowu Xu [Wed, 9 Nov 2011 04:05:17 +0000 (20:05 -0800)]
make debug match release build on win32 with 8x8 transform enabled
The 8x8 forward transform makes use of floating operations, therefore
requires emms call to reset mmx registers to correct state. Without
the resets, the 8x8 forward transform results are indefinite on win32
platform.
Paul Wilkins [Fri, 4 Nov 2011 10:59:54 +0000 (10:59 +0000)]
Segment Features with 8x8DCT.
Temporary check in to turn off other segment features
tests when #if CONFIG_T8X8 is set as the assignment of
MBs to differnt segments in each case will conflict.
The 8x8 code will be modified to use the new segment
feature method properly in a later check in.
Increase bits allowed for EOB end stop marker to 6 ready
for 8x8.
Paul Wilkins [Thu, 3 Nov 2011 16:58:26 +0000 (16:58 +0000)]
Segment Feature Data Access
No change to functionality or output.
Updates to the segment feature data structure now all done
through functions such as set_segdata() and get_segdata()
in seg_common.c.
The reason for this is to make changing the structures (if needed)
and debug easier.
In addition it provides a single location for subsequent addition
of range and validity checks. For example valid combination of
mode and reference frame.
Yaowu Xu [Thu, 4 Aug 2011 23:30:27 +0000 (16:30 -0700)]
make uv intra mode coding adaptive to Y mode
This commit tries to do UV intra mode coding adaptive to Y intra mode.
Entropy context is defined as conditional PDF of uv intra mode given
the Y mode. All constants are normalized with 256 to be fit in 8 bits.
This provides further coding efficiency beyond the quantizer adaptive
y intra mode coding. Consistent gains were observed on all clips and
all bit rates for HD all key encoding tests.
To test, configure with
--enable-experimental --enable-uvintra
Yaowu Xu [Thu, 3 Nov 2011 23:05:29 +0000 (16:05 -0700)]
Added context reset when 2nd order coefficients are cleared
As discovered in path 10 of Change Ia12acd2f, reset 2nd order coeffs
without reset of above and left coding context may have introduced
problem that causes encoder/decoder mismatching. This commit added
update to coding context when the 2nd coefficients are cleared.
In addition, this commit also introduced early breakout in the checks
to speed up when coefficients are too significant to be cleared.
Paul Wilkins [Wed, 2 Nov 2011 13:30:10 +0000 (13:30 +0000)]
Segmentation: Reference frames
Modify reference frame segmentation so that ONE or MORE
reference frames may be marked as a available for a given
segment.
Fixed bugs relating to segment coding of INTRA and some
INTER modes at the segment level.
Modified Q boost for static areas based on ambient average Q.
Strong results now on clips with significant static areas.
(some data points in derf set as high as 9% and some static &
slide show type content in YT set > 20%)
Adrian Grange [Mon, 31 Oct 2011 19:42:00 +0000 (12:42 -0700)]
Fixed this_mode used before set in vp8_pick_inter_mode
The variable this_mode was being used before it had been
initialized.
Moved the line that sets-up this_mode toward the top of the
enclosing loop, prior to its first use. The bug would result in
tests in the loop lagging the mode that was expected to be
tested.
Paul Wilkins [Fri, 28 Oct 2011 14:27:23 +0000 (15:27 +0100)]
Segmentation Entropy and tweaks.
Some correction for entropy impact of segment signaled (EOB and ref frame)
Other slight tweaks.
Derf VBR average gain now over 1% (best over 7%)
One YT test clip has gains of circa 30% (VBR)
There is still an issue with noisy clips where making the background static
and coded with 0,0 can have a negative effect, especially at low Q.
This is probably because of the loss of smoothing by fractional pixel filters.
Yaowu Xu [Fri, 14 Oct 2011 16:58:35 +0000 (09:58 -0700)]
added a last stage rounding for 8x8 inverse dct
Prior to the added rounding, tests on randomly generated data showed
that forward-inverse transform round trip errors are about 3.02/block
for input range [-10,10] and 2.68/block for input range [-256, 255].
The added rounding reduced the errors to 0.031/block for input range
[-10,10] and 0.037/block for input range [-256, 255].
Maximum round trip error on for any pixel position is 1.
The average errors are calculated based on 100,000 blocks of randomly
with the specified ranges.
Paul mentioned in discussion that the change was not clear on why we
need change the rounding, so Patch 2 intends to make the rationale
obvious in code, it merged the two separate shifts into one, and the
two separate rounding factors into one. Patch 1 and 2 have same
numerical test results.