Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick and dirty explanation (through C code) of why we need video compression techniques
/*
* Project Name: VideoFrameSizes
* Solution Name: MandelbrotCalc
* Original creation date: 24/03/2011
* Edit date: 19/01/2013
* Programmer name: Jamie Taylor (aka "GaProgMan")
* File name: VideoFrameSizes.c
*
* Purpose of the project:
* To underpin the reasons why video compression exist
* by showing how much memory is required to store a video
* with the following attributes:
* Resolution (pixels): 640*480
* Colour depth: 24-bit
* Frame rate (fps): 25
*
*
* GNU Copyright information
* Copyright 2011 Jamie Taylor <jamie@taylorj.org.uk>
*
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General
* Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
int main(int argc, char** argv) {
float _width, _height, _pixelsPerFrame, _colourDepth, _bitsPerFrame,
_frameRate, _bitRate, _length, _videoSize = 0;
/* These values have been chosen as test values
* because they produce answers that are easy to
* predict. Also, they represent a compressed AVI
* rip of a Pal DvD source.
* 25 frames a second, 24 bit colour, 640 * 480,
* and 1 hour in length
*/
_width = 640; _height = 480; _colourDepth = 24;
_frameRate = 25; _length = 3600;
// pixels per frame
/* Commented these lines out as I'm testing the internal
* logic with known values, first
* printf("Enter the width for the video in pixels: ");
* scanf("%f", &_width);
* printf("Enter the height for the video in pixels: ");
* scanf("%f", &_height);
*/
_pixelsPerFrame = _width * _height;
printf("A video with %f pixels wide by %f high, ", _width, _height);
printf("has %f pixels per frame\n", _pixelsPerFrame);
//bits per frame
/* Commented these lines out as I'm testing the internal
* logic with known values, first
* printf("Enter the colour depth for the video in bits: ");
* scanf("%f", &_colourDepth);
*/
_bitsPerFrame = _pixelsPerFrame * _colourDepth;
_bitsPerFrame = (_bitsPerFrame/1024)/1024;
printf("A video with %f pixels per frame has ", _pixelsPerFrame);
printf("%f bits per frame\n", _bitsPerFrame);
//bit rate
/* Commented these lines out as I'm testing the internal
* logic with known values, first
* printf("Enter the frame rate in frames per second");
* scanf("%f", &_frameRate);
*/
_bitRate = _bitsPerFrame * _frameRate;
_bitRate = (_bitRate/1024)/1024;
printf("A video with %f frames per second has ", _frameRate);
printf("a bit rate of %f bits per second\n", _bitRate);
//video size
/* Commented these lines out as I'm testing the internal
* logic with known values, first
* printf("Enter the length for the video in seconds: ");
* scanf("%f", &_length);
*/
_videoSize = _bitRate * _length;
_videoSize = (_videoSize/1024)/1024;
printf("The video size is %f (in MBITS per second), ", _videoSize);
printf("which is %f in bytes per second", _videoSize/8);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.