CS414 Spring 2009 Multimedia System Design

Homework and Machine Problems

Updated 28/01/09


Machine Problems

Hints for MP3

-         Slides of MP3 help session

-         Investigate the provided example code. (mp3server.c, mp3client.c, msg.h, Makefile)

Important: Please note that this is a very simple example. It uses TCP (UDP is required in mp3). Most of the code is adopted from the ffmpeg tutorial01. The most important part of code is in the function "fixCodecContext()".

Hints for MP2

-         Read through Beej socket programming tutorial (http://beej.us/guide/bgnet/)

-         Read the slides of the help session. (PPT)

-         Investigate the provided example code. (server.c, client.c, dispatcher.c, msg.h, Makefile)

Hints for MP1

In order to access the audio or video devices, you must be logged in at the console.

If you are using high-level APIs, please keep in mind that accessing individual media frames is very important for rewinding and fast forwarding in your video player.

Finding Audio & Video Content

MJPEG & Au files are highly recommended due to their simplicity. You might try to find them directly in the Internet.

Another option is to find video/audio contents in any formats (such as MPEG and WAV) and use ffmpeg to convert them into MJPEG/Au format. Please look at these howtos to see how to use ffmpeg to do various format conversions. The following might be a good starting point.

ffmpeg -i input.wav -f au output.au
ffmpeg -i input.mpg -vcodec mjpeg output.mjpeg

 C-based implementation: ffmpeg/SDL

The ffmpeg tutorial might be a good place to start if you want to write an audio and video player using ffmpeg and SDL libraries.

Note: The latest ffmpeg might be incompatible with the ffmpeg tutorials above. If you want to try those tutorials, one suggestion is to use earlier version of ffmpeg (such as revision 11879). If you want to install the specified ffmpeg above into csil-0216 machines, please look at the instructions below.

For some machines, the sound devices are in /dev/snd and can be accessed using the Advanced Linux Sound Architecture (ALSA).  For other machines, the sound devices can be accessed through /dev/dsp directly or through the SoX libraries.

For this particular MP, ffmpeg tutorial 1, 2, 3 and 7 are quite relevant. Tutorial 1 is an introduction. Tutorial 2 deals with displaying video without any delays. Tutorial 3 shows how to play sound. Tutorial 7 helps to understand seeking operation. Please go through these tutorials very carefully and think of how to customize/modify them to fit the specification of this MP.

Tutorial 3 can be modified to add delay to the video for a correct display. Look for the frame rate and use SDL_Delay() appropriately.

Tutorial 2 can be used to playback sound as it is. Please make sure you understand the code though.

Tutorial 7 uses av_seek_frame() to do seeking operation. Customize that to do fast forward/rewind operations.

If you want to try any GUI, you might want to check out GTK+.

Java-based implementation: Java Media Framework (JMF)

For this particular MP, JMF provides most of the functionalities. Following examples and guides might be useful.

Frame seeking inside a movie
http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/Seek.html

Accessing Individual Decoded Video Frames
http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/FrameAccess.html

JMF Programmer Guide
http://java.sun.com/javase/technologies/desktop/media/jmf/1.0/guide/index.html

Please note that JMF software might not be IS NOT available on CSIL-0216 machines due to some platform incompatibility issues. If you really want to use JMF, please let us know!

Java-based implementation: Building your own player from scratch!

The media player can be built scratch using Java standard libraries. For videos, the basic idea is to decompose video file into a sequence of JPEG images, and merge them into a big file with time your own timestamp, headers, index, etc… Then, the media player can simply just read those jpeg images and display accordingly.

Decomposing a video file into JPEG images can be done using ffmpeg utility. The ffmpeg utility is already in CSIL-0216 machines, you don’t have to install anything. Please look at ffmpeg howtos below for more information.
ffmpeg -i input.avi -f image2 -vcodec mjpeg img%d.jpg

Audio track can be extracted too!
ffmpeg -i input.avi -vn -acodec pcm_s16le -ar 44100 -ac 2 output.wav

To merge these jpeg images into your own MJPEG file, you may have to write your own script. The MJPEG file may need to contain an index for fast forward/rewind operation.

This sample code might be use for this approach.
http://www.csee.umbc.edu/~pmundur/courses/CMSC691C/lab5-kurose-ross.html

Playing audio content can be done using standard Java sound library.
http://www.jsresources.org/examples/audio_playing_recording.html

 

Resources

[Installing ffmpeg on csil-0216]

Download ffmpeg from SVN trunk:
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg -r 11879

Configure, make & install. Please make sure to replace “yourhomedir” into your home directory.

./configure –prefix=/usr/dcs/csil-projects/cs414/groupX/myffmpeg
./make
./make install

When compiling the tutorials, please make sure to use options –L/usr/dcs/csil-projects/cs414/groupX/myffmpeg/lib and –I/usr/dcs/csil-projects/cs414/groupX/myffmpeg/include to specify the ffmpeg headers and libraries.

[Some common errors when installing and compiling ffmpeg]
- “Input/output” error when “make” or “make install”
: not enough disk space. Free some space and try again.
- A bunch of errors like “undefined reference to `av_log’ ” when compiling with ffmpeg libraries: follow the order of libraries included “-lavformat –lavcodec –lavutil”

[ALSA on csil-0216]

On some csil-0216 machines, ASLA lib cannot find the “card 0” due to its default setting. Please look at this page for more information.

If you ever encounter such an error, please try the following
- Type “cat /proc/asound/cards” to list available sound cards. Look for the number at the sound card you want to output to. In csil-0216 machines, that is usually Intel card.
- Create a file “.asoundrc” in your home directory

pcm.!default {
            type hw
            card 1
}

ctl.!default {
            type hw
            card 1
}

, where the number after the “card” field is the one corresponding to the device we want to output to.

[Video/Audio examples]

Example WAV files
Example MPEG files

 

[ffmpeg howto(s)]

http://howto-pages.org/ffmpeg/

http://www.itbroadcastanddigitalcinema.com/ffmpeg_howto.html