summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_ratectrl.c
AgeCommit message (Collapse)Author
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
2018-07-16Assign estimate qp for overlay frameJingning Han
Assign the estimated qp for the overlay frame too. Cap the minimum quantization parameter to be 1 to avoid lossless coding in the temporal dependency model setup. Change-Id: I8acbc7182045dbf3017b6712a119b18407b76ab0
2018-07-13Set the estimate frame qp in tpl_frameJingning Han
Assign the estimate frame quantization parameter in the tpl_frame data structure. Change-Id: I6149bdb1e15dbdae348f06ff61bf814004462232
2018-07-13Estimate the frame qp in a gopJingning Han
Gather the availabel statistics to estimate the frame level quantization parameter set in a group of pictures. This will be called in the tpl model construction. No visible coding stats change would occur. Change-Id: Ic412e4afd9a60f1317a5f8eab6a4f6d5e48c4c07
2018-07-12Refactor rc_pick_q_and_bounds_two_pass parametersJingning Han
Send the gf_group index as argument into the function. This prepares later re-use of this function in the tpl model. Change-Id: Id6203105629e687172c651a013d38c207b60ace7
2018-07-09vp9-svc: Intra-only frame for spatial layers.Marco Paniconi
Use case is for layered (SVC) coding to allow higher resolution layers to continue decoding with temporal references, while base spatial layer is intra-only frame. Made encoder changes to real-time path for encoding intra-only frame. The intra-only frame will be followed by the overlay/copy frame (with both packed in the same superframe). Use existing control to enable intra_only frame. Intra only is only applied to base spatial layer, and only allowed under fixed/non-flexible SVC mode, and only for 1 < number_spatial_layers < 4. Added svc datarate unittest for inserting intra_only frame as sync frame. Added svc end to end tests to check mismatch. Change-Id: I2f4f0106b2c4f51ce77aa2c1c6823ba83ff2f7a0 Signed-off-by: Marco Paniconi <marpan@google.com>
2018-06-27vp9-svc: Set avg_frame_low_motion for lower layers.Marco Paniconi
The avg_frame_low_motion metric is only computed on the top spatial layer, and since its part of the layer context struct, it needs to written to all lower spatial layers for consistency. Small/minor change in metrics. Change-Id: I92a001c37aeb332e613212288b13a2ed9745af88
2018-06-25vp9-svc: Fix to frame dropping when layer is skipped.Marco Paniconi
Fix condition in frame dropper for SVC to handle case where spatial layer is skipped encoded (due to 0 bitrate). Change-Id: I24185178774d73e8bb1c406acc0292422dfbe174
2018-06-20vp9-svc: Add support for spatial layer sync frames.Marco Paniconi
Add encoder control to allow application to insert spatial layer sync frame. The sync frame disables temporal prediction for that spatial layer. This is useful for RTC application to have receiver start decoding a higher spatial layer, without inserting a key frame on base spatial layer. If the layer sync is requested on the base spatial layer this then force a key frame, otherwise it only disables the temporal reference for that spatial layer, allowing temporal prediction to continue for the other layers. Although the temporal prediction is disabled and reset on a layer sync frame, the inter-layer prediction for the sync frame is enabled on INTER frames. So the meaning of INTER_LAYER_PRED_OFF_NONKEY is modified to mean disable inter-layer prediction on non-key and non-sync frames. Added unittest for inserting layer sync frames. Bump up ABI version. Change-Id: Id458acc400a77c853551f125c4e7b6d001991f03
2018-06-11Merge "vp9-svc: Fix to frames_since_golden update for SVC."Marco Paniconi
2018-06-11vp9-svc: Fix to frames_since_golden update for SVC.Marco Paniconi
When the second (gf) temporal reference is used in SVC: the reference is refreshed on base TL superframes, and so the rc->frames_since_golden counter was also only updated on base TL frames. But this was disabling the golden reference from being used as a temporal reference for TL > 0 frames (since frames_since_golden was 0/not updated on TL > 0 frames). Fix is to copy the update of rc->frames_since_golden to all upper temporal layers. This allows TL > 0 frames to test the golden inter mode. Gain on RTC set: ~2%, ~8% on desktop_vga clip. Encode time increase ~5-8% on linux, 3SL-3TL run with 1 thread. For now keep this off for TL > 0 frames in speed features, so this change does not change current behavior for speed >= 7. Change-Id: I405708f3f80039ae47bd64ec53e66f92160acd9e
2018-06-08vp9 svc: clean up first_spatial_layer_to_encode.Jerome Jiang
Change-Id: I3c9aefd3ea5028797b9105d7e49b1cb2f762a9fc
2018-06-07vp9-svc: Adjust some logic on gf temporal reference.Marco Paniconi
For the feature of using second temporal reference (when inter-layer is off): move the buffer_idx assignement and refresh flag settings further down to vp9_rc_get_svc_params(), since is_key_frame is set there for every frame/layer. Otherwise it was using the setting from the previous frame/layer. This makes the refresh more consistent for both layers for 2 spatial layers case. Small/negligible change in metrics. Change-Id: I88279243bc27898448e8891dba38143d936cf6d5
2018-06-07vp9 svc: add control to set using second temporal ref.Jerome Jiang
Bump up ABI version. Change-Id: I4498d7ea4ed72994c5f847aa98e75b0150dd7f82
2018-06-07vp9-svc: Allow second temporal reference for next highest layer.Marco Paniconi
When inter-layer prediction is disabled on INTER frames, allow for next highest resolution to have second temporal reference. Current code allowed for only top/highest spatial layer. Change-Id: I102137273e3e4d57512a13d95e8ccb9c5b0a7b4b
2018-06-06vp9-svc: Add a buffer_idx is_used parameter for SVC.Marco Paniconi
For the case where a second (long term) temoral reference is used in the SVC: this additional parameter is to make sure the buffer slot selected for this reference is available for usage, i.e., it is never used for any of the 3 references set for the fixed SVC patterns. And some code cleanup (replace cpi->svc). No change in behavior. Change-Id: Icba46edfbbefb94d5ea8e2d5c24cccd85a406ee6
2018-06-04vp9-svc: Allow usage of second (long term) temporal reference.Jerome Jiang
Allow for second temporal reference for top spatial layer in SVC, when inter-layer prediction is disabled on INTER frames. The second temporal reference is labelled as the golden reference and the update/refresh of this reference buffer is only on base temporal layer superframes. For now the period of refresh is fixed at every 20 TL0 superframes. Average gain is ~4% on RTC set, several clips up by ~8-12%. Speed loss is about ~2% on mac. Feature is disabled as default for now. Change-Id: I2e5db5052c62dbe958a3b14be97d043823b7a529
2018-05-31vp9-svc: Fix to some frame metrics for real-time mode.Marco Paniconi
Add condition of LAST frame to the consec_zeromv and avg_frame_low_motion metrics. This is needed for SVC as the golden reference is a spatial reference and should not be included in the metric computation. Small/negligible change in metrics on RTC set. Change-Id: I6ea16298fae566bb288c34cf50d120b509146eee
2018-05-30vp9-svc: Fix to compute some metrics on top spatiail layer.Marco Paniconi
The avg_frame_low_motion and consec_zeromv are frame-level metrics that are updated on every frame. For SVC these should be updated on top spatial layer (full resolution). Small/negligible change in metrics. Change-Id: Ibe14f05be3b82daa9dd60378097ff11a27f1b95e
2018-05-30vp9: Refactor code for q adjustment in CBR mode.Marco Paniconi
Move the adjustment code to separate function. Change-Id: I876b246a5c26095f262bb9a19f03d1f17077225d
2018-05-30Merge "Revert 3 slide show coding changes"James Zern
2018-05-30Revert 3 slide show coding changesJames Zern
This is a combination of the following 3 reverts. The changes cause issues on certain hardware devices. We'll pull them for now to allow for further investigation. Revert "Experiment regarding playback problems on Bravia TVs." This reverts commit 624f8105f5ae7e0bc82bdc7e10a4253295134a8b. Revert "Improved slide show coding" This reverts commit f4091bc30eef0fcacb5d5bd74ab7cfbc3c8aab5f. Revert "Improved coding on slide show content." This reverts commit 2fa333c2ae1b6fcc1864de12a7ad344a16e2ac0a. BUG=b/77492144 Change-Id: Ifba937792d644a9286307262f050216408e8ecf4
2018-05-29vp9: Adjust cyclic refresh and limit frame-level q.Marco Paniconi
For CBR mode with aq-mode=3: reduce delta-q for second segment and limit how much the frame-level q can decreae from one frame to the next. Reduces bitrate spikes in slide/sreen content. Change-Id: Id9ac4b7270f07e09690380755cfbef4aec5c26dc
2018-05-28vp9-realtime: Move frame dropper to after scene detection.Marco Paniconi
Move frame dropper to after scene detection and noise estimation. Scene detection and noise estimation operate on source data and update metrics along sequence, so they should be moved before the frame dropper. Also we don't want to drop on scene change, as the scene detection and (possible) re-encode step will be missed. Change-Id: I3d9e16d785bd5ace6707db2abce77ddc110bfef4
2018-05-24vp9-svc: Add max_consec_drop to SVC frame drop.Marco Paniconi
For any spatial, limits the amount of consecutive frame drop. Change-Id: I692d90363f329f571f2b59e12cc680ad2e76065d
2018-05-23vp9: Rate control adjustments for screen content.Marco Paniconi
For screen content mode: changes to reduce occurence of significant QP decrease (from one frame to next), which can cause large frames (overshoot/delay). -cap the buffer increase to optimal level for frame drop mode where full superframe can drop -reduce the max_adjustment_down due to buffer overflow -reduce qp threshold to trigger re-encode on large frame Change-Id: I3e30e4814192b5f728abff3f7359eb64f561b8f0
2018-05-22vp9-svc: Add full superframe drop mode.Marco Paniconi
This will check for dropping full superframe if any spatial layer is overshooting. Change-Id: Ic656807028ebef5552301b6d10399fbe3a6c890c
2018-05-16vp9-svc: Enable scene detection and re-encode for SVC.Marco Paniconi
Keep a lower rate threshold for video case. Also lower the exiting threshold somewhat for screen-content mode. Change-Id: I79649a36678d802fd4d4080754fd366e78904214
2018-05-01Clean switch cases in vp9 encoderLinfeng Zhang
To save a branch. Change-Id: Ifa2be7583e95c6991784731c654bbd4cce31e993
2018-04-19Merge "vp9: Rate control fix for CBR mode."Marco Paniconi
2018-04-18vp9: Rate control fix for CBR mode.Marco Paniconi
For CBR mode: modify the qp clamping to allow q to respond faster to overshoot. Can reduce some suprious overshoot events observed in screen content coding. Change-Id: I0b3f54b0d1b4086182f834e557a4121950b176d4
2018-04-18vp9: Remove limit on QP on key frame for CBR.Marco Paniconi
This piece was carried over the VBR routine, for CBR mode we don't want to apply this limit. Change-Id: Ib9e9937eabeff8cfd30e11c9bd17444cc2b591aa