# RealVideo 4

RealVideo 4 is available in RealPlayer starting with version 9. RealVideo 10 (introduced with RealPlayer 10) uses the same RV40 video format, and can be played by RealPlayer 9 decoder. All Realvideo 10 enhancements are in the encoder.

RV40 is somewhat of a prototype of H.264. It also shares the same internal structure as RealVideo 3, the main difference only in coding methods and codes used.

## Technical Details

The following block diagram is lifted wholesale from the above whitepaper and gives a general overview of the general decoding flow for a RealVideo 4 data stream.

This actually is not very interesting as it describes many video codecs.

## Transforms

These are the 4x4 inverse transforms used in the RV40 decoding process. These transforms assume an input coefficient matrix laid out as:

``` c0  c1  c2  c3
c4  c5  c6  c7
c8  c9 c10 c11
c12 c13 c14 c15
```

### ITransform4x4

For each row [c0 c1 c2 c3]:

```c0' = 13*c0 + 17*c1 + 13*c2 +  7*c3
c1' = 13*c0 +  7*c1 - 13*c2 - 17*c3
c2' = 13*c0 -  7*c1 - 13*c2 + 17*c3
c3' = 13*c0 - 17*c1 + 13*c2 -  7*c3
```

For each column [c0 c4 c8 c12]:

```c0' = (13*c0 + 17*c4 + 13*c8 +    c12 + 512) / 1024
c4' = (13*c0 +  7*c4 + 13*c8 - 17*c12 + 512) / 1024
c8' = (13*c0 -  7*c4 + 13*c8 + 17*c12 + 512) / 1024
c12'= (13*c0 - 17*c4 + 13*c8 +    c12 + 512) / 1024
```

Note that if only the DC coefficient is non-zero, it is possible to simply compute n as:

```n = (DC * 169 + 512) / 1024
```

and then populate the transformed matrix with n in all 16 positions.

### Intra16x16ITransform4x4

For each row [c0 c1 c2 c3]:

```c0' = 13*c0 + 17*c1 + 13*c2 +  7*c3
c1' = 13*c0 +  7*c1 - 13*c2 - 17*c3
c2' = 13*c0 -  7*c1 - 13*c2 + 17*c3
c3' = 13*c0 - 17*c1 + 13*c2 -  7*c3
```

For each column [c0 c4 c8 c12]:

```c0' = (624*c0 + 816*c4 + 624*c8 + 336*c12) / 32768
c4' = (624*c0 + 336*c4 - 624*c8 - 816*c12) / 32768
c8' = (624*c0 - 336*c4 - 624*c8 + 816*c12) / 32768
c12'= (624*c0 - 816*c4 + 624*c8 - 336*c12) / 32768
```

## Prediction

See H.264 Prediction for descriptions of RV40's prediction modes which are very similar to those found in H.264.