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

Give a formal expression of the specification, A function REPAT is specifie...

A function REPAT is specified below. Function REPAT(c in Char, i in Int, s in mString) return in mString pre 1 ≤ i ≤ the length of s. post The returned value is a string identic

Decode the code, By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the ...

By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area

Flash my terminal vx670, Flash my terminal vx670 Project Description: ...

Flash my terminal vx670 Project Description: Have VeriFone software need it to communicate with the vx670 through com port 1 it is not talking I'm not sure why have all the r

Fundamental input - output routines getc and putc, Access to the channel/de...

Access to the channel/devices is achieved by means of general purpose I/O routines Theses are standard functions described in stdio.h header file namely getc and putc. Getc and put

Program to determine the number is prime or not, Write a function to determ...

Write a function to determine whether a number is prime: it will return true if the input is prime and false otherwise. Use it to see whether -7 is prime.

Thermodynamics, want to solve the thermodynamics problems on c language

want to solve the thermodynamics problems on c language

Program, program to check whether a given point lies inside a rectangle or ...

program to check whether a given point lies inside a rectangle or not

C++, Write C++ code for calculating the time table

Write C++ code for calculating the time table

New customer, #questionhow can i add new customer and alot him a new unique...

#questionhow can i add new customer and alot him a new unique id ..

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