qwerpoi
26th January 2004, 20:53
As the title suggests, this is a bitrate calculator written in my
favorite programming language, Avisynth :) . The function takes in a
target filesize (default 700MB) and an audio bitrate (default 128kb/s)
and tells you the target video bitrate or filesize, as well as the
bits per pixel.
function BitrateCalc(clip c,float "target_size",float "audio_bitrate",string "container",float "bpp_threshold")
{
target_size = default(target_size,700) #MB
audio_bitrate = default(audio_bitrate,128) #kB/s
container = default(container,"avi")
bpp_threshold = default(bpp_threshold,0.170)
assert((container=="avi")||(container=="ogm")||(container=="mkv"), "Valid containers are avi, ogm, or mkv")
seconds = c.framecount/c.framerate
audiosize = (audio_bitrate/8.0)*(seconds/1024.0)
overhead = (container == "avi") ? (c.framecount)*(24+24)/(1024*1024+0.0) :
\ ((container == "ogm") ? (c.framecount)*(0.069)/(1024+0.0) :
\ (c.framecount)*(0.013)/(1024+0.0))
videosize = target_size-audiosize-overhead
targetbitrate = videosize*1024*8/seconds
bpp = (targetbitrate*1024)/(c.framerate*c.width*c.height+0.0)
f = c.Subtitle("Audio Size = "+String(round(audiosize))+" MB",last_frame=1)
f = f.Subtitle("Video Size = "+String(round(videosize))+" MB"+" ("+container+" overhead = "+String(round(overhead))+" MB)",last_frame=1,y=36)
f = f.Subtitle("Target Bitrate = "+String(round(targetbitrate))+" kB/s",last_frame=1,y=72)
f = f.Subtitle("Target Filesize = "+String(floor(videosize*1024))+" kB",last_frame=1,y=90)
f = bpp > bpp_threshold ? f.Subtitle("Bits Per Pixel = "+LeftStr(String(bpp),5),last_frame=1,y=108,text_color=$00FF00) :
\ f.Subtitle("Bits Per Pixel = "+LeftStr(String(bpp),5),last_frame=1,y=108,text_color=$FF0000)
return f
}
To use it, simply copy the above code into the beginning of your
script, or copy it into a text file and name it something.avsi and
put it in your plugins directory. Example usage:
mpeg2source("D:\something.d2v")
LanczosResize(640,480)
BitrateCalc()
Preview this script in Virtualdub, information will be written on the
first two frames of the video. You can also specify a container to
calculate overhead. I got the formulas for the overhead
computations by searching this forum, please let me know if there are
any problems with them.
Why use this? Well, you don't need to input stuff like resolution,
number of frames, framerate, etc., since avisynth already knows it.
If you use gordian knot, you probably don't need this, but if you're
like me, and use only avisynth and virtualdub to set up your dvd
backups, it might come in handy (well, maybe until xvid 1.0 has a
working bitrate calculator). Let me know if you use it or have any
problems with it.
favorite programming language, Avisynth :) . The function takes in a
target filesize (default 700MB) and an audio bitrate (default 128kb/s)
and tells you the target video bitrate or filesize, as well as the
bits per pixel.
function BitrateCalc(clip c,float "target_size",float "audio_bitrate",string "container",float "bpp_threshold")
{
target_size = default(target_size,700) #MB
audio_bitrate = default(audio_bitrate,128) #kB/s
container = default(container,"avi")
bpp_threshold = default(bpp_threshold,0.170)
assert((container=="avi")||(container=="ogm")||(container=="mkv"), "Valid containers are avi, ogm, or mkv")
seconds = c.framecount/c.framerate
audiosize = (audio_bitrate/8.0)*(seconds/1024.0)
overhead = (container == "avi") ? (c.framecount)*(24+24)/(1024*1024+0.0) :
\ ((container == "ogm") ? (c.framecount)*(0.069)/(1024+0.0) :
\ (c.framecount)*(0.013)/(1024+0.0))
videosize = target_size-audiosize-overhead
targetbitrate = videosize*1024*8/seconds
bpp = (targetbitrate*1024)/(c.framerate*c.width*c.height+0.0)
f = c.Subtitle("Audio Size = "+String(round(audiosize))+" MB",last_frame=1)
f = f.Subtitle("Video Size = "+String(round(videosize))+" MB"+" ("+container+" overhead = "+String(round(overhead))+" MB)",last_frame=1,y=36)
f = f.Subtitle("Target Bitrate = "+String(round(targetbitrate))+" kB/s",last_frame=1,y=72)
f = f.Subtitle("Target Filesize = "+String(floor(videosize*1024))+" kB",last_frame=1,y=90)
f = bpp > bpp_threshold ? f.Subtitle("Bits Per Pixel = "+LeftStr(String(bpp),5),last_frame=1,y=108,text_color=$00FF00) :
\ f.Subtitle("Bits Per Pixel = "+LeftStr(String(bpp),5),last_frame=1,y=108,text_color=$FF0000)
return f
}
To use it, simply copy the above code into the beginning of your
script, or copy it into a text file and name it something.avsi and
put it in your plugins directory. Example usage:
mpeg2source("D:\something.d2v")
LanczosResize(640,480)
BitrateCalc()
Preview this script in Virtualdub, information will be written on the
first two frames of the video. You can also specify a container to
calculate overhead. I got the formulas for the overhead
computations by searching this forum, please let me know if there are
any problems with them.
Why use this? Well, you don't need to input stuff like resolution,
number of frames, framerate, etc., since avisynth already knows it.
If you use gordian knot, you probably don't need this, but if you're
like me, and use only avisynth and virtualdub to set up your dvd
backups, it might come in handy (well, maybe until xvid 1.0 has a
working bitrate calculator). Let me know if you use it or have any
problems with it.