The MPEG4IP Server Side Tools allow for the
conversion of raw audio and video into MPEG-4 compressed media stored in an MP4
file which can be streamed by the Darwin Streaming Server.
If you are using a UNIX system, the easiest
way to proceed is to use the 'mp4encode' script which is installed with
MPEG4IP. This script makes some simplifying assumptions about the input and the
desired output. See "The Simple Process" below.
If you are using Windows, or if 'mp4encode'
doesn't meet your needs, you must use the tools directly. See "The
Detailed Process" below for the details of the underlying tools.
The Simple Process
1) Capture raw audio and/or video into an
AVI file
The details here are varied. But generally
speaking, you use a capture program to record audio and video from either a
camera or a capture board into an AVI file on disk.
The audio format should be PCM raw audio, 16
bits/sample, little-endian, 2 channels, 44100 samples/sec.
The video format should be YUV12, aka YV12.
(FYI: This is a planar format sampled at 4:2:0). Any frame size and frame rate
are acceptable. If your capture program doesn't support this format, capture in
RGB24 (packed format) which every capture program should support; MPEG4IP has a
utility to convert from RGB24 to YUV12.
Personally, I recommend 320x240 @ 24
frames/sec as a good compromise between video quality and size. At these
settings, 5 minutes of raw audio/video will consume approximately 1 GB of disk
space. (Don't worry things get much better once we encode.)
2) Encode content
Invoke 'mp4encode' with the name of the raw
AVI file to produce the encoded MP4 file.
The following parameters can be specified to
'mp4encode':
-w <uint> The input video frame width in pixels,
default value is 320
-h <uint> The input video frame height in pixels,
default value is 240
-r <uint> The video frame rate in frames per second,
default value is 24
-V <uint> The desired video bitrate in Kbps, default
value is 500
-A <uint> The desired audio bitrate in Kbps, default
value is 96
-a <float> The desired aspect ratio, default value is
1.33 (4:3). Typically letterbox is 2.35.
-I Use the ISO MPEG-4 video encoder
instead of the Xvid encoder
-M Use the MP3 audio encoder instead of
the AAC encoder
-R The input video is RGB24, convert to
YUV12 before encoding.
-d Debug mode, leave intermediate
files.
Examples:
mp4encode
mycontent.avi (results are written to mycontent.mp4)
mp4encode
-w 640 -h 480 -r 30 -I -R -V 1000 -M -A 128 mycontent.avi mycontent_mpeg4_1000_mp3_128.mp4
3) Make content available
Copy the MP4 file to a directory under the
configured media root for your streaming server. See the documentation for your
server as to how to generate a URL for the file, but typically it would look
like rtsp://myserver/mycontent.mp4
Example:
cp mycontent.mp4
/usr/local/movies
The Detailed Process
1) Acquire raw audio and/or video
The details here are varied. But generally
speaking, you use a capture program to record audio and video from either a
camera or a capture board into one or two files on disk.
The audio format should be PCM raw audio, 16
bits/sample, little-endian, 2 channels, 44100 samples/sec.
The video format should be YUV12, aka YV12.
(FYI: This is a planar format sampled at 4:2:0). Any frame size and frame rate
are acceptable. If your capture program doesn't support this format, capture in
RGB24 (packed format) which every capture program should support. MPEG4IP has a
utility to convert from RGB24 to YUV12.
If you use a Windows system for the media
acquisition, you frequently will have your data stored in an AVI file. If that
is the case, the avi2raw utility is provided to extract either the audio or
video tracks from an AVI file, and write the raw track data to a file of your
choice.
Examples:
avi2raw -a
mymedia.avi myaudio.pcm
avi2raw -v
mymedia.avi myvideo.yuv
avi2raw -v
mymedia.avi myvideo.rgb
The avi2raw utility also has very basic
editing capabilities. You can specify a time to start the extraction in seconds
from the beginning of the file and a length in seconds. For example, to extract
10 seconds of video starting at 5 seconds from the beginning of the file:
avi2raw -s 5 -l 10
-v mymedia.avi myvideo.yuv
If you have captured the video in RGB24
format, you need to convert that to YUV12 before giving it to the video encoder.
To do that use the MPEG4IP utility, rgb2yuv. Note that the video image width
and height must be specified for rgb2yuv. For example:
rgb2yuv -w 320 -h
240 myvideo.rgb myvideo.yuv
2) Encode audio
There are two options for audio encoding:
MP3 and AAC.
2a) MP3
If you wish to use MP3, the provided lame
tool will generate the MP3 file.
The -b parameters are specifies the desired
bitrate in kbps, typically between 64 and 128.
The -h parameter specifies that high quality
output should be generated at the expense of slower encoding. It is recommended
since it does not significantly impact the encoding time in our experience.
If a raw PCM file is provided as the input,
then the -r and -x options must be used.
Examples:
lame -h -b 128
myaudio.wav
lame -h -b 96 -r -x
myaudio.pcm
2b) AAC
If you wish to use AAC, the provided faac
tool will generate the MPEG-4 AAC file.
Two parameters are required: the profile to
be used, typically "LOW" for low-complexity; the desired bitrate in kbps,
typically between 16 and 128.
If a raw PCM file is provided as the input,
then the -r option must be used.
Examples:
faac -pLOW -b128
myaudio.wav
faac -pLOW -b96 -r
myaudio.pcm
(output file is myaudio.aac)
ISSUE: currently the FAAC code is hard-coded
with respect to the parameters of the raw format, which match those described
in section 1. If you must use a different format, you should embedded the audio
input in a WAV file which faac will read to determine the correct configuration
parameters to use with your audio data.
3) Encode video
There are two options for video encoding:
ISO reference and Xvid. Both generate MPEG-4 video bitstreams. The Xvid encoder
produces a Simple Profile stream only. The ISO
encoder contains many of the video tools defined for MPEG-4, and hence
can produce many of the defined profiles. In terms of video quality and
encoding speed we have found the Xvid encoder to be vastly superior.
If you want to use the Xvid encoder, use the
provided xvidenc tool.
The following options should be used to
inform the encoder of the configuration parameters for the compressed video
bitstream.
-h <uint> --height <uint> Use the given number as the video frame height in pixels,
default value is 240
-w <uint> --width <uint> Use the given number as the video frame width in pixels,
default value is 320
-r <uint> --rate <uint> Use the given number as the video frame rate in frames
per second, default value is 30
-b <uint> --bitrate <uint> Use the given number as desired bitrate in Kbps, default
value is 500
-i <uint> --ifrequency <uint> Use the given number as the frequency of I
frames in frames, default value is 30, i.e. once a second at 30 fps
Example:
xvidenc -w 320 -h
240 -r 24 -b 500 -i 24 myvideo.yuv myvideo.xvid
If you want to use the ISO encoder, use the
provided mp4venc tool. This tool takes one parameter which is the name of a
file where the many configuration parameters are given. An template parameter
file, 'mp4venc_template.par', is installed into the /usr/local/share directory.
Example:
mp4venc myvideo.par
4) Create an audio only mp4 file
Use the provided mp4creator tool to generate
an MP4 file from the MP3 or AAC encoded file. There are two required parameters
the first is the input file name, the second is the output file name. The -H
option instructs mp4creator to add a hint track needed by the Darwin Streaming
Server.
Examples:
mp4creator -c
myaudio.mp3 -H myaudio.mp4
mp4creator -c
myaudio.aac -H myaudio.mp4
5) Create a video only mp4 file
Use the provided mp4creator tool to generate
an MP4 file from the MPEG-4 Video encoded file. There are three required
parameters the first is the input file name, the second is the video frame
rate, the third is the output file name. The -H option instructs mp4creator to
add a hint track needed by the Darwin Streaming Server.
Examples:
mp4creator -c
myvideo.xvid -H -r=29.97 myvideo.mp4
mp4creator -c
myvideo.cmp -H -r=25 myvideo.mp4
6) Create an audio and video mp4 file
Use the provided mp4creator tool to first
generate an MP4 file for one of the media. Then use the mp4creator tool to add
the second media. The resulting MP4 file will contain both media tracks and any
associated hint tracks.
Example:
mp4creator -c
myaudio.aac -H mymedia.mp4
mp4creator -c
myvideo.xvid -r=15 -H mymedia.mp4
7) Useful options
-mtu=<uint> Use the given number as the MTU
size for hinting, the default value is 1500 bytes
-verbosity=<uint> Emits increasing levels about what is
happening to stdout
8) Make content available
Copy the MP4 file to a directory under the
configured media root for your streaming server. See the documentation for your
server as to how to generate a URL for the file, but typically it would look
like rtsp://myserver/mymedia.mp4
Example:
cp mymedia.mp4
/usr/local/movies