summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_firstpass.c
AgeCommit message (Collapse)Author
2018-08-20Remove unneeded frame_till_gf_update_due assignmentJingning Han
This will get update after define_gf_group() is called and returned. No need to update it inside. Change-Id: Ia42c6f7ef16bca3f1ee88392f3b90b9ebe409da8
2018-07-20Fixed "MAX" boost for static kf sections.Paul Wilkins
Apply a fixed maximum boost for static key frame groups / slide show content (if > 8 frames long). This insures sufficient boost on shorter sections whilst preventing excessive boost on longer sections. Change-Id: I5b857dab023d674cfd55bced3437f3bce3b4f1cb
2018-07-20Fix issue with short static KF groups.Paul Wilkins
Where a KF group is very short but static make sure it is coded as a single GF group. Previously there was a bug where such groups could be coded as an arf group with the arf in the next scene. Change-Id: I4504ae2b03c4877fcecfa58dd503879aa4eefac4
2018-07-20Limit Max GF boost for slide showsPaul Wilkins
Set an upper limit on the maximum boost for a static GF only group such as in slide shows as part of tweaks to quality / rate trade off. Change-Id: Ic72575328419cdcf82ad3a20a1d9b947538c25c6
2018-07-20Tweaks to determination of slide show groups.Paul Wilkins
Slight adjustment to rules for defining static groups. Adjustment of small bias towards 0,0 motion in first pass. Change-Id: Id1d3753979ad54622f983f4de08472738317ec8e
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-16Merge "Delete invalid assert."Paul Wilkins
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-09Delete invalid assert.Paul Wilkins
Delete assert that is not valid in all cases. This can occur if the last group in a clip is a GF only group. Here the frame count reflects the nominal positioning of the "next" GF (were it to exist) one frame beyond the of the end of the clip. Change-Id: I0d36b83de0ab478dab032599ee7df7fff4a35cd5
2018-06-22Add reference frame update flags for hierarchicalZoe Liu
Previous CLs have implemented the construction of the hierarchical structure at the encoder side. This CL is to define and configure the according flags that will guide the reference frame update according to the constructed hierarchical structure. Change-Id: Iae55f2400f7c7beff41feff9308f87bfc70c7b21
2018-06-22Add extra altref option for hierarchical structureZoe Liu
This CL is to hook up the implemented hierarchical structure construction as well as its corresponding bitrate allocation functionality with the defining of a GF group. Currently the hierarchical structure is off by default. Hence this CL has no impact on coding performance. Change-Id: I9e1ddfd877559e99072c23970f7fe103b64ed9ee
2018-06-20Add bit allocation for hierarchical layerZoe Liu
This CL migrates the bit allocation scheme from libaom and combines the scheme for hierarchical layer with the updated scheme in libvpx that uses a modified scheme to calculate the target bitrate per frame. Change-Id: I63593ed528abd4a6a1a8681abf6c9cf06c7a2ee0
2018-06-19Add hierarchical structure in GF groupZoe Liu
Change-Id: I06fc4b0ad5a45c49e10a9601a2356fbc6e93d6da
2018-06-14Separate GF structure defining from bit allocationZoe Liu
This CL separates the defining of the GF group structure from the handling of its bitrate allocation. The encoder performance should stay unchanged. Change-Id: Ib77967757702bb4b284034e429d4c41ae86d0838
2018-06-13Unify frame_index in defining GF group structureZoe Liu
Following are completed in defining GF group structure in firstpass: 1. Remove redundant alt_frame_index; 2. Remove hard coded index value with the variable of frame_index. Change-Id: I7b56e454559bbf704afc7410ea9832b20ffcd57e
2018-06-06Localize variable scope in vp9_rc_get_second_pass_params()Jingning Han
Remove unnecessary definitions. Change-Id: Ie540aaed5f3ed3768eff4e6563455666aef9c9e8
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-08Improved slide show codingpaulwilkins
This patch improves coding of slide shows with fade or other complex transitions. Previously, fades and other complex transitions between static "slides" were sometimes being incorrectly marked such that they were coded as a single static slide rather than two slides with a transition. As the initial key frame for the first slide is not necessarily a good predictor of the second slide and ARFs were turned off, this led to a poor visual and metrics outcome in some such cases. This patch allows for long GF groups in static sections before and after a complex transition (instead of just with simple slide transitions) with one or more normal ARF groups during the transition. It also 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 act as a good GF for the long static section that follows. Change-Id: Ica1f979e27d8a0625f3cebf7b7cf6d69edccaba9
2018-05-01Clean switch cases in vp9 encoderLinfeng Zhang
To save a branch. Change-Id: Ifa2be7583e95c6991784731c654bbd4cce31e993
2018-04-13Clean up is_two_pass_svc.Jerome Jiang
Change-Id: I9e92616471be380d3ba4e2b85399d7eb9f687d2f
2018-03-29Add extra case to wq_err_divisor()paulwilkins
Add extra case for 360P and smaller. This hurts a little in psnr for the derf cif set but helps a little in terms of average rate accuracy. Most clips come in a little smaller with this patch. No impact on larger formats. Change-Id: I5056246cb53b90f961ff9ea5813937f33778aa4c
2018-03-16Adjustment to initial q range estimate and kf boost.paulwilkins
Adjustment to initial active based on image size. Add extra breakout case for kf boost loop. Small adjustment to q delta calculation for key frames. Net % improvements for all standard tests sets (-ve values) measured using c-bvr mode. (Overall PSNR, SSIM, PSNR-HVS) Low Res: -0.223 -0.229 -0.107 Mid Res: -0.175 0.008 -0.180 High Res: -0.131 0.106 -0.206 NFlix 2K: -0.390 -0.271 -0.489 NFlix 4K: -1.370 -0.825 -1.590 Change-Id: I06a39de43594e1a99bb0cb281af15cdb8058a8ed
2018-02-28Change to KF frame boost calculation.paulwilkins
This change is targeted mainly at higher resolutions where typically the average error per MB is much smaller. hence this patch replaces a fixed error per MB factor with a tiered value. It also adds in a fixed offset value that acts as a minimum return score. Note also minor fix to debug stats output. The results are overall beneficial (-ve) on our test sets, most notably for higher definition formats (see below - overall psnr, ssim, psnr hvs) low res: 0.184 -0.262 -0.166 mid res: 0.094 0.075 0.049 hd res: -0.752 -0.300 -0.800 NF 2K: -0.353 1.095 -0.302 NF 4K: -1.245 -0.578 -1.205 The most notable negative case is pierseaside 2K which appears to be worse by 8-10% (which has a big impact on the overall gain for the NF 2K set). Closer inspection reveals that the drop does not relate to the key frame boost per se as in both cases the key frame substantially undershoots its target. Rather this is a side effect relating to the initial Q range allowed for the key frame and a poor initial complexity estimate. This will hopefully be improved in a later patch. Change-Id: I4773ebe554782f4024c047c3c392c763a3fe843b
2018-02-09Improved coding on slide show content.paulwilkins
This patch adds in detection of slide show key frame groups. The detection assumes extremely low or 0 motion for all frames in the key frame group. If this case is detected the boost level is set to a very high value and the min Q to a lower value for the key frame itself. Alt refs and golden frames are disabled to save bits (up to a limiting maximum interval currently set to 240 frames). In test samples that I created, 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 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. Given that average psnr tends to be dominated by the best frames, a ramp like this from q7.5 to lossless may give a better average psnr than, for example, coding the entire sequence at q2.5. Overall psnr, however, will be much better in the latter case. The option exists to boost the key frame further which would insure much better results for all metrics, but at the expense of smaller bitrate savings. Given that these samples tend to have very good quality anyway this seems like a bad trade off. For slides displayed for several seconds, bitrate savings of >= 20% are likely and much larger gains are possible in some cases. Change-Id: Ib4b61e153c55d3f2f561153da13fdb56f397a52b
2018-02-06Fix file input pointer bug in allocate_gf_group_bits().paulwilkins
The stats input pointer, when passed in, already points to the frame after the golden frame so should not be advanced here. This fix has a small mostly positive effect on results in our test sets (tested using corpus vbr settings) and gives a gain of almost 0.5% in overall psnr (plus slightly smaller gains on other metrics) for the 4K set. The bug also caused a crash in calculate_group_score() in another patch which allows coding of slides in a slide show as a single long KF group without ARFs or GFs. Change-Id: I57a3a24baf442ce55dbc91fba05e056697c63a6f
2018-01-31Further change to code detecting slide transitions.paulwilkins
Eliminate false positives in previous patch. The previous patch did a good job of detecting slide transitions but in discussions a number of situations were identified that might trigger harmful false positives. This risk seems to be born out by some testing on a wider YT set done by yclin@. This patch adds an additional clause that requires that the best case inter and intra error for the frame are very similar,meaning it is almost as easy to code a key frame as an inter frame. This will certainly prevent the false positive conditions that Jim and I discussed and even if one does occur it should not be very damaging. The down side is that this clause may mean that we still miss some real slide transitions, especially if the images are small and similar. If this proves to be the case then some further adjustment of the threshold may be required. However, in the specific problem sample provided we do trap every transition correctly. Change-Id: I7e5e79e52dc09bc47917565bf00cc44e5cddd44c
2018-01-22Merge changes from topic "clang-format"Johann Koenig
* changes: clang-format v5.0.0 vp9/ remove spurious comments clang-format v5.0.0 vp8/ clang-format v5.0.0 vpx_dsp/ clang-format v5.0.0 mem_ops.h clang-format v5.0.0 vpx_util/vpx_atomic.h clang-format v5.0.0 y4minput.c clang-format v5.0.0 vpxenc.c clang-format v5.0.0 examples/ clang-format v5.0.0 test/
2018-01-18clang-format v5.0.0 vp9/Johann
Remove trailing commas to keep multiple elements on one line. Add blank lines to prevent comments from being treated as blocks. clang-format guards for struct with a comment in the middle. Change-Id: I3bcb8313ae8aaf69179249a13b4087b1272cdbc0
2018-01-12Merge "Add zoom break out for kf boost loop."Paul Wilkins
2018-01-12Merge "Fix kf detection in some slide shows."Paul Wilkins
2018-01-10Add zoom break out for kf boost loop.paulwilkins
Adds a breakout threshold to key frame boost loop. This reduces the boost somewhat in cases where there is a significant zoom component. In tests most clips no effect but a sizable gain for some clips like station. Change-Id: I8b7a4d57f7ce5f4e3faab3f5688f7e4d61679b9a
2018-01-10Fix kf detection in some slide shows.paulwilkins
This fix improves detection of key frames in slide shows. In particular it helps if the slides are pictures of varying formats as in a sample provided by yclin@. This change does not impact any of the clips in our standard tests but for the example slide show test clip helped global psnr by several db and resolved a serious visual quality issue. Change-Id: Iaeeeed55dc0bb50aeacd4996ed660ced06374603
2018-01-05Fix bug in use of zoom metric as part of arf breakout.paulwilkins
The in/out (or zoom metrics) in accumulate_frame_motion_stats() are in effect a % of the blocks that have a motion vector pointing either towards or away from the center. As such they are already normalized in terms of image size and the thresholds against which these are tested should be image size independent. In practice a zoom either in or out is an indicator for a shorter group length so the abs value is more important as a breakout clause. This patch fixes the threshold test. Clips without noticeable zoom show no effect but some with strong zooms such as "station" show a big gain (5-10%). Average psnr-hvs gain on hdres set was 0.292% Change-Id: I4f97a72b0e273e4e844ade15285749c32cd81c1c
2017-12-08Bug fix for second reference stats.paulwilkins
Immediately following a key frame the trailing second reference error in the first pass stats will be based on a reference frame from the prior key frame group and will thus usually be much larger. This fix eliminates that effect (which typically triggers a short arf group immediately after a key frame). It also changes the accounting for the first frame in each new arf group. This change gives large gains on a couple of clips that contain mid sequence key frames (e.g. 6% on 1080P tennis). Overall there was a net gain in PSNR and PSNR-HVS ~(0.05- 0.4%) and mixed results for SSIM (+/- 0.2%). Change-Id: I8e00538ac2c0b5c2e7e637903cac329ce5c2a375
2017-11-15Code cleanup.paulwilkins
Removal of parameters to and code in calc_frame_boost() that is no longer required. No change to results from previous patch. Change-Id: Ic92da35613fdc247d22fddf24d09679fc5329017
2017-11-15Remove decay_accumulator clause from alt ref breakout.paulwilkins
The decay accumulator clause covers similar ground to the new clause that tests the accumulated second reference error so it has been removed to reduce complexity. Change-Id: I4ec1cce32d72bd4ee463ad7def2831a68447d525
2017-11-15Add clause to alt ref group breakout.paulwilkins
Add a clause to the breakout test for alt ref groups that examines the size of the accumulated second reference frame error compared to the cost of intra coding. This clause causes a reduction in the average group length for many clips. Alongside the change to the group length the minimum boost is increased. On balance the results are positive for psnr and psnr-hvs but is negative for ssim/fast ssim for the smaller image formats. Strong gains on some harder clips (eg ducks take off (midres) ~20%, husky (lowres) 6-17%. Most of the negative cases are lower motion clips. Subsequent patch hopefully will help with those. Change-Id: Ic1f5dbb9153d5089e58b1540470e799f91a65dc4
2017-11-13Small parameter clean up.paulwilkins
Removed three parameters that are no longer needed in calls to calc_arf_boost() and associated minor changes. No impact on encode results. Change-Id: Ieaf31d0d2e1990b99cf69647170145a1bbfbb9fb
2017-11-13Merge "Fix to frames considered in arf boost calculation."Paul Wilkins
2017-11-09Fix to frames considered in arf boost calculation.paulwilkins
For a chosen interval "i" the existing arf boost calculation examined frames +/- (i-1) frames from the current location in the second pass. This change checks to make sure that the forward search does not extend beyond the next key frame in the event that the distance to the next key frame is < (i - 1). Small metrics gains on all our test sets but these are localized to a few clips (e.g. midres set psnr-hvs sintel -2.59% but overall average was only -0.185%) Change-Id: I26fc9ce582b6d58fa1113a238395e12ad3123cf6
2017-11-08CVBR command line option.paulwilkins
Added command line control of Corpus VBR. The new corpus vbr mode is a variant of standard VBR (end-usage=0) where the complexity distribution mid point is passed in rather than calculated for a specific clip or chunk. The new variant is enabled by setting a new command line parameter --corpus-complexity to a zero value. Omitting this parameter or setting it to 0 will cause the codec to use standard vbr mode. The correct value for a given corpus needs to be derived experimentally using a training set such that the average rate for the corpus is close to the target value. For example our using our low res test set with upper and lower vbr limits of 50%-150% and a corpus complexity value of 650 gives a similar average data rate across the set to using standard vbr. However, with the corpus mode easier clips will be allocated fewer bits and harder clips more bits rather than having the same rate target for all. Change-Id: I03f0fc8c6fb0ee32dc03720fea6a3f1949118589
2017-10-12Increase precision of some debug stats output for corpus VBR.paulwilkins
Change-Id: I75841797cc0c215781b5b36e3a3e9f4b0e35ba63
2017-10-10Further Corpus VBR change.paulwilkins
Change to the bit allocation within a GF/ARF group. Normal VBR and CQ mode allocate bits to a GF/ARF group based of the mean complexity score of the frames in that group but then share bits evenly between the "normal" frames in that group regardless of the individual frame complexity scores (with the exception of the middle and last frames). This patch alters the behavior for the experimental "Corpus VBR" mode such that the allocation is always based on the individual complexity scores. Change-Id: I5045a143eadeb452302886cc5ccffd0906b75708
2017-10-10Corpus Wide VBR test implementation.paulwilkins
This patch makes further changes to support an experimental corpus wide VBR mode that uses a corpus complexity number as the midpoint of the distribution used to allocate bits within a clip, rather than some average error score derived from the clip itself. At the moment the midpoint number is hard wired for testing and the mode is enabled or disabled through a #ifdef. Ultimately this would need to be controlled by command line parameters. Change-Id: I9383b76ac9fc646eb35a5d2c5b7d8bc645bfa873
2017-09-01apply clang-formatclang-format
Change-Id: If4c3e8a396d0fcb304f407b44e28cac3219f038c
2017-08-09Patch relating to Issue 1456.paulwilkins
Testing of 4k videos encoded with a fixed arbitrary chunking interval uncovered a bug where by if a chunk ends 1 frame before a real scene cut, the next chunk may be encoded with two consecutive key frames at the start with the first being assigned 0 bits. This fix insures that where there is a key frame group of length 1 it is at least assigned 1 frames worth of bits not 0. See also patch Change-Id: I692311a709ccdb6003e705103de9d05b59bf840a which by virtue of allowing fast adaptation of Q made this bug more visible. BUG=webm:1456 Change-Id: Ic9e016cb66d489b829412052273238975dc6f6ab
2017-07-11Reintroduce fix for max qindex calculation of a gf intervalJim Bankoski
This reintroduces the fix: https://chromium-review.googlesource.com/c/422807/ and later reverted here: https://chromium-review.googlesource.com/c/447843/ BUG=webm:1355 This time behind a compile time flag : configure --disable-always_adjust_bpm configure --enable-always_adjust_bpm This should make side by side testing easier and let users of the lib pick which way they want to go. Change-Id: I7d7b37b83015dc001810af84c132cbc1e71ba8d6
2017-07-05Merge "Further refactoring of mod error calculation."Yaowu Xu
2017-07-05Further refactoring of mod error calculation.paulwilkins
Further refactoring to support alternative error distributions. Change-Id: I0f7fa3fd6f3baa4b0a1e53c6aa3be63966e97b82
2017-07-05Fix incorrect index test in GF group rate assignment.paulwilkins
Correct test for middle frame in the group. Change-Id: I1ee49fa33968eb3c4a01d6a27a60bb1409e3e68c