summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_ratectrl.c
AgeCommit message (Collapse)Author
2019-01-15vp9-svc: Fix to buffer update under frame_dropsMarco Paniconi
For svc with frame dropping in full_superframe_drop or constrained dropped mode: the buffer level for a given layer may be capped from increasing too much. This is because that layer may be dropped even though its buffer is stable (the dropped is forced due to underflow in other layers in full/constrained svc-drop mode). This capping is needed to prevent decrease in qp over consecutive frame drops. The capping already exists and has been used, but this change introduce an error that prevented its usage: https://chromium-review.googlesource.com/c/webm/libvpx/+/1330875 The fix here is to also cap the bits_off_target as well, since after the change mentioned above, its the bits_off_target that is used to update buffer on next frame (which in turn affects qp for next frame/layer). Change-Id: Ifdab5d478e91cce20ecec51faa574eed375ee36b
2019-01-14vp9-svc: Rate control fix for key base layerMarco Paniconi
After encoding key frame on base spatial layer, if the overshoot is significant, reset the avg_frame_qindex[INTER] on base spatial layer for all temporal layers. This forces the active_worst_quality to increase on subsequent frames/layers and reduces frame dropping. Change-Id: I53a3cd14131d69120e59a649b7ed1bfde3e940ee
2018-12-12Merge "Use undamped adjustment for rate correction factors"Deepa K G
2018-12-11Use undamped adjustment for rate correction factorsDeepa K G
Undamped adjustment is used for the first frame of each frame type while updating the rate correction factors. Change-Id: I42f80daa123c4cd4e45c18c6960cc7a67e7df7e6
2018-12-10Clean up condition logics in rc_pick_q_and_bounds_two_pass()Jingning Han
Factor out common conditions for better readability. Change-Id: I2a2b576e7d3e5cf036e9e355fc7ce0509ecb3d7e
2018-12-04Merge "Clean up rc_pick_q_and_bounds_two_pass()"Jingning Han
2018-12-03vp9-svc: Fix to postencode drop for layers.Marco Paniconi
Postencode drop is only checked on base spatial layers, and if set, whole superframe is dropped and and next superframe is encoded at max-q. Fix here is to make sure all layers are encoded at max-q on a postencode dropped frame. Change-Id: I2313d83ee29a382465bcec1085d8c73c37ce26d6
2018-12-03Merge "vp9: Rename post_encode drop function."Marco Paniconi
2018-12-03vp9: Overshoot detection for skipped base layer.Marco Paniconi
If scene/slide change is detected on current superframe and max-q set because of high overshoot: then if the lower/base spatial layer are skipped on the current superframe, max-q is forced on the next encoded base/lower spatial layers. Change-Id: Id61efda86ee545395012e19476d19845e3932678
2018-12-03vp9: Rename post_encode drop function.Marco Paniconi
Feature works also for non-screen content mode, so rename it. Change-Id: I665362d50cf9a4017f114973586ad0eead066ddd
2018-11-30Clean up rc_pick_q_and_bounds_two_pass()Jingning Han
Remove unneeded VPX_Q condition check. Change-Id: I46b09ae522caa47fa7ea4441b6a6ac2840315d1c
2018-11-30Simplify constant q mode qp selectionJingning Han
Decouple the constant q mode qp selection from vbr/cbr/cq modes. Skip vp9_frame_type_qdelta() adjustment for non-ARF inter frames, instead keep using the cq-level. It improves the compresson performance: avg PSNR overall PSNR SSIM lowres -0.17% -0.20% -0.1% midres -0.21% -0.24% -0.08% hdres -0.15% -0.19% -0.04% Change-Id: I52fd5f8edbd3fdcbeda31ee3a6d6eb016091a7e3
2018-11-29Factor key frame qp selection from two-pass qp and bound decisionJingning Han
Factor out this common code needed all rate control modes. Change-Id: If17850fbebcdce7ff24afb211aa2e6054486b814
2018-11-27Remove ineffective condition from rc_pick_q_and_boundsJingning Han
Change-Id: I67b92182ee80ec5548c5a97345b6252e49033c4a
2018-11-26Fix ARF rate allocation for cq modeJingning Han
In the limited test set, it improves the cq mode compression performance by 1.9% in PSNR and 6% in SSIM as compared to use same quantization parameter for all ARFs. Change-Id: I35c4d7097b5838ab0b92d7f9937520721e3bb84b
2018-11-20vp9-svc: Reset temporal layers on scene changeMarco Paniconi
Reuse existing function for resetting temporal layer pattern. And fix to use first spatial layer to encode, and some refactoring in encode_without_recode_loop(). Change-Id: Ifb22bb9de793ecb8e73f410e125c7c12383da1d2
2018-11-19vp9: Fix to the svc buffer updateMarco Paniconi
Condition the pre-encode buffer update based on TS diff on temporal layers = 1 for now, as some fix is needed for the case where #temporal_layers > 1. Change-Id: I58163b956db415217e4687a31f8ba110545b09f5
2018-11-16vp9: Reorganize the buffer level for cbr modeMarco Paniconi
Refactor the code with some changes. Split update into two parts: move the fillup (with per-frame-bandwidth) before the encoding, and keep the leaking part (with encoded_frame_size) after the encoding (postencode). For SVC with ref_frame_config usage: allow usage of timestamp delta for the fillup part of buffer, instead of the (average) framerate passed in via the duration. Moving the buffer fillup (+per-frame-bandwidth) part to the pre-encode causes some difference in performance (since buffer level affects active_worst/QPand frame-dropping), but the change is observed to be small. Made small adjustment to active_worst_quality to compensate. Adjust some thresholds in datarate tests. Change-Id: I81a5562367034f318cffd451304bc4a34bf02a1d
2018-11-07Merge "vp9: postencode drop frame for screen content in CBR."Jerome Jiang
2018-11-06vp9: postencode drop frame for screen content in CBR.Jerome Jiang
Encode the next frame at max q. For layers: post_encode_drop is only check on base spatial layer, and if base is post-encoded-dropped, then whole superframe is dropped. Added API to guard postencode dropping. Turned off by default. Added unittest. BUG=b/112990050 Change-Id: I42fee279014aca616f7a4d9b582cb2bf5da2f2e7
2018-11-06vp9 screen-content: Adjustments for screen content.Marco Paniconi
Increase search area, use NSTEP, and in some cases avoid bsize below 16x16. This for base spatial layer when many blocks in the frame have motion (from scene detection analysis). Improves quality for scrolling motion. Change-Id: If77b43e738a6c43610d4727a95712667088db564
2018-10-29Properly space qp in q mode for multi-layer ARFJingning Han
Space the quantization parameter distribution according to the layer depth for multi-layer ARF coding structure. This allows lower layers to have relatively smaller quantization parameters than higher layers. It improves the compression performance in constant q mode for multi-layer ARF system: avg PSNR overall PSNR SSIM lowres -0.33% -0.31% -1.44% midres -0.29% -0.38% -1.14% hdres -0.27% -0.49% -1.02% Change-Id: I9cfe2f27e6c0029c30614970a46de3045840264e
2018-10-23Reset frame udpate flags after qp estimate in tplJingning Han
After the frame quantizer estimate run in tpl model, reset the actual value assigned to the current coding frame. This would avoid certain frame update flags being overwritten by different frame types' update. Change-Id: Idde2ba1108f1f68747b14149b211f882965c99f0
2018-10-23Fix frame offset computation for GOP extensionJingning Han
Properly compute the extended GOP frames' buffer offsets. Change-Id: I9aed14f4b8d623f1832e782828dce07aa546507d
2018-10-23Refactor gop_length use case in tpl modelJingning Han
Make it support both single- and multi-layer ARF GOP structure. Change-Id: I760a95804d1b583b057120f6d6be65195a0e6c19
2018-10-17For keyframe-only coding do not boost in q modeUrvang Joshi
If we are using keyframe only coding - either coding a single frame, or a sequence of keyframes - in the end-usage=q mode, use the cq_level directly as the quality of each coded frame, rather than boost them. Ported from AV1: 563a0d1eb92bdc1e987df071a568d8406c4ffa92 Change-Id: I6dc929b8b4f0aa18e279139077f3a87958c92245
2018-09-28Merge "Add MID_OVERLAY_UPDATE frame type"Jingning Han
2018-09-27Add MID_OVERLAY_UPDATE frame typeJingning Han
Add a MID_OVERLAY_UPDATE abstract to support multi-layer ARF-Overlay frame based approach. When setting the frame update type to be USE_BUF_FRAME, the encoder will use show_existing_frame to process the intermediate ARF frames. When setting the frame update type to be MID_OVERLAY_UPDATE, the intermediate ARF frames will go through an overlay frame for display. Change-Id: Ia0c91452c09d39312ac22d855cdf681b7da851c5
2018-09-25Use layer dependent gfu_boost factorJingning Han
When multi-layer ARF is enabled, use the corresponding gfu_boost factor assigned to each ARF to compute the best_quality_index adjustment. This on average improves the coding performance by 0.2% for lowres and hdres, 0.4% for ntflx2k. It seems this change will only affect a small group of clips, e.g., pamphlet, bowing, mobcal_720p, etc., which tend to gain 4-5%, whereas the rest clips remain largely identical coding statistics. Change-Id: Ie19636a6cf32214aefd73e21ead2aea647ddbca8
2018-09-11Simplify vp9_frame_type_qdelta()Jingning Han
Make direct use of frame type in the available VP9_COMMON structure. Eliminate the need to map through rf_level to fetch the frame type. This change doesn't alter the coding stats. It simplifies the vp9_frame_type_qdelta() function logic and removes unnecessary reference to rf_level. Change-Id: I1a7b2f5abcae39aa4a60d08a6011dde38ecf3b58
2018-09-03Revert "Revert "Prevent double application of min rate in two pass.""Paul Wilkins
This rate control bug in the original patch is not the underlying cause of the quality regression but simply unmasked a problem which stems from applying 0 bits to the last frame in a short KF group at the start of a chunk. This reverts commit d10b1f233657054b1465d40f0b409c20029a540b. Change-Id: I32c91a24a14d013853bb8e5587aa69600e6a0063
2018-08-31vp9-svc: Add first_spatial_layer_to_encode per superframeMarco Paniconi
VP9E_SET_SVC_LAYER_ID sets the first spatial layer to encoder per superframe, so add this parameter to svc encoder. This is needed, for example, to properly set is_key_frame for spatial layers when base spatial layer is skipped encoded. Change-Id: Ifd4ac77f539197ec021e62f4c624a6cc79d64f43
2018-08-23Revert "Prevent double application of min rate in two pass."Hui Su
This reverts commit 416b7051d7f610ed6d62dff18af7776ec520fd9c. Reason for revert: it causes visual quality drop as described in b/112953058. Original change's description: > Prevent double application of min rate in two pass. > > The initial allocation of bits in the two pass code to each frame > should be within the min max limits on the command line. However, > when forming an ARF group the cost of the ARF is shared by frames > in that group such that the residual bits for a frame could drop below > the min value. This change prevents the minimum being re-applied > after the cost of the ARF has been deducted as this may otherwise > cause low rate sections to overshoot their target. > > Test runs comparing to a baseline run with min and max section pct > 0-2000% vs one closer to the YT use case (50-150%) suggest that > this fix not only results in better rate control but also gives a better > rd outcome. > > For example the HD set vs 0-2000% baseline (opsnr, ssim). > Old code (50-150): +0.751, +1.099 > New code(50-150): +0.241, -0.009 > > Change-Id: I715da7b130bf53ba8aa609532aa9e18b84f5e2ef TBR=yaowu@google.com,paulwilkins@google.com,debargha@google.com,builds@webmproject.org # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Ic9849e4e0db64e9d92bbb9df9cc923230a15c4df
2018-08-22Set refresh_frame_context flag off in show_existing_frame modeJingning Han
Match the decoder expectation, set off refresh_fame_context flag in show_existing_frame mode. Change-Id: I5258635b715ea04f41a4a087178709f707449b71
2018-08-21Control reference frame refresh flags for USE_BUF_FRAMEJingning Han
The enum USE_BUF_FRAME makes the use of show_existing_frame. In this setting, all the reference frame buffer condition will stay unchanged. Change-Id: I5b7b28488dbd94982f721667128f004e4e6a00d8
2018-08-13vp9: Small refactor on overshoot detection, for cbr real-time.Marco Paniconi
Change-Id: I70997d35a2371bb4614d716ef0c587fa12ea0f4a
2018-08-09vp9: Allow for overshoot detection for non-screen CBR mode.Marco Paniconi
For CBR real-time mode: refactor usage of speed feature to handle overshoot on slide/scene change. Add 2 modes to indicate how slide/scene change is processed for re-setting Q/rate control. Keep the speed setting to 1 for speed >= 5, otherwise set to 0. Video content and screen content are now handled in similar way, though with different thresholds. Some fixes to thresholds and reset: correct the reset of the buffer level to optimal level for each temporal layer, if scene change frame will be encoded at max_q. Also increase the min_thresh for video mode (non-screen content): this is to avoid scene change detection on cases like large lighting changes, cameras focus. And increase in min_thresh makes it more robust to sudden increase in noise level. Change-Id: I256d350da6e92d2ddc09f100fc06ac147cbc1e49
2018-08-09vp9-svc: Fix for scene detection for SVCMarco Paniconi
For spatial layers: use the correct mi_cols/rows in the scene detection. The scene detection for spatial layers is only called once per superframe, but we were using wrong mi_cols/rows (those for base spatial were being used). Also increase frame_since_key threshold to account for spatial layers. Change-Id: I2731da49684a798c4718693a0468eda7db82d2bd
2018-08-03vp9: Adjust qp_thresh on slide change overshoot detectionMarco Paniconi
For real-time screen-content mode: increase the qp_thresh for max_Q setting on slide changes. This will make bitrate spikes less likely on slide changes. Change-Id: Ie13524a06490214456b1c9c042a864ea0d0750c5
2018-08-02vp9: Add zero_temp_sad count to scene detection.Marco Paniconi
For real-time screen-content mode: makes the scene/slide change detection more robust. Change-Id: I28d8d28b42bb92d527811f814bf14bbbbb53ab25
2018-08-03Merge "vp9: Disable re_encode_overshoot feature for speed >= 6."Marco Paniconi
2018-08-02vp9: Increase min_thresh for slide change detectionMarco Paniconi
For real-time screen-content mode: increase min_thresh to avoid some false detection. Change-Id: I3e93dea63cbd65e3ad5d0af7eabf0d3686fe9943
2018-08-02vp9: Disable re_encode_overshoot feature for speed >= 6.Marco Paniconi
For real-time screen content mode: for speed >= 6 disable the re_encode_overshoot feature. This means for speed >= 6 the Q and rate control is reset on slide changes based on the scene/slide detection and the current Q (and not on a first pass encoded frame at current Q). This reduces encode time on slide changes, but may be less accurate in deciding when to reset/max-out the Q. Change-Id: Id0fdcafd55bc43bd8b3afee211e524f37c8ddce6
2018-07-25Merge "Limit min Q for normal frames."Paul Wilkins
2018-07-24vp9: Modify logic for flat blocks in nonrd-pickmode.Marco Paniconi
For real-time screen content mode: when slide change is detected, for spatially flat blocks (source_variance = 0) on the re-encoded frame, skip inter modes (so force intra) if non-zero temporal variance is detected for the coding block. Add flag to keep track of re-encoded frame at max Q. Reduces artifacts on slide change. Change-Id: I28151f412aba6ab8cb03f30087c7ce16d443654b
2018-07-24Limit min Q for normal frames.Paul Wilkins
This patch limits the active min Q for normal frames based on the previous KF/GF/ARF. In a few cases, especially at the end of a clip where there has been systemic underspend, (as is often the case with slide shows), this prevents the encoder rapidly dropping Q on normal frames (just to try and use up bits), such that they end up with a lower Q than the key frame / GF / ARF off which they key. Change-Id: Ic8def5c0d1e37ca2202e007ec1d13e501c0a91dd
2018-07-20Improved coding on slide show content.Paul Wilkins
This patch adds in detection of slide show content and allows for coding of long GF only groups up to a length of 240 frames rather than coding a large number of shorter ARF groups that gradually lower the Q. In test samples this patch gave rise to a substantial improvement in overall psnr and a drop in data rate. In some cases the average psnr fell, however, with the boost and minQ values set as they are. This is to be expected because average psnr is dominated by the best frames in the sequence and previously a relatively poor key frame could be followed by progressively better alt refs. For example a key frame at q7.5 but subsequent alt refs improving it to lossless. For slides displayed for several seconds, savings of >= 20% (or commensurate quality gains) are likely. This patch allows for long GF groups in static sections before and after complex transitions (e.g. fades) with one or more normal ARF groups during the transition. However, it enforces a single "normal" length GF group after the transition before any extended group is allowed. The reason for this is that the ARF that spans the transition my not have a very high quality and hence may not be a good GF for the long static section that follows. Change-Id: I66cc404c3b85e87dae9829b49d9d631cbf04e037
2018-07-18vp9: Screen-content after slide-change: increase refresh rateMarco Paniconi
For screen-content real-time CBR mode: on a detected slide change that is encoded at max Q (to prevent excessive overshoot), increase the perc_refresh in the cyclic refresh following the slide change. Use counter to increase refresh up to some #frames from slide change. This is attempt to increase quality ramp-up after slide change without causing too much excess overshoot. Change-Id: Ie4ec4361082803a522f4a8794b3bb0178c9cf307
2018-07-17Merge "vp9: Force hybrid_intra on scene change"Marco Paniconi
2018-07-16vp9: Force hybrid_intra on scene changeMarco Paniconi
For real-time screen content mode: when scene/slide change is detected and re-encode is decided, force hybrid_intra mode search if slide change is big and alot of Intra modes were used. hybrid_intra mode will use rd-based intra mode search for small blocks. Overall better PSNR on clip with slide changes, with similar encoded frame size. Encode time lightly higher on average with this change. Change-Id: I503835253b777b9f98d74e75a52a8000b76c310c