Asp
Asp
DOCTYPE html>
<HTML lang="en">
<HEAD>
<TITLE>Video Bitrate Calculator</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<META name="author" content="Alexander Thomas">
<META name="generator" content="HTML TagWriter 3.8 by A.T.">
<META name="keywords" content="Convert, convertor, conversion, video, encoding,
bitrate, bit rate, KiloByte, MegaByte, GigaByte, TeraByte, ExaByte, KibiByte,
MebiByte, GibiByte, TebiByte, ExbyByte, online">
<META name="description" content="A calculator that helps to determine the optimal
bitrate for encoding movie files.">
<META name="viewport" content="width=device-width, initial-scale=1.0">
<LINK rel="stylesheet" href="../lexStyles.css" type="text/css">
<LINK rel="canonical" href="https://www.dr-lex.be/info-stuff/videocalc.html">
<STYLE><!--
TR {vertical-align:text-top}
TD.Label {font-weight:bold; text-align:right}
TD.Action {color:#038}
INPUT {font-family:monospace; text-align:left; margin:.1em .5em}
INPUT[type=button] {margin:.3em .5em}
.sml {font-size:.8em}
.flash {background:#FF0}
.plain {background:#FFF}
.in {background:#BFB}
.out {background:#FFB}
TR.set0 {background:#EEE}
TR.set1 {background:#CCC}
TR.set2 {background:#AAA}
TD.bottom {padding-bottom:.3em}
TD.title {height:2em; padding:.1em .8em; font-style:italic; vertical-align:middle}
SELECT.drop {display:inline-block; color:#0000; width:24px; height:24px; -moz-
appearance:none; -webkit-appearance:none; appearance:none;
background:url('../imags/drop_down.svg') #eee; border:1px solid #888; border-
radius:3px; margin-left:.5em}
SELECT.drop option {color:#000}
.code {font-family:monospace; background:#DDD; text-align:left}
@media (pointer: coarse) {
INPUT {margin:.3em .5em}
INPUT[type=button] {margin:.4em .5em}
SELECT.drop {margin-top:.25em; margin-bottom:.4em}
}
--></STYLE>
<!--HTMLTW includeFile="../ga.emb"--><!-- Google tag (gtag.js) -->
<script async
src="https://www.googletagmanager.com/gtag/js?id=G-763QGHGK34"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-763QGHGK34');
</script><!--/HTMLTW-->
</HEAD>
<BODY class="edu">
<DIV id="wrapper">
<DIV id="headMargin"> </DIV>
function roundN(x, n) {
return Number(Math.round(x + 'e' + n) + 'e-' + n);
}
// Update the other file size fields according to the current value of the source
field.
function updateCalc(source)
{
var oVal=0, val=0;
if(typeof source == "undefined" || source == "") {
source = lastSource;
} else {
lastSource = source;
}
eval("oVal = document.Calc."+source+".value;");
val = oVal;
switch(source) {
case "kB":
val *= 1000;
break;
case "KiB":
val *= 1024;
break;
case "MB":
val *= 1e6;
break;
case "MiB":
val *= 1048576;
break;
case "GB":
val *= 1e9;
break;
case "GiB":
val *= 1073741824;
break;
case "bits":
val /= 8;
break;
}
document.Calc.bytes.value = Math.ceil(val);
if(source == "bits") {
document.Calc.bits.value = oVal;
} else {
document.Calc.bits.value = Math.ceil(val)*8;
}
function getBPP()
{
var width = parseInt(document.Calc.Width.value);
var height = parseInt(document.Calc.Height.value);
var pixRate = width*height*parseFloat(document.Calc.FPS.value);
document.Calc.BPP.value =
roundN(1000*parseFloat(document.Calc.RVideo.value)/pixRate, 6);
flash('BPP');
}
function getAR()
{
var width = parseInt(document.Calc.Width.value);
var height = parseInt(document.Calc.Height.value);
document.Calc.AR.value = roundN(width/height, 2);
flash('AR');
}
function updateHMS(hms)
{
var s, HH, MM, SS;
if(hms == 's') {
s = parseInt(document.Calc.secs.value);
} else { // need to add the base, otherwise "08" is parsed as octal and
becomes 0
s =
parseInt(document.Calc.HH.value,10)*3600+parseInt(document.Calc.MM.value,10)*60+par
seInt(document.Calc.SS.value,10);
}
HH = Math.floor(s/3600);
MM = Math.floor((s%3600)/60);
SS = s%60;
// Update the bitrate fields that are affected by a change in fields of type 'typ'.
function updateRate(typ)
{
var s = parseInt(document.Calc.secs.value),
at = parseInt(document.Calc.ATrack.value),
ro = parseFloat(document.Calc.ROver.value),
ra = parseFloat(document.Calc.RAudio.value),
rv = parseFloat(document.Calc.RVideo.value);
if(typ == 'total') {
document.Calc.RVideo.value = parseFloat(document.Calc.RTotal.value)-ro-
at*ra;
flash('RVideo');
} else if(typ == 'video' || typ == 'vidFromBPP' || typ == 'audio' || typ ==
'over') {
document.Calc.RTotal.value = roundN(rv+at*ra+ro, 2);
flash('RTotal');
if(typ == 'video') {
getBPP();
}
} else {
var rTotal = roundN(8*document.Calc.bytes.value / (1000*s), 2);
document.Calc.RTotal.value = rTotal;
if(typ == 'time2vid') {
document.Calc.RVideo.value = roundN(rTotal-ro-at*ra, 2);
flash('RTotal,RVideo');
getBPP();
} else if(typ == 'time2aud') {
if(at != 0)
document.Calc.RAudio.value = roundN((rTotal-ro-rv)/at, 2);
else {
document.Calc.RAudio.value = 0;
}
flash('RTotal,RAudio');
} else if(typ == 'time2ovh') {
document.Calc.ROver.value = roundN(rTotal-rv-at*ra, 2);
flash('RTotal,ROver');
}
}
}
function setARate(r)
{
document.Calc.RAudio.value = r;
flash('RAudio');
updateRate('audio');
}
function arPreset()
{
var sel = document.getElementById("AR_pre");
var numOpt = sel.options.length;
for(var i=0; i<numOpt; i++) {
var opt = sel.options[i];
if(opt.selected) {
setARate(opt.value);
sel.selectedIndex = -1;
return;
}
}
}
function moreATracks()
{
var tracks = parseInt(document.Calc.ATrack.value);
if(isNaN(tracks) || tracks < 0)
tracks = 0;
document.Calc.ATrack.value = tracks + 1;
updateRate('audio');
}
function fewerATracks()
{
var tracks = parseInt(document.Calc.ATrack.value);
if(isNaN(tracks) || tracks < 1)
tracks = 1;
document.Calc.ATrack.value = tracks - 1;
updateRate('audio');
}
// Make a guesstimate for a reasonable video bitrate based on frame size and rate
and fudge factors.
function guessRate(codec)
{
var bpp;
var pixRate =
parseInt(document.Calc.Width.value)*parseInt(document.Calc.Height.value)*parseFloat
(document.Calc.FPS.value);
if(codec == 'raw') {
bpp = 24;
} else if(codec == 'mp4') {
bpp = 0.25;
} else if(codec == 'h264') {
bpp = 0.13;
} else if(codec == 'h264+') {
bpp = 0.11;
} else { //if(codec == 'h265')
bpp = 0.075;
}
if(codec != 'raw') {
if(document.Calc.cgi.checked) { bpp *= 0.75; }
if(document.Calc.dark.checked) { bpp *= 0.85; }
if(document.Calc.noise.checked) { bpp *= 1.25; }
}
function setSize(s)
{
document.Calc.bytes.value = s;
updateCalc('bytes');
}
function szPreset()
{
var sel = document.getElementById("sz_pre");
var numOpt = sel.options.length;
for(var i = 0; i < numOpt; i++) {
var opt = sel.options[i];
if(opt.selected) {
setSize(opt.value);
sel.selectedIndex = -1;
return;
}
}
}
function setFPS(f)
{
document.Calc.FPS.value = f;
flash('FPS');
getBPP();
}
function fpsPreset()
{
var sel = document.getElementById("FPS_pre");
var numOpt = sel.options.length;
for(var i = 0; i < numOpt; i++) {
var opt = sel.options[i];
if(opt.selected) {
setFPS(opt.value);
sel.selectedIndex = -1;
return;
}
}
}
function frameChanged()
{
getAR();
getBPP();
}
function ratioChanged()
{
var width = parseInt(document.Calc.Width.value);
var aRatio = document.Calc.AR.value;
if(aRatio.match(/^\d*\.?\d+:\d*\.?\d+$/)) {
var parts = aRatio.split(':');
aRatio = parts[0]/parts[1];
}
else {
aRatio = parseFloat(aRatio);
}
document.Calc.Height.value = Math.round(width/aRatio);
flash('Height');
getBPP();
}
function whPreset()
{
var sel = document.getElementById("WH_pre");
var numOpt = sel.options.length;
for(var i=0; i<numOpt; i++) {
var opt = sel.options[i];
if(opt.selected) {
var wh = opt.value.split("x");
document.Calc.Width.value = wh[0];
document.Calc.Height.value = wh[1];
getAR();
getBPP();
sel.selectedIndex = -1;
return;
}
}
}
function bppChanged()
{
var width = parseInt(document.Calc.Width.value);
var height = parseInt(document.Calc.Height.value);
var pixRate = width*height*parseFloat(document.Calc.FPS.value);
document.Calc.RVideo.value = roundN(pixRate *
parseFloat(document.Calc.BPP.value) / 1000, 2);
flash('RVideo');
updateRate('vidFromBPP');
}
function flash(fields)
{
var fieldsArray = fields.split(',');
for(var i=0; i<fieldsArray.length; i++) {
document.Calc.elements[fieldsArray[i]].setAttribute('class', 'flash');
}
window.setTimeout(function() {unFlash(fields);}, 500);
}
function unFlash(fields)
{
var fieldsArray = fields.split(',');
for(var i=0; i<fieldsArray.length; i++) {
document.Calc.elements[fieldsArray[i]].setAttribute('class', 'plain');
}
}
function showFlds(evt)
{
var fArray = evt.currentTarget.inFields.split(',');
for(var i=0; i<fArray.length; i++) {
document.Calc.elements[fArray[i]].setAttribute('class', 'in');
}
var outf = evt.currentTarget.outFields;
if(!outf)
return;
fArray = outf.split(',');
for(var i=0; i<fArray.length; i++) {
document.Calc.elements[fArray[i]].setAttribute('class', 'out');
}
}
function hideFlds(evt)
{
var f = evt.currentTarget.inFields;
if(evt.currentTarget.outFields)
f += ',' + evt.currentTarget.outFields;
unFlash(f);
}
function setupInputs()
{
prepInput("tsa2vid", 'HH,MM,SS,ROver,ATrack,RAudio,bytes',
'RVideo,RTotal,BPP', 'click', function() {updateRate('time2vid');});
prepInput("tsv2aud", 'HH,MM,SS,ROver,ATrack,RVideo,bytes', 'RAudio,RTotal',
'click', function() {updateRate('time2aud');});
prepInput("tsva2o", 'HH,MM,SS,RVideo,ATrack,RAudio,bytes', 'ROver,RTotal',
'click', function() {updateRate('time2ovh');});
prepInput("bs2t", 'bytes,RTotal', 'TB,HH,MM,SS', 'click', getTime);
var sFlds = 'bytes,kB,MB,GB,bits,KiB,MiB,GiB';
prepInput("tb2s", 'HH,MM,SS,RTotal', sFlds, 'click', function()
{getSize('total');});
prepInput("v2s", 'HH,MM,SS,RVideo', sFlds, 'click', function()
{getSize('video');});
prepInput("a2s", 'HH,MM,SS,ATrack,RAudio', sFlds, 'click', function()
{getSize('audio');});
prepInput("AR", 'Width', 'Height,BPP', 'change', ratioChanged);
prepInput("BPP", 'Width,Height,FPS', 'RVideo,RTotal', 'change', bppChanged);
sFlds = 'RVideo,RTotal,BPP';
prepInput("rRaw", 'Width,Height,FPS', sFlds, 'click', function()
{guessRate('raw');});
prepInput("rMP4", 'Width,Height,FPS', sFlds, 'click', function()
{guessRate('mp4');});
prepInput("r264", 'Width,Height,FPS', sFlds, 'click', function()
{guessRate('h264');});
prepInput("r264h", 'Width,Height,FPS', sFlds, 'click', function()
{guessRate('h264+');});
prepInput("r265", 'Width,Height,FPS', sFlds, 'click', function()
{guessRate('h265');});
document.getElementById('F_UI').value = "Force "+(isTouch?"desktop UI":"touch
UI");
document.getElementById('F_UI').addEventListener('click', toggleUI);
}
function toggleUI()
{
isTouch = !isTouch;
setupInputs();
}
function initCalc()
{
if('ontouchstart' in window || navigator.maxTouchPoints > 0)
isTouch = true;
setupInputs();
updateCalc('bytes');
updateHMS('s');
updateRate('time2vid');
// hack: ensure selecting value always triggers onChange
var reset = ["AR", "FPS", "WH", "sz"];
for(var i = 0; i < reset.length; i++) {
document.getElementById(reset[i] + "_pre").selectedIndex = -1;
}
}
<DIV class="mRoot">
<DIV class="article">
<!--HTMLTW includeFile="infoAd-inArt.emb"--><DIV class="adBox"><script async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-4744639122259360"
data-ad-slot="2576862267"></ins></DIV>
<!--needs cookiemgr--><!--/HTMLTW-->
<P class="center">
◆ Other calculators: <STRONG><A href="bytecalc.html">File sizes</A> — <A
href="timecalc.html">Time</A></STRONG> ◆
</P>
<H2 id="about">About</H2>
<P>
This calculator is intended to make bitrate calculations for encoding movies
easier. Fields used as inputs for a button or edit field are <SPAN
class="in">highlighted in green</SPAN>, and output fields <SPAN class="out">in pale
yellow</SPAN>. When pushing a button or having edited a field, fields updated by
this action will flash <SPAN class="flash">bright yellow</SPAN>.<br>
Highlighting behaviour differs between desktop and touch browsers due to
differences between a cursor- or touch-driven UI. If you prefer either or the
other, or if touch UI detection should fail, the button below the calculator allows
to override it.
</P>
<H2 id="use">Usage</H2>
<P>
The classic use case is to determine the required video bitrate to fill a fixed-
size medium like a CD-R or DVD+R, given a fixed audio bitrate and movie duration.
To do this, enter the duration, audio bitrate and target size, and press the
<EM>“Video from time,size,audio”</EM> button. You can do the same for audio. Total
audio bitrate is the number of audio tracks times the given audio bitrate. You can
use this to either represent multiple tracks (for instance languages), or multiple
discrete surround channels.
</P>
<P>
Another useful scenario is to determine whether a video file can fit in a fixed-
size medium like a DVD-R at acceptable quality. Or likewise, if you want to avoid
wasting download time on a file that just seems too small to possibly offer good
quality. In these cases, do the same as above to calculate the actual video bitrate
and write down or memorise this number. Then enter the film's image dimensions and
frame rate in the lower part of the calculator. Push the appropriate ‘Suggest
bitrate’ button (see instructions <A href="#suggest">below</A>). If the suggested
video bitrate is much higher than the actual one (about double or more), video
quality will probably be unacceptably bad. Just to give an example: with H.264
there is <EM>no</EM> way to fit a normal two-hour film on a single CD-R at anything
higher than DVD resolution without making it look or sound awful, so please do not
try it.
</P>
<P>
Mind that sizes are given in two ‘flavours.’ If you don't know the difference
between a <EM>MB</EM> and a <EM>MiB</EM>, check out my <A
href="bytecalc.html">other page that explains it</A>. Unfortunately a lot of
software still uses the ‘MB’ symbol while they actually mean MiB. In case of doubt,
assume KiB, MiB and GiB values: if the software does use kB, MB, and GB, your file
will be slightly too small, which is not as bad as too large.
</P>
<P>
<EM>Overhead</EM> is what is left of the file after removing actual video and audio
data. This is heavily dependent on the container format, codecs and parameters, and
includes any extra streams like subtitles. This calculator assumes overhead is
proportional to the length of the video, which is a simplification. In reality
there will also be a one-time overhead for the file itself and metadata. In case of
doubt and if the file must fit within a certain size, it's better to use a
conservatively high overhead estimate.
</P>
<H2 id="hint">Hints</H2>
</DIV><!--article-->
</DIV><!--mRoot-->
<DIV id="footMargin"></DIV>
</DIV><!--wrapper-->
</BODY>
</HTML>