📄 snow.txt
字号:
------------ | \ Dequantizaton ------------------- \ || Reference frames | \ IDWT| ------- ------- | Motion \ |||Frame 0| |Frame 1|| Compensation . OBMC v -------| ------- ------- | --------------. \------> + --->|Frame n|-->output| ------- ------- | -------||Frame 2| |Frame 3||<----------------------------------/| ... | -------------------Range Coder:============FIXMENeighboring Blocks:===================left and top are set to the respective blocks unless they are outside ofthe image in which case they are set to the Null blocktop-left is set to the top left block unless it is outside of the image inwhich case it is set to the left blockif this block has no larger parent block or it is at the left side of itsparent block and the top right block is not outside of the image then thetop right block is used for top-right else the top-left block is usedNull blocky,cb,cr are 128level, ref, mx and my are 0Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled tocompensate for the difference of reference framesscaled_mv= (mv * (256 * (current_reference+1) / (mv.reference+1)) + 128)>>82. the median of the scaled left, top and top-right vectors is used asmotion vector prediction3. the used motion vector is the sum of the predictor and (mvx_diff, mvy_diff)*mv_scaleIntra DC Predicton:======================the luma and chroma values of the left block are used as predictorsthe used luma and chroma is the sum of the predictor and y_diff, cb_diff, cr_diffto reverse this in the decoder apply the following:block[y][x].dc[0] = block[y][x-1].dc[0] + y_diff;block[y][x].dc[1] = block[y][x-1].dc[1] + cb_diff;block[y][x].dc[2] = block[y][x-1].dc[2] + cr_diff;block[*][-1].dc[*]= 128;Motion Compensation:====================Halfpel interpolation:----------------------halfpel interpolation is done by convolution with the halfpel filter storedin the header:horizontal halfpel samples are found byH1[y][x] = hcoeff[0]*(F[y][x ] + F[y][x+1]) + hcoeff[1]*(F[y][x-1] + F[y][x+2]) + hcoeff[2]*(F[y][x-2] + F[y][x+3]) + ...h1[y][x] = (H1[y][x] + 32)>>6;vertical halfpel samples are found byH2[y][x] = hcoeff[0]*(F[y ][x] + F[y+1][x]) + hcoeff[1]*(F[y-1][x] + F[y+2][x]) + ...h2[y][x] = (H2[y][x] + 32)>>6;vertical+horizontal halfpel samples are found byH3[y][x] = hcoeff[0]*(H2[y][x ] + H2[y][x+1]) + hcoeff[1]*(H2[y][x-1] + H2[y][x+2]) + ...H3[y][x] = hcoeff[0]*(H1[y ][x] + H1[y+1][x]) + hcoeff[1]*(H1[y+1][x] + H1[y+2][x]) + ...h3[y][x] = (H3[y][x] + 2048)>>12; F H1 F | | | | | | | | | F H1 F | | | | | | | | | F-------F-------F-> H1<-F-------F-------F v v v H2 H3 H2 ^ ^ ^ F-------F-------F-> H1<-F-------F-------F | | | | | | | | | F H1 F | | | | | | | | | F H1 Funavailable fullpel samples (outside the picture for example) shall be equalto the closest available fullpel sampleSmaller pel interpolation:--------------------------if diag_mc is set then points which lie on a line between 2 vertically,horiziontally or diagonally adjacent halfpel points shall be interpolatedlinearls with rounding to nearest and halfway values rounded up.points which lie on 2 diagonals at the same time should only use the onediagonal not containing the fullpel point F-->O---q---O<--h1->O---q---O<--F v \ / v \ / v O O O O O O O | / | \ | q q q q q | / | \ | O O O O O O O ^ / \ ^ / \ ^ h2-->O---q---O<--h3->O---q---O<--h2 v \ / v \ / v O O O O O O O | \ | / | q q q q q | \ | / | O O O O O O O ^ / \ ^ / \ ^ F-->O---q---O<--h1->O---q---O<--Fthe remaining points shall be bilinearly interpolated from theup to 4 surrounding halfpel and fullpel points, again rounding should be tonearest and halfway values rounded upcompliant snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chromainterpolation at leastOverlapped block motion compensation:-------------------------------------FIXMELL band prediction:===================Each sample in the LL0 subband is predicted by the median of the left, top andleft+top-topleft samples, samples outside the subband shall be considered tobe 0. To reverse this prediction in the decoder apply the following.for(y=0; y<height; y++){ for(x=0; x<width; x++){ sample[y][x] += median(sample[y-1][x], sample[y][x-1], sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]); }}sample[-1][*]=sample[*][-1]= 0;width,height here are the width and height of the LL0 subband not of the finalvideoDequantizaton:==============FIXMEWavelet Transform:==================Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integertransform and a integer approximation of the symmetric biorthogonal 9/7daubechies wavelet.2D IDWT (inverse discrete wavelet transform)--------------------------------------------The 2D IDWT applies a 2D filter recursively, each time combining the4 lowest frequency subbands into a single subband until only 1 subbandremains.The 2D filter is done by first applying a 1D filter in the vertical directionand then applying it in the horizontal one. --------------- --------------- --------------- ---------------|LL0|HL0| | | | | | | | | | | ||---+---| HL1 | | L0|H0 | HL1 | | LL1 | HL1 | | | ||LH0|HH0| | | | | | | | | | | ||-------+-------|->|-------+-------|->|-------+-------|->| L1 | H1 |->...| | | | | | | | | | | || LH1 | HH1 | | LH1 | HH1 | | LH1 | HH1 | | | || | | | | | | | | | | | --------------- --------------- --------------- ---------------1D Filter:----------1. interleave the samples of the low and high frequency subbands likes={L0, H0, L1, H1, L2, H2, L3, H3, ... }note, this can end with a L or a H, the number of elements shall be ws[-1] shall be considered equivalent to s[1 ]s[w ] shall be considered equivalent to s[w-2]2. perform the lifting steps in order as described below5/3 Integer filter:1. s[i] -= (s[i-1] + s[i+1] + 2)>>2; for all even i < w2. s[i] += (s[i-1] + s[i+1] )>>1; for all odd i < w\ | /|\ | /|\ | /|\ | /|\ \|/ | \|/ | \|/ | \|/ | + | + | + | + | -1/4 /|\ | /|\ | /|\ | /|\ |/ | \|/ | \|/ | \|/ | \|/ | + | + | + | + +1/2snows 9/7 Integer filter:1. s[i] -= (3*(s[i-1] + s[i+1]) + 4)>>3; for all even i < w2. s[i] -= s[i-1] + s[i+1] ; for all odd i < w3. s[i] += ( s[i-1] + s[i+1] + 4*s[i] + 8)>>4; for all even i < w4. s[i] += (3*(s[i-1] + s[i+1]) )>>1; for all odd i < w\ | /|\ | /|\ | /|\ | /|\ \|/ | \|/ | \|/ | \|/ | + | + | + | + | -3/8 /|\ | /|\ | /|\ | /|\ |/ | \|/ | \|/ | \|/ | \|/ (| + (| + (| + (| + -1\ + /|\ + /|\ + /|\ + /|\ +1/4 \|/ | \|/ | \|/ | \|/ | + | + | + | + | +1/16 /|\ | /|\ | /|\ | /|\ |/ | \|/ | \|/ | \|/ | \|/ | + | + | + | + +3/2optimization tips:following are exactly identical(3a)>>1 == a + (a>>1)(a + 4b + 8)>>4 == ((a>>2) + b + 2)>>216bit implementation note:The IDWT can be implemented with 16bits, but this requires some care toprevent overflows, the following list, lists the minimum number of bits neededfor some terms1. lifting stepA= s[i-1] + s[i+1] 16bit3*A + 4 18bitA + (A>>1) + 2 17bit3. lifting steps[i-1] + s[i+1] 17bit4. lifiting step3*(s[i-1] + s[i+1]) 17bitTODO:=====Important:finetune initial contextsflip wavelet?try to use the wavelet transformed predicted image (motion compensated image) as context for coding the residual coefficientstry the MV length as context for coding the residual coefficientsuse extradata for stuff which is in the keyframes now?the MV median predictor is patented IIRCimplement per picture halfpel interpolationtry different range coder state transition tables for different contextsNot Important:compare the 6 tap and 8 tap hpel filters (psnr/bitrate and subjective quality)spatial_scalability b vs u (!= 0 breaks syntax anyway so we can add a u later)Credits:========Michael NiedermayerLoren MerrittCopyright:==========GPL + GFDL + whatever is needed to make this a RFC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -