#!/usr/bin/bc # # videocalc.bc - Copyright (c) 2003 Nikolaus Rath # # Distribution and use allowed under the terms of the perl license. # scale=10 # CONFIGURE THIS: # The preferred resolution, achieved with quality=1 res_max = 640 * 480 # The preferred bpp, achieved with quality=1 bpp_max = 0.26 # The minimum resolution res_min = 528 * 240 # The minimum bpp bpp_min = 0.18 # END CONFIGURABLE SECTION # Input print "Enter actual width in pixels: " width_old = read() print "Enter actual height in pixels: " height_old = read() print "Enter desired quality (0 - 1) or bitrate (>1): " input = read() # Max shouldn't exceed actual size, we don't want # to make the video bigger if(res_max > width_old * height_old) res_max = width_old * height_old # Min shouldn't exceed actual size if(res_min > width_old * height_old) res_min = width_old * height_old if(input > 1) { # Bitrate bitrate_des = input # Calcute quality for desired bitrate rb_max = res_max * bpp_max rb_des = (bitrate_des * 1000) / 25 quality = rb_des / rb_max } else { # Quality was entered directly quality = input } # Calculate BPP and resolution for quality bpp_des = bpp_min + (bpp_max - bpp_min) * quality res_des = res_min + (res_max - res_min) * quality # Calculate final width and height based on resolution # (using aspect ratio and ensuring that width and height # are multiples of 16) rscale = sqrt((res_des) / (width_old*height_old)) if(rscale >= 1) { # Old resolution is lower than new resolution, we # increase max. 10 pixels or decrease max. 6 pixels # to ensure beeing n*16 width_new = width_old + 10 height_new = height_old + 10 } else { width_new = rscale * width_old height_new = rscale * height_old } scale=0 width_new -= width_new % 16 height_new -= height_new % 16 # Calculate effective reached bitrate bitrate = (25 * width_new * height_new * bpp_des)/1000 print "Quality: ", quality, "\n" print "BPP: ", bpp_des, "\n" print "Size: ", width_new/1, "x", height_new/1, "\n" print "Bitrate: ", bitrate, "\n" quit