FindPage
View Source:
DPG
Note:
You are viewing an old version of this page.
View the current version.
DPG is a simple container format for mpeg video and audio.<br> The header is big endian, and the data is just a concatenation of raw mpeg video and either mpeg audio or GSM audio. <verbatim> The DPG format is a video and audio container used by the popular Moonshell homebrew program on the Nintendo DS. There are currently (December 2006) three versions of the DPG format, identified by the initial four bytes of in the DPG file, namely DPG0, DPG1 and DPG2. [DPG file structure] Each DPG file consists of three (DPG0,DPG1) or four (DPG2) sections: a header, the audio stream, the video stream and for the DPG2 format an additional GOP (Group Of Pictures) list used for seeking during playback. All these sections are concatenated in the above mentioned order when creating the DPG file. [Header] The first section of the DPG file is the header with the following fields: (all fields are read by Moonshell 1.5 as a 32 bit unsigned number) Offset Description 0 DPG[012] Identifier. One of the strings: DPG0 (0x30475044), DPG1 (0x31475044) or DPG2 (0x32475044). 4 DPG[012] Number of frames in video. 8 DPG[012] Frames per second (FPS). Fixed point 8.8 format, i.e. 25 fps is multiplied by 100h (FPS<<8) to 6400. 12 DPG[012] Sampling rate of audio data (e.g. 32000) 16 DPG[012] Number of audio channels. If MP2 audio, this is zero. 20 DPG[012] Offset in file to audio stream 24 DPG[012] Size of audio stream. 28 DPG[012] Offset in file to video stream 32 DPG[012] Size of video stream. 36 DPG[1] Pixel format type 36 DPG[2] Offset in file to GOP list. 40 DPG[2] Size of GOP list. 44 DPG[2] Pixel format type Note: dpgtools 1.2 reads all values except the identifier as a signed 32 bit value. Moonshell 1.5, on the other hand, reads them as unsigned 32 bit values. This should not pose any problem, at least not until we reach 2GB files. [Pixel Formats] DPG0 only supports the RGB24 pixel format. DPG1 and DPG2 know the following pixel formats, Type Description 0 RGB15 1 RGB18 2 RGB21 3 RGB24 [GOP List] The Group Of Pictures (GOP) list of a DPG2 file is the last section of a DPG file. It consists of an array of a "FrameIndex" and "Offset" pair, both are read as an unsigned 32 bit value from within Moonshell. The use of the GOP list, within Moonshell 1.5, is when requesting a jump to a certain frame. In the case when a GOP list exists, it is searched in order to find the frame within the GOP list lower than or equal to the requested frame. (The search in Moonshell requires the GOP list to be ordered. Also a trivial optimization was omitted, namely to break out of the search loop once the GOP frame number is larger than the requested one.) So, to get clean seeks, I would put I-frames from the MPEG stream in the GOP list. [Audio Format] The audio format can be one of two types: GSM or MP2. The type used in a DPG file is distinguished by the number of audio channels. If audio channels is zero, an MP2 stream is assumed, otherwise the audio is GSM. </verbatim> Some useful commands: Audio conversion doesn't seem to work correctly in mencoder, so I used sox and twolame. <verbatim> mplayer -ao pcm:fast -vo null file.avi # extract the audio sox audiodump.wav -r 32000 out.wav # Transform it into 32kHz, to save some space twolame -b 128 out.wav out.mp2 # Create an Mpeg-1 Layer-II file </verbatim> dpgconv calculates the video stuff and transcodes it sufficiently well. Patch the header file, and concatenate the results together. mplayer -aid 0 source.mkv -endpos 1:35 -vo null -ao pcm:fast sox audiodump.wav -r 32000 audio.wav twolame -b 128 audio.wav audio.mp2 mencoder source.mkv -endpos 1:35 -v -ofps 16 -sws 9 -vf format=rgb24,scale=256:146:::3 -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:cmp=6:subcmp=6:precmp=6:dia=3:predia=3:last_pred=3:vbitrate=256 -o video.mpg -of rawvideo