Use of the MPEG4IP Server Side Tools

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 Linux system, the easiest method is to use mp4live. Hook your inputs to your capture card, set your audio and video settings (remember to use AAC to create ISMA-compatible content), and start.

If you are using a UNIX system, the next 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. Note that the mp4encode script might be outdated.y

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 byte order.

    You can choose the number of channels and sampling frequency (mp4encode assumes 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 an AVI file on disk.

    The audio format should be PCM raw audio, 16 bits/sample, little-endian byte order.

    You can choose the number of channels and sampling frequency (mp4encode assumes 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

    Note that if the avi file already contains encoded content, you can still use avi2raw to extract into elementary streams. For example:

    avi2raw -v mymedia.avi myvideo.xvid

  2. Encode audio

    For ISMA compliant audio, the popular choice is AAC encoding. mpeg4ip will also support MP3 Content.

    1. MP3

      If you wish to use MP3, download a mp3 encoding package such as LAME, and follow the directions.

      Examples:

      lame -h -b 128 myaudio.wav

      lame -h -b 96 -r -x -s 22050 -m m myaudio.pcm

    2. AAC

      If you wish to use AAC, download an AAC encoding package such as FAAC, and follow the directions.

      You will want to most likely encode as low-complexity.

      Examples (faac version 1.23.1):

      faac -o 0 -a128 myaudio.wav myaudio.aac

      faac -o 0 -a96 -P myaudio.pcm myaudio.aac

  3. Encode video

    For mpeg4ip, you will want to encode your video in mpeg4, simple or advanced simple profile. We include an older version of the xvid codec. We also recommend the released version of xvid, or ffmpeg. We also include the ISO encoder, but do not have the encoder linking on Linux. 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 ISO encoder, you will need to create an executable and use a file where the many configuration parameters are given. An template parameter file, 'mp4venc_template.par', is installed into the /usr/local/share directory.

  4. Adding audio to a 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 streaming server.

    Examples:

    mp4creator -c myaudio.mp3 -H myaudio.mp4

    mp4creator -c myaudio.aac -H myaudio.mp4

  5. Adding video to a 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

Valid HTML 4.01!