Browse code

A quick description of Rate distortion theory.

Originally committed as revision 17774 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2009/03/04 01:09:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,50 @@
0
+A quick description of Rate distortion theory.
1
+
2
+We want to encode a video, picture or music optimally.
3
+What does optimally mean?
4
+It means that we want to get the best quality at a given
5
+filesize OR (which is almost the same actually) We want to get the
6
+smallest filesize at a given quality.
7
+
8
+Solving this directly isnt practical, try all byte sequences
9
+1MB long and pick the best looking, yeah 256^1000000 cases to try ;)
10
+
11
+But first a word about Quality also called distortion, this can
12
+really be almost any quality meassurement one wants. Commonly the
13
+sum of squared differenes is used but more complex things that
14
+consider psychivisual effects can be used as well, it makes no differnce
15
+to us here.
16
+
17
+
18
+First step, that RD factor called lambda ...
19
+Lets consider the problem of minimizing
20
+
21
+distortion + lambda*rate
22
+
23
+for a fixed lambda, rate here would be the filesize, distortion the quality
24
+Is this equivalent to finding the best quality for a given max filesize?
25
+The awnser is yes, for each filesize limit there is some lambda factor for
26
+which minimizing above will get you the best quality (in your provided quality
27
+meassurement) at that (or a lower) filesize
28
+
29
+
30
+Second step, spliting the problem.
31
+Directly spliting the problem of finding the best quality at a given filesize
32
+is hard because we dont know how much filesize to assign to each of the
33
+subproblems optimally.
34
+But distortion + lambda*rate can trivially be split
35
+just consider
36
+(distortion0 + distortion1) + lambda*(rate0 +rate1)
37
+a problem made of 2 independant subproblems, the subproblems might be 2
38
+16x16 macroblocks in a frame of 32x16 size.
39
+to minimize
40
+(distortion0 + distortion1) + lambda*(rate0 +rate1)
41
+one just have to minimize
42
+distortion0 + lambda*rate0
43
+and
44
+distortion1 + lambda*rate1
45
+
46
+aka the 2 problems can be solved independantly
47
+
48
+Author: Michael Niedermayer
49
+Copyright: LGPL