c programming a video player, C/C++ Programming

Assignment Help:
FIT 3042 System Tools and
Programming Languages
Semester 1 2013
Assignment 1
An SDL video player for a custom video format
Worth: 20% of final mark.
Must be completed individually
Hurdle: 40% of assignment marks across assignment 1&2.
Due: Monday 29th April 2013, 5PM.
In this project you will implement a simple video player using the Simple DirectMedia Layer as
a display library.
The video files that the player is required to play will be in a custom format called DUMBRLE,
and are based on one of the simplest graphics compression schemes runlength
encoding.
Pixel maps
As you probably know, video images are made up of a collection of coloured dots or pixels.
To represent these digitally, we use a sequence of numbers representing the intensity of red,
green, and blue colouration of each pixel by
convention, that order is typically used. For
most video files, 8bit
integers are used to represent colour intensity, where 0 (the smallest
value that can be represented as an 8bit
unsigned integer) represents the lowest intensity,
and 255 the highest.
The table below shows some example colour values and the resulting colour:
Color values Colour
(0,0,0) XXXX (black)
(0, 255,0) XXXX (green)
(128, 128, 0) XXXX (vomit)
(255, 255, 255) (white)
To represent an entire image in a file, all we need to do is store a sequence of colour values
in a defined order, and supply a little bit of extra information about the image size and shape
(either explicitly or implicitly). One very simple format for doing so is the Portable PixMap
format, or PPM, used in the widelydistributed
netpbm image processing tools. There are
two versions of PPM one
encodes the numbers directly, the second writes the numbers as
ASCII text and is known as "plain PPM". A very small example plain PPM is below. The first
line is a "magic number" that identifies the file as a "plain PPM" file, the second line contains a
comment, the third line records the width and height of the image in pixels, and the last line
contains the maximum value for a "channel" (note that this example uses 15 rather than the
more common 255).
Pixels are represented in the file lefttoright,
then toptobottom
order
.
P3
# feep.ppm
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
15 0 15 0 0 0 0 0 0 0 0 0
We could write a video player that simply reads and displays a sequence of PPM files
sufficiently quickly. However, there are two problems with this: first, it''s kind of
inconvenient to have a video spread out over thousands, possibly hundreds of
thousands of individual files, and secondly the PPM format takes up a lot of space just
to store a single image.
RLE image compression
As far as the second problem goes, we can reduce this by taking advantage of a common
property of image data it
is very repetitive. We can take advantage of this property using a
simple scheme called runlength
encoding.
As Wikipedia1 explains:
1 Runlength
encoding. (2012, November 9). In Wikipedia, The Free Encyclopedia. Retrieved 04:08,
December 13, 2012, from
For example, consider a screen containing plain black text on a solid white
background. There will be many long runs of white pixels in the blank space, and
many short runs of black pixels within the text. Let us take a hypothetical single scan
line, with B representing a black pixel and W representing white:
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
If we apply the runlength
encoding (RLE) data compression algorithm to the above
hypothetical scan line, we get the following:
12W1B12W3B24W1B14W
This is to be interpreted as twelve Ws, one B, twelve Ws, three Bs, etc.
The runlength
code represents the original 67 characters in only 18.
The runlength
encoding scheme we will use for our files is based on this principle, but is
slightly more sophisticated: the "PackBits Variant" scheme designed by Michael Dipperstein2.
Video File Format
Our video file format is unique. Like PPM, it contains some header information which
describes the dimensions of the frames that make up the images. It then contains data
representing each individual frame of the video.
To assist in the runlength
encoding, within each frame we will store the red channel for the
whole frame, then the green, then the blue. You should apply the PackBits algorithm to the
data for each channel, for each frame, independently.
A BackusNaur
form3 description of the file format is presented below:

::=

::=


::= "DUMBRLEv1\n"
::= " " "\n"
::=
::=

::= /* a positive integer rendered as an ASCII string */
::= | "E"
::= "K"

:: <
greenframedata><
blueframedata>

::
::

https://en.wikipedia.org/w/index.php?title=Runlength_
encoding&oldid=522223183
2
https://michael.dipperstein.com/rle/index.html
3
Add reference for BackausNaur
::

::
/* binary unsigned integers with variant PackBits
compression applied, see https://en.wikipedia.org/wiki/PackBits and
https://michael.dipperstein.com/rle/index.html*/

stores
the information for the red channel,
for the
green channel, and
for the blue channel. Each channel has an 8bit
value for
each pixel.
Each channel''s data is stored in rowmajor
order, so the first value corresponds to the top left of the
image, the second value the pixel immediately to the right, and so on, until you start the next row.
As noted, each channel''s data is compressed using "Variant PackBits" compression by Michael
Dipperstein.
There are a couple of sample DUMBRLE files, and in one case the PGM files from which it
was produced, on Moodle. There is also a Ubuntu package containing a tool,
ppmtodumbrle, which can compress a series of files in PPM format (all of the same size,
and with a maxval of 255) into a single dumbrle file.
to use it, you must first create a series of PPM files in the same directory using the following
naming convention:
xxxx.
ppm
Where prefix is a prefix common to all the files, and xxxx is a 4digit
integer 0000 up to
(potentially) 9999. The files must all be the same size.
To make a DUMBRLE file, run ppmtodumbrle as follows:
ppmtodumbrle outfile minindex
maxindex
Where outfile is the name for the output file, minindex
is the number of the first image in
the sequence you wish to convert, and maxindex
is the last.
Note that ppmtodumbrle has not been engineered properly, and will simply crash or
worse, fail silently, if the command line, if the input is illformed.
If you submit such a fragile
piece of code, you will be heavily marked down!
Simple DirectMedia Layer
The Simple DirectMedia Layer "is a crossplatform
multimedia library 4 designed to provide
low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D
video framebuffer". If it''s not already installed, you can install it on your virtual machine (you
will need the dev
package as well as the library itself).
4 https://www.libsdl.org
SDL
is extensively documented online, and there are many tutorials. As well as a 2D video
library, it provides support for event loops with timers, which may be useful for ensuring that
video frames are updated at the correct moments.
* SDL is introduced in Lectures 9&10.
Netpbm and libnetpbm
For stage 1, you may choose to use libnetpbm, a library that supports loading and saving
correctlyformed
PPM files. The PPM file format is very simple, so it is not really of that much
assistance. If you do, you should use the (very out of date, but functional) version included
with the Ubuntu distribution on the virtual machines.
Your Task
Your task is to implement a video player using SDL to play videos in the format described.
However, because the task is substantial, there are several incremental stages of
functionality that you should implement. Each stage builds on the previous one, and you
should share as much code as possible between them do
not do "cut and paste" reuse!
Furthermore, even if you complete stage 3, your submission should also build solutions for
stage 1 and 2 as well.
stage 1: maximum 10/20.
Implement a commandline
converter dumbrletoppm that converts a DUMBRLE file as
described above, into a series of PPM files.
dumbrletoppm takes two command line arguments: the first is the name of the DUMBRLE
file to convert, and the second is the prefix to be prepended to the output files. Each output
file should have xxxx.
ppm appended to it, where xxxx is a 4digit
integer indicating which
frame it is. The first frame should be 0001, the next 0002, and so on.
For instance, the following command
dumbrle2ppm stuff.dumbrle stuffout
If stuff.dumbrle is present and readable, and a correctly formed DUMBRLE file, this
should produce a sequence of files stuffout0001.
ppm, stuffout0002.
ppm and so
on.
stage 2: maximum 13/20
Implement a utility firstframeview that displays the first frame of a DUMBRLE file on the
screen. firstframeview should have two commandline
arguments, the first is the
name of the DUMBRLE file to be displayed, the second is the time (in seconds) for which the
frame is to be displayed before closing.
stage 3: maximum 17/20
Implement dumbrleplayer, which plays a DUMBRLE video using the SDL library.
dumbrleplayer has two commandline
arguments, the name of the file to be played, and
the delay (in milliseconds) between frames. Delays should not be allowed to accumulate a
50 frame video played with a delay of 20 should take 1 second to play! After the video has
finished playing, the program should close.
For example,
dumbrleplayer stuff.dumbrle 25
should play the DUMBRLE file stuff.dumbrle with each frame appearing at a 25
millisecond interval.

Related Discussions:- c programming a video player

How can define an array, Q: How can Define an Array? An Array is define...

Q: How can Define an Array? An Array is defined in much the alike manner as ordinary variables except that every array name must be accompanied by a size specification (that is

Programing solution, write a program that declares and initializes 2 intege...

write a program that declares and initializes 2 integer variable a and b with the value 35 and 14, and displays and calculates their sum,product,quotient and real division result.t

Define register simply with bit fields, Define register with bit fields? ...

Define register with bit fields? We could define register simply with bit fields: struct DISK_REGISTER { unsigned ready:1; unsigned error_occured:1; unsigned disk_spinni

Memory allocation for objects, when a class is defined the compiler will no...

when a class is defined the compiler will not allocate memory. This is true only for data member not for member function.  As soon as the member function is defined  the require

#psuedocode, Create a pseudocode in getting Calendar Quarter. The program s...

Create a pseudocode in getting Calendar Quarter. The program should identify which quarter falls the given date. Note: Consider the date format DDMMYYYY.

Program to display appropriate message-clients accounts, Question A ban...

Question A bank normally updates it's clients accounts at the end of each month.Of the two types of bank accounts:savings and checking, a client must maintain a minimum balance

Using nested if statement, write a program in c/C++ using nested if stateme...

write a program in c/C++ using nested if statement for calculating the average marks and grades of 5 subjects

Can copy constructor admit an object of the same class , Can copy construct...

Can copy constructor admit an object of the same class as parameter, rather than reference of the object?

Program to calculate tax - c++, Program to calculate tax: float tax (f...

Program to calculate tax: float tax (float) ; int main() {                 float purchase, tax_amt, total;                 cout                 cin >> purchase

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd