참고. DPG 파일 포맷
원문 : http://kkamagui.springnote.com/pages/492957
들어가기 전에...
- 이 글은 kkamagui에 의해 작성된 글입니다.
- 마음껏 인용하시거나 사용하셔도 됩니다. 단 출처(http://kkamagui.tistory.com, http://kkamagui.springnote.com)는 밝혀 주십시오.
- 기타 사항은 mint64os at gmail.com 이나 http://kkamagui.tistory.com으로 보내주시면 반영하겠습니다.
- OS 제작에 대한 상세한 내용은 책 "64비트 멀티코어 OS 구조와 원리"를 참고하기 바랍니다.
0.시작하면서...
문쉘(MoonShell)의 동영상 포맷인 DPG에 대해서 알아보자.
1.파일 포맷(File Format)
아래는 Wikipedia에 등록된 내용이다.
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
- Two bytes for the frames per second that the video runs
- 00 00
- Four bytes for the audio sample rate
- 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 64k -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:192This 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.mpgOr, in more recent versions of mencoder you can just add the following option:
-of rawvideoThis makes MEncoder output raw video with no need to extract it later with ffmpeg.
2.DPG 파일 생성 소스
- #include "stdio.h"
#include "stdlib.h" - void putint(unsigned int i, FILE* outfile) {
fputc(i & 0xff, outfile);
i >>= 8;
fputc(i & 0xff, outfile);
i >>= 8;
fputc(i & 0xff, outfile);
i >>= 8;
fputc(i & 0xff, outfile);
} - int main(int argc, char* argv[]) {
int frames;
int fps;
int samplerate;
int audiosize;
int videosize;
//char* filename = "header",0;
FILE* outfile;
if (argc != 7) {
printf("usage: headermaker <frames> <fps> <samplerate> <audiosize> <videosize> <filename>\n");
return -1;
}
// read our parameters
frames = atoi(argv[1]);
fps = atoi(argv[2]);
samplerate = atoi(argv[3]);
audiosize = atoi(argv[4]);
videosize = atoi(argv[5]);
outfile = fopen(argv[6], "wb");
// magic number:
fputc(0x44, outfile);
fputc(0x50, outfile);
fputc(0x47, outfile);
fputc(0x30, outfile);
// frames
putint(frames, outfile);
// fps
fputc(0x00, outfile);
fputc(fps%256, outfile);
fputc(0x00, outfile);
fputc(0x00, outfile);
// samplerate
putint(samplerate, outfile);
// channels
putint(0, outfile);
// begin and size audio
putint(36, outfile);
putint(audiosize, outfile);
// begin and size video
putint(36+audiosize, outfile);
putint(videosize, outfile);
fclose(outfile);
return 0;
}
3.마치면서...
아주 간단한 파일 포맷이다. 시간나면 인코딩 라이브러리를 이용해서 직접 생성해봐야겠다.
이 글은 스프링노트에서 작성되었습니다.
'NDS 홈브루(Homebrew) > 홈브루 Tutorial' 카테고리의 다른 글
참고. Software Reset 방법 (0) | 2007.11.14 |
---|---|
참고. NDS 속도에 대한 몇가지 테스트 (0) | 2007.11.14 |
참고. ARM 어셈블리(Assembly) (0) | 2007.11.14 |
참고. ARM Processor Overview (0) | 2007.11.14 |
26 윈도우 라이브러리(Window Library) 사용을 위한 프로젝트(Project) 만들기 (0) | 2007.11.14 |