NDs-mPeG

From Wikipedia, the free encyclopedia

The correct title of this article is nDs-mPeG. The initial letter is shown capitalized due to technical restrictions.

nDs-mPeG, usually abbreviated DPG, is a special format of MPEG-1 video specifically for playback using the homebrew Moonshell program for the Nintendo DS. The video is encoded on a computer and then transferred, along with Moonshell, to the DS for playback.

Contents

[edit] Encoding

[edit] With GUI Programs

DPG files are usually created using the dpgtools program for Windows, but a newer program, BatchDPG[1], is a viable alternative. Encoding programs for platforms other than Windows do not exist, but the file format is simple enough to allow DPG files to be manually encoded and placed into the proper container format.

[edit] Without GUI Programs

There is a Python script ( theli.ho.com.ua/dpgconv/index.html ) which uses MEncoder and can be used on platforms where both Python and MPlayer are available.

Also, a program called EZBuilder by erspicu_brox can convert to DPG with FFmpeg.

[edit] File Format

[edit] General Outline

The DPG file specification is simple. All DPG files contain a 36 byte header, followed by audio, and then a standard mpeg-1 video stream. The audio format can differ; older DPG files used a special WAV format audio, but newer versions of moonshell have phased that out in favor of MP2 audio.

[edit] File Structure

The file begins with a 36 byte header (Note: all of the numbers below are hexadecimal.):

  • 44 50 47 30 (this stands for DPG0 in ASCII)
  • Four bytes for the number of frames in the video
  • 00 00 00 00
  • Two bytes for the frames per second that the video runs
  • 00 00
  • Four bytes for the audio sample rate
  • 00 00 00 00
  • 00 00 00 00 (this was the number of audio channels, now deprecated in favor of MP2 audio)
  • 24 00 00 00 (this is the start of the audio file, i.e. right after the header)
  • Four bytes for the length, in bytes, of the audio
  • Four bytes for the above length + 36 bytes (i.e. the start of the video file)
  • Four bytes for the length, in bytes, of the video

(A C program and source is included in the BatchDPG source code to simplify the header generation)

After a header has been made, concatenate everything together:

  • Linux & Mac (OS X Terminal): cat header.head audio.mp2 video.raw.mpg > ndsmpeg.dpg
  • Windows: copy /b header.head + audio.mp2 + video.raw.mpg ndsmpeg.dpg

[edit] Audio Encoding

The audio is encoded in standard MP2 format. For example, using ffmpeg to encode in.avi into out.mp2 at a 22050 sample rate and a bitrate of 64 kb/s:

 ffmpeg -i in.avi -vn -ab 64 -ar 22050 out.mp2

[edit] Video Encoding

MoonShell can be very particular about the types of MPEG video it will decode correctly. Videos made with ffmpeg do not work very well; MEncoder seems to be a better option. The FPS and bitrate rely on personal preference, but the DS does not have much processing power - lower bitrates and framerates seem to work better. Finally, since the DS screen is so small, rescaling to 256 by 192 is the most space-efficient.

Here is an example command using MEncoder (this should be on one line):

 mencoder in.avi -o out.mpg -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vrc_buf_size=327:vrc_maxrate=512:vbitrate=256:vstrict=-1 -ofps 18 -vf scale=256:192

This produces an AVI with a working MPEG video stream, but it should be extracted into a raw format with ffmpeg, however, this is not required:

 ffmpeg -i out.mpg -an -vcodec copy -f mpeg1video out.raw.mpg

Or, in more recent versions of mencoder you can just add the following option:

 -of rawvideo

This makes MEncoder output raw video with no need to extract it later with ffmpeg.

[edit] External Links

Convert Moonshell Video under Linux (GBADev forums)

[edit] References