View Full Version : Bitrate -vs- Resolution
bobmaster
4th October 2005, 17:49
Hi
I would like to know the algorithm that programs like "Dr.DivX" and "Nero Recode" to calculate the resolution of the video depending on the final video bitrate. e.g. selecting a low bitrate causes resolution to drop and vice versa.
Some code would be nice (any language) :)
Inputs: Original Resolution X, Original Resolution Y, Output Bitrate
Outputs: New X, New Y.
Thanks
E-Male
4th October 2005, 18:55
if you really wanna automat that you need to decide for a minimum bits per pixel value
then you'd also need a FPS parameter to be exact
bitrate/(xres*yres*fps) should give you the bits per pixel ratio
if it is smaller then the one you want reduce the resolution
if nobody beats me to it i'll try to come up with some c-code later tonight
but i can't promise elegant or opimized code (but working code if i don't miss anything)
bobmaster
5th October 2005, 20:39
Thanks
What is the typical bits-per-pixel value for Divx5 codec? (good/normal quality).
I assume better codecs have lower bits-per-pixel for the same quality.
I think 0.2bbp is good for Divx5 and 0.1bbp for AVC.
Correct me if I am wrong.
E-Male
5th October 2005, 20:47
i got 0.17 in the back of my head, but that likely is outdated
i'm not sure if i can write the function you requested, but if i get it done i'll post it
E-Male
5th October 2005, 22:00
ok, i think this should do it:
(resmod is the value height and with should be devidable by, for example 16
bitrate in bits/s, NOT kilobits
pixel-ar of input and output must be equal [this one will be fixed later])
input: int x, int y, int bitrate, float fps, float bpp, int resmod
float ar=x/y
x /= resmod;
x *= resmod;
y=x/ar;
y /= resmod;
y *= resmod;
while(bpp>(bitrate/(fps*x*y)))
{
x -= resmod;
y=x/ar;
y /= resmod;
y *= resmod;
}
output: int x, int y
hope it works and helps
stax76
5th October 2005, 23:21
You are missing a essential variable, the comp check. Some movies will compress 3 times better than other.
E-Male
6th October 2005, 00:07
that's why i have an input variable for bpp
i t hink putting a compression check inside this function would be overkill
it should be a function on it's on
bobmaster
6th October 2005, 00:14
Thanks E-Male, code works great.
I tested in VB6 (i've lost my .NET discs :( )
Heres the code I made from E-Male's example, if anyones intrested.
Private Function ResizeVideo(X As Integer, Y As Integer, Bitrate As Long, _
FPS As Double, BPP As Double, resmod As Integer) As Variant
Dim TempArray(1) As Integer
Dim AR As Double
AR = X / Y
X = X / resmod
X = X * resmod
Y = X / AR
Y = Y / resmod
Y = Y * resmod
Bitrate = Bitrate * 1024 'change bits to killobits
While (BPP > (Bitrate / (FPS * X * Y)))
X = X - resmod
Y = X / AR
Y = Y / resmod
Y = Y * resmod
Wend
TempArray(0) = X
TempArray(1) = Y
ResizeVideo = TempArray
End Function
'test code
Private Sub Command1_Click()
output = ResizeVideo(640, 480, 500, 25, 0.17, 16)
Shape1.Width = output(0)
Shape1.Height = output(1)
End Sub
I'll probably never make a usefull program out of this... but its good to learn.
Thanks alot e-male! :)
:thanks:
Now... this "compression check" I take its used to automaticly calculate the bpp value? .... suppose i'll do some research, figure out how it works.....
stax76
6th October 2005, 00:24
I tested in VB6 (i've lost my .NET discs )
besides the free sdk with cli compiler there are quite a few free IDE's, the undoubted best IDE for .NET and C++ is free as well until Mai where it will be at 50$ for the smallest version
http://lab.msdn.microsoft.com/express/vbasic/default.aspx
Now... this "compression check" I take its used to automaticly calculate the bpp value? .... suppose i'll do some research, figure out how it works.....
source code for it can be found in Gordian Knot and DVX
jonny
6th October 2005, 11:54
About comp. check, this is an old thread (bpp is also covered):
http://forum.doom9.org/showthread.php?t=44621
here is a more general overview of "size prediction":
http://forum.doom9.org/showthread.php?t=100154
(search my long post in this thread)
here is a manual way to do it (can help to understand how it works):
http://forum.doom9.org/showthread.php?t=44414
Also you should check VirtualDubMod's command line options:
/log
/nowrite
if you want to automate it with VirtualDub
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.