gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS Misc > Convert MoonShell Video with mp2 audio

#73675 - lobster - Mon Feb 27, 2006 10:29 am

I updated my MoonShell to 1.0 today and discovered that it now supports mp2 (the last time i updated was to 0.99 at the end of january XD) so after messing around with the included encoder and analyzing the header of the files it created i have come up with a modified method of making DPG files.

first of all, you need to generate your converted audio and video files.
this command will convert the video file "foo.avi" to mpeg1video encoded "foo.m1v"
Code:
mencoder foo.avi -of rawvideo -ofps 24 -sws 9 -vf scale=256:192:::3 -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=160 -o foo.m1v

this is essentially the same command as the one suggested by JaJa's method. the major difference is that i am using a lanczos resize (-sws 9) with filter length 3 (the :::3 after scale=256:192). this ensures that your converted video file will look alot cleaner than without it (mencoder defaults to a bicubic resize which is good but not the best).

next you need to convert the audio.
Code:
mencoder foo.avi -af resample=32000:1:2 -of rawaudio -oac lavc -ovc copy -lavcopts acodec=mp2:abitrate=160 -o foo.mp2

this command will extract and encode the audio from your video to a 160kbps 32000kHz mp2 file. the dpgenc program has only 32000kHz as a selectable sample rate but i think other rates will work as well. the maximum bitrate allowed by dpgenc is 160 you may be able to exceed this parameter as well.

almost done. you now need to make the header.
the header is the same up until audio channels. remember that all these values need to be 4 bytes long so if they're not, pad them with 0s. first is the obligatory DPG0 followed by the number of frames, frames per second, then audio sample rate. the new channels setting for mp2 audio is 0. the audio and video file information is changed a bit in the new header. it starts off the same with the start of the audio file then the size of the audio file (this used to be the end of the audio file), then the start of the video file (this is just 36+size of the audio file in decimals), finally you have the size of the video file.

if we were using the video used in JaJa's original post this is how the header would break down:
DPG0
the number of frames in your movie = 1000
the number of frames every second = 25
the sample rate of the audio = 41000
number of channels in the audio = 0
the start of the wav file = 36
the size of the audio file = 365100
the start of the video file = 365136
the size of the video file = 15007142

44 50 47 30 E8 03 00 00 00 19 00 00 44 AC 00 00 00 00 00 00 00 24 00 00 2C 92 05 00 50 92 05 00 A6 FD E4 00

here is my modification of the header maker written by juhees
Code:
#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 samples;
   int audiosize;
   int videosize;
   
   //char* filename = "header",0;
   FILE* outfile;
   
   if (argc != 7) {
      printf("usage: headermaker <#frames> <fps> <samples> <audiosize> <videosize> <filename>\n");
      return -1;
   }
   
   // read our parameters
   frames   = atoi(argv[1]);
   fps   = atoi(argv[2]);
   samples   = 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);
   
   // samples
   putint(samples, outfile);
   
   // channels
   putint(0, outfile);
   
   // begin and end audio
   putint(36, outfile);
   putint(audiosize, outfile);
   
   // begin and end video
   putint(36+audiosize, outfile);
   putint(videosize, outfile);
   
   fclose(outfile);
   
   return 0;
}

enjoy your fancy new dpg files with mp2 audio!

#73696 - Rudi Rastelli - Mon Feb 27, 2006 3:44 pm

How to edit the mencoder-commandline within DPGEnc to use lanczos resize ?

I'm not very common with that kind of commandline-stuff, so help is welcome...

Best Regards

Rudi