Internatonal Journal of Scentfc & Engneerng Research, Volume 4, Issue, November-203 ISSN 2229-558 33 COMPARATIVE STUDY OF HUFFMAN CODING, SBAC AND CABAC USED IN VARIOUS VIDEO CODING STANDARS AND THEIR ALGORITHM [] Imran Ullah Khan Research Scholar, Dept. Electroncs & Comm. Engg Mewar Unversty, Mewar mranuk79@gmal.com [2] M.A.Ansar, Senor Member IEEE Dept. Electrcal Engneerng, SOE Gautam Budha Unversty, Gr. Noda ma.ansar@eee.org ABSTRACT symbols. It s necessary to calculate the probablty Ths paper represents the Algorthm for varous of occurrence of each symbol and to construct a set of Codng standards such as Huffman codng, Syntax varable length code words. based arthmetc codng and Adaptve Bnary Arthmetc Codng used n MPEG, H.263 and H.264 respectvely and ther analyss. We found that average A.GENERATING THE HUFFMAN CODE TREE bt per symbol (average code word length) for Huffman SYM codng s nearly equal to Entropy whch s the basc BOL requrement, for dfferent bt rate PSNR s calculated wth and wthout SBAC and fnally we dscuss Block PROBABILITY CODE dagrams of CABAC codec of H.264/AVC and Modfed parallel algorthm for CABAC. A 0.4 0.4 0.4 Experments demonstrate that ths SBAC provde the 0.6 mprovement of up to db over conventonal H.263. For a set of test sequences representng typcal B 0.2 0.2 0.4 0 materal used n broadcast applcatons and for a 0.4 range of acceptable vdeo qualty of about 30 to 38 db, average bt-rate savngs of 9%-4% are acheved. 0 Key Words: CABAC, VLC, Transform Coeffcent, DC C 0.2 0.2 0.2 coeffcent for INTRA blocks 0 D 0. 0.2 I. VARIABLE-LENGTH CODING A varable-length encoder maps nput symbols to a E 0. seres of code words (varable length codes or VLCs). Each symbol maps varyng length but must each contan an ntegral number of bts. Frequentlyoccurrng symbols are represented wth short VLCs whlst less common symbols are represented wth long VLCs. Over a suffcently large number of encoded Fgure : Huffman Code tree for Fve Symbols Table-: Huffman Code for Fve Symbols symbols ths leads to compresson of data. II. HUFFMAN CODING In computer scence and nformaton theory, Huffman codng s an entropy encodng algorthm used for lossless data compresson. The term refers to the use of a varable-length code table for encodng a source symbol (such as a character n a fle) where the varable-length code table has been derved n a partcular way based on the estmated probablty of occurrence for each possble value of the source symbol. It was developed by Davd A. Huffman whle he was a Ph.D. student at MIT, and publshed n the 952 paper "A Method for the Constructon of Mnmum-Redundancy Codes [9]. Huffman codng assgns a VLC to each symbol based on the probablty of occurrence of dfferent Message A B C D E Probabltes 0.4 0.2 0.2 0. 0. Code Word 00 0 00 0 The average bt per symbol (average code word length) s then L = 5 = p X Lengthof messagen bts L = 0.4 X 2 + 0.2 X 2 + 0.2 X 2 + 0. X 3 + 0. X 3 = 2.2 bts () Whch s very close to the entropy gven by 5 H(x) = p log p. (2) = 2 0 203
Internatonal Journal of Scentfc & Engneerng Research, Volume 4, Issue, November-203 ISSN 2229-558 34 B. ALGORITHM FOR HUFFMAN CODING IV. SYNTAX BASED ARITHMETIC CODING. Lst source symbol (messages) n the order of decreasng probablty. 2. The two source symbols of lowest probablty are assgned numbers 0 and. 3. These two source symbols are combned Into a new message. 4. The probablty of ths new message s Equal to the sum of probabltes of the two orgnal symbols. 5. The probablty of ths new message s Placed n the lst accordng to ts value. 6. Repeat ths procedure untl we are left wth only two source symbols, for whch a 0 and a are assgned. Fgure & 2 shows an example of Huffman Codng of fve symbols, A-E. Ther probabltes are shown n the second column. In the next column the two smallest probabltes are added and combned probablty s ncluded n the new order. The procedure contnues to the last column, where a sngle probablty s reached. Startng from the last column for every branch of probablty of a 0 s assgned to the top and a n the bottom[9]. The correspondng codeword s read off by followng the Fxed models are effectve when the Huffman codng can be optmum f the symbol probablty s an nteger power of /2 whch s usually not the case. Arthmetc codng s a data compresson technque that encodes data by creatng code strng whch represent a fractonal value on the number lne between 0 and [2]. It encourages clear separaton between the model for representng data and the encodng of nformaton wth respect to that model. Another advantage of arthmetc codng s that t dspenses wth the restrcton that each symbol must translate nto an ntegral number of bts, thereby codng more effcently. It actually acheves the theoretcal entropy bound of compresson effcency for any source. In other words arthmetc codng s a practcal way of mplementng entropy codng. There are two types of modelng used n arthmetc codng: Fxed model and adaptve model[5]. Characterstcs of the data source are close to the model and have lttle fluctuaton. In the adaptve model, the assgned probabltes May Change as each symbol s coded, based on the symbol Frequences seen so far. Each symbol s treated as an ndvdual unt and hence there s no need for a representatve sample of text. Intally all the counts mght be same, but they update as each symbol s seen. sequence from rght to left. Although n fxed word A. DEFINING A MODEL length each sample s represented by three bts, they are represented n varable length code from two or four In general, arthmetc coders can produce near-optmal bts. Output for any gven set of symbols and probabltes (the optmal value s log 2 P bts for each symbol of III. ARITHMETIC CODING probablty(p),compresson algorthms that use arthmetc codng start by determnng a model of the data bascally a The entropy encoder converts a seres of symbols predcton of what patterns wll be found n the symbols of representng elements of the vdeo sequence nto a the message. The more accurate ths predcton s the closer compressed bt stream sutable for transmsson or to optmal the output wll be storage. An arthmetc encoder converts a sequence of data symbols nto a sngle fractonal number and can approach the optmal fractonal number of bts requred to represent each symbol[8]. Block Layer Example: A smple, statc model for descrbng the output of a partcular montorng nstrument over tme mght be: 60% chance of symbol NEUTRAL 20% chance of symbol POSITIVE 0% chance of symbol NEGATIVE 0% chance of symbol END-OF-DATA For the four-symbol model above: a b c d e Fgure 2 : H.263 Structure of SBAC Block layer SBAC- Syntax based arthmetc codng a-intradc- DC coeffcent for INTRA blocks b- TCOF c- TCOF 2 d- TCOF 3 e- TCOF 4 TCOEF-Transform coeffcents The nterval for NEUTRAL would be [0, 0.6) The nterval for POSITIVE would be [0.6, 0.8) The nterval for NEGATIVE would be [0.8, 0.9) The nterval for END-OF-DATA would be [0.9,) B. ALGORITHM OF ARITHMETIC COING FOR ABOVE XAMPLE The process starts wth the same nterval used by the encoder: [0,), and usng the same model, dvdng t nto the same four sub-ntervals that the 203
Internatonal Journal of Scentfc & Engneerng Research, Volume 4, Issue, November-203 ISSN 2229-558 35 encoder must have. The fracton 0.538 falls nto the sub-nterval for () NEUTRAL, [0, 0.6); ths ndcates that the frst symbol the encoder read must have been NEUTRAL, so ths s the frst symbol of the message.() Next dvde the nterval [0, 0.6) nto sub- Intervals: (2) The nterval for NEUTRAL would be [0, 0.36) 6 0% of [0, 0.6) (4). The nterval for POSITIVE would be [0.36,0.48) 20% of [0, 0.6) (5). The nterval for NEGATIVE would be [0.48, 0.54) - 0% of [0, 0.6) (6). The nterval for END-OF-DATA would be [0.54, 0.6). -- 0% of [0, 0.6). 7. Snce.538 s wthn the nterval [0.48, 0.54), the second symbol of the message must have been NEGATIVE. Agan dvde our current nterval nto sub-ntervals: The nterval for NEUTRAL would be [0.48, 0.56) The nterval for POSITIVE would be [0.56, 0.528) The nterval for NEGATIVE would be [0.528, 0.534) The nterval for END-OF-DATA would be [0.534, 0.540). Now.538 falls wthn the nterval of the END-OF-DATA symbol; therefore, ths must be the next symbol. Snce t s also the nternal termnaton symbol, t means the decodng s complete. If the stream s not nternally termnated, there needs to be some other way to ndcate where the stream stops. Otherwse, the decodng process could contnue forever, mstakenly when all symbols have been encoded, the resultng nterval unambguously dentfes the sequence of symbols that produced t. Anyone who has the same fnal nterval and model that s beng used can reconstruct the symbol sequence that must have entered the encoder to result n that fnal nterval. A dagram showng decodng of 0.538 (the crcular pont) n the example model. Consder the process for decodng a message encoded wth the gven four-symbol model. The message s encoded n the fracton 0.538 (usng decmal for clarty, nstead of bnary; also assumng that there are only as many dgts as needed to decode the message.) readng more symbols from the fracton than were n fact encoded nto t Fgure 3: Example for Arthmetc codng V. OVERVIEW OF CONTEXT-BASED ARITHMETIC CODING (CABAC) IN H.264. H.264/MPEG-4 AVC s the latest vdeo compresson standard that acheves the same vdeo qualty wth almost half of the bt rate than prevous vdeo codng standards []. Frst a gven non-bnary value syntax element wll pass to bnarzaton to form a unquely bn-strng.second except for suffx of syntax element moton vector and level nformaton, all of bns from bnarzaton wll enter nto decson mode, and a probablty model wll be selected to assgn context Model[4]. The selecton of Probabltes models depends on prevously encode syntax element or bns. After recevng bn an context, AC can encode and output the compressed data drectly. AC can encode and output the compressed data almost half of the bt rate than prevous vdeo codng standards []. In whch, the entropy coder, -based Adaptve Bnary Arthmetc Codng (CABAC), plays an mportant role and can save, 9%~4% of bt rate n typcal broadcast applcatons [5]. However, the desgn and mplementaton of the CABAC s dffcult due to ts nherent bt-seral nature. The codng result of one bt often has a drect effect on the codng process of the successve bts. CABAC s used as one of the entropy codng method for H.264 vdeo codng that s conssted of three stages Bnarzaton, modelng and arthmetc codng (AC).Frst a gven non-bnary value syntax element wll pass to bnarzaton to form a unquely bn-strng.second except for suffx of syntax element moton vector and level nformaton[], all of bns from AC consst of two sub-engnes and s classfed n three modes () Decson mode that ncludes adaptve probablty models and nterval mantaner. (2) Bypass mode for fast encodng of symbols. (3) Termnaton mode for endng of encodng. Successful entropy codng depends on accurate models of symbol probablty. -based Arthmetc Encodng (CAE) uses local spatal and/or temporal characterstcs to estmate the probablty of a symbol to be encoded. Due to hgh correlaton between the symbols n the mage data, f the neghborng symbols of a, b, c are manly then t 203
Internatonal Journal of Scentfc & Engneerng Research, Volume 4, Issue, November-203 ISSN 2229-558 36 START Modeler Syntax Element CABAC Encoder CABAC Decoder Bnarzer Bn Strng Bnary Arthmetc Codng Engne Modeler Modeler Btt Stream 2 4 3 Syntax Element Debnarzer Bn Strng Bnary Arthmetc Decodng 5 6 Fgure 4: Block dagrams of CABAC codec of H.264/AVC 7 SE ndex generaton Range table access Bt-stream update read 8 memory 9 0 Bnarzaton Probablty update wrte Bnary Arthmetc codng AC 2 5 6 7 8 3 4 OUTPUT BIT PACKING 9 20 Fgure 5: Modfed parallel algorthm for CABAC Where SE-Syntax Element AC-Arthmetc codng 2 STOP Fgure 6: CABAC Decodng Flow 203
Internatonal Journal of Scentfc & Engneerng Research, Volume 4, Issue, November-203 ISSN 2229-558 37 Where IS Frst MB of Slce 2 Intalzaton context memory & other CABAC parameters 3 Determne Top/Left neghbor MBs for Current MB 4 MB parameters ntalze 5 Load nfo from global neghbor memory to local memores 6 Decode MB type and 8X8 type 7 IS skp MB? 8 IS ntra? 9 Decode IPCM MB 0 IS IPCM? Read ntra predcton mode 2 Read chroma ntra predcton mode 3 Read reference frame nfromaton neghborng symbols are manly 0 the assgned probablty of x= should be reduced. Thus we can defne the context for codng a symbol as: =2 2 c+2 b+2 0 a=4c+2b+a. (3) For the bnary values of a,b,c the context has a value between 0 and 7. Hgher values of context ndcate a hgher probablty should be assgned for codng of. Whch s nearly equal to average bts per symbol (average code word length) =2.65 bts () The software for vdeo codec used n ths work s test model No.8 (TMN 8) verson 3.0 developed by unversty of Brtsh Columba Canada. Ths coder can accept nput vdeo of varous formats and ncludes almost all optons ncludng that for advanced mode defned for H.263 standard. The tests are performed on standard vdeo sequence SALESMAN (QCIF,76x44,300 frames, 4:2:0 f ormat) The snapshot of ths vdeo sequence s shown n fg. (2).The performance s compared n terms of average Peak sgnal to nose rato (PSNR) usng followng relatonshp; 255 2 255 PSNR = 0log0 ( ) = 20log0( )(foreach Y,U,V)...(6) MSE MSE Where MSE s Mean square error X Y 2 MSE = [(x, y) e(x, y)]...(7) XY x= y= Where (x,y) = ntensty of nput pxel(for each Y,U,V) 4 Read moton vector dfferental nfo e(x,y) = ntensty of output pxel(for each Y,U,V) The PSNR for entre vdeo sequence s defned n terms of 5 Read CBP nfo average PSNR t 6 Read transform flag nfo Average PSNR = PSNR() (for each Y,U,V)...(8) 7 Read Delta quantzaton nfo t = 8 Read coeffcent nfo Where t s total number of frames n vdeo sequence wth each 9 Store current MB nfo n global neghbor frame of dmenson XY and PSNR() s the PSNR value for memory th frame and Y,U,V are standard lumnance and chromnance 20 Package current MB nfo n global neghbor sgnals respectvely. memory 2 IS last MB of slce Table 2 gves the summary of results obtaned for Huffman code and Entropy for varous values of probablty. Table 3 gves the summary of results obtaned n ths work regardng the performance of H.263 vdeo codec (Salesman sequence) for Syntax Based Arthmetc Codng at dfferent target bt rates. It s observed that for SBAC mprovement n PSNR s around 0.5 db. VI. SIMULATION RESULTS ()The Entropy of the symbols whch s the mnmum average bts requred to code the symbols can be calculate as; H ( x) = n p log 2 p.(4) = H(x) == 0.4log2(/0.4) + 0.2log2(/0.2) + 0.2log2(/0.2) + 0.log2(/0.) + 0.log2(/0.) = 2.29...(5) Fgure 7: Snapshot of Salesman vdeo sequence 203
Internatonal Journal of Scentfc & Engneerng Research, Volume 4, Issue, November-203 ISSN 2229-558 38 Table 2: Entropy vs. Huffman codes Probabl ty Average code word length(huffman Code) Entropy. 0.25 0.5 0.5 2. 0.20 0.4 0.45 3. 0.8 0.54 0.48 4. 0.5 0.45 0.42 5. 0.2 0.36 0.36 6. 0.06 0.24 0.244 7. 0.04 0.6 0.8 Table 3 : Smulaton results for SBAC S.No. Wthout SBAC Wth SBAC (a) OBR (kbps) PSNR (db) OBR (kbps) PSNR (db). 20.05 30.8 20.05 30.22 2. 40.0 32.7 40.0 32.99 3. 60.4 34.9 60.4 34.95 4. 80.6 35.99 80.6 35.84 5. 00.23 37.47 00.23 37.53 6. 20.23 38.0 20.2 38.0 7. 40.24 39.23 40.24 39.65 8. 60.25 40.7 60.25 40.02 9. 80.27 4.4 80.27 4.5 0. 200.29 42.42 200.29 4.49 (b) Fgure 8:(a) Entropy vs. rates acheved by Huffman codng. VII. CONCLUSION (b) Comparatve performance of H.263 Coder wth and wthout SBAC In ths paper we dscuss the Algorthm for varous Codng standards such as Huffman codng, Syntax based arthmetc codng and Adaptve Bnary Arthmetc Codng used n MPEG, H.263 and H.264 respectvely. We found that average bt per symbol (average code word length) for Huffman codng s nearly equal to Entropy whch s the basc requrement. For dfferent bt rate PSNR s calculated wth and wthout SBAC and there s a mprovement of 0.02 0.5 db wth the use of SBAC. Fnally we dscuss Block dagrams of CABAC codec of H.264/AVC and Modfed parallel algorthm for CABAC.For a set of test sequences. Also the CABAC decodng flow dagram. Where BPP-Bt per pxel PSNR-Peak Sgnal to Nose rato REFERENCES [] M.Ghanbar, Vdeo Codng: an ntroducton to standard codes; IEE press, London 999. [2]Langdon G.G.An ntroducton to arthmetc codng IBM journal, res. Develop, 28:2, pp.35-49, 984. [3] www.eee.org [4] ITU-T H.263 Encoder, verson 2,Sgnal Processng and Multmeda Group, Unversty of Brtsh Columba, Canada. [5] http:\\www.ubvdeo.com [6] Compressed vdeo communcatons, by Abdul H.Sadka,publshed by John Wley and sons, 2002. [7]R. Aravnd, R.Cvanlar, and A.R.Rebman, Packet loss reslence of MPEG- 2scalable vdeo codng algorths, IEEE Trans. Crsuts and System vdeo Technolology, vol. 6, pp. 426-435, Oct.994 203
Internatonal Journal of Scentfc & Engneerng Research, Volume 4, Issue, November-203 ISSN 2229-558 39 [8] G. G. Langdon, An ntroducton to arthmetc codng, IBM Journal of Research and Development, Vol. 28, No. 2, pp.35-49 Mar. 984. [9] D. A. Huffman, A method for the constructon of mnmum redundancy codes, Proceedngs IRE, vol.40, pp. 098-0, 952. [0] Draft ITU-T Recommendaton and Fnal Draft Internatonal Standard of Jont Vdeo Specfcaton (ITU-T Rec. H.264/ISO/ IEC 4496-0 AVC), Mar. 2003 [] Marpe. D, Schwarz. H, Wegand. T, based adaptve bnary arthmetc codng n the H.264/AVC vdeo compresson standard, IEEE Transactons on Crcuts and Systems for Vdeo Technology, Volume 3, Issue 7, July 2003,p.p 620 636. [2] Ha. V.H.S, W. S. Shm, and J. W. Km, Realtme MPEG-4 AVC/H.264 CABAC entropy coder, n Internatona Conference on Consumer Electroncs Dgest of Techncal Papers, p.p 255-256, Jan. 8-2, 2005 [3] R. R. Osoro and J. D. Bruguera, Hgh- Throughput Archtecture for H.264/AVC CABAC Compresson System, IEEE Transactons on Crcuts and Systems for Vdeo Technology, Vol.6, No., pp.376-384, Nov. 2006. 203