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 under Linux

#64817 - JaJa - Tue Dec 27, 2005 1:55 am

Ok then. I have finished a method for creating .dpg files on linux (and so mac os x) and worked out the header as well.

This way is long winded. Juhees is working on a utility to generate a header and a shell script to perform the conversion.

Method
You will need Mplayer, mencoder, sox, cat and a hex editor.
The first step is to create a plain mpg1 video file. I did this using :

Code: Select all

mencoder foo.avi  -o foo.mpg -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=160000 -nosound -ofps 25 -vf scale=256:192

This creates an mpeg1 (named foo.mpg) file with a bitrate of 160000 bps and resolution of 256 x 192 (a little high for the DS i think).
Now we create a pcm (wav) file from the avi.

Code: Select all

mplayer foo.avi -dumpaudio -dumpfile output.dmp
mplayer output.dmp -ao pcm:file=output.wav
This wav will have the same sample rate and bitrate of the original file.
Now we convert the wav into the format expected by moonshell (WAV or wav49 or WAV GSM 6.01 call it what you want). I did this by

Code: Select all

sox output.wav -r 44100 -g -c 1 output.gsm.wav
Replace 44100 with the sample rate of your audio file.
You can check this is the correct format by running

Code: Select all

mplayer output.gsm.wav
The codec should read "Selected audio codec: [msgsm] afm:msgsm (MS GSM)" if correct.
Now create a file which is 36 bytes long. This forms you header, which i'll talk about in a minute. Now to create you movie file you do

Code: Select all

cat 36byteheader output.gsm.wav foo.mpg > my.dpg
The header
Without this the file won't play. It tells moonshell where the sound starts and ends and where the video starts and ends.
The first 4 bytes in the header are DPG0 (44 50 47 30). This is the same in all .dpg files. The next two bytes tell moonshell the number of frames in your movie. Then there are two spacing bytes (00 00). The next two bytes tells moonshell
(fps). The next two are again spacing bytes (00 00). So the first 12 bytes are something like 44 50 47 30 e8 03 00 00 00 19 00 00. In this example the video has 1000 frames and is played at 25 fps.
The next bytes tell moonshell about the audio in the file. The 13th and 14 bytes of the header (44 ac) tell moonshell the sample rate of the audio. Then there are two spacing bytes (00 00). The next two bytes tell moonshell the number of channels in the audio. In this example (and i think always because of the format) there is only one channel. There are again two spacing bytes (00 00). So 44 ac 00 00 01 00 00 00. This example is 44100 sample rate and one channel. The next bytes tell moonshell the start and end of the audio and video. The 21st and 22nd byte tell moonshell the start of the wav file. This is always 36 bytes into the file (24 00). There are another pair of spaces (00 00). These are followed by 4 bytes that tell the end byte of the audio file. This is the length of the audio file + 36. The next 4 bytes are the start of the video file. This is the end of the audio file + 36 (i think there's a header there). The last 4 bytes in the header are the end of the video file. This is the filesize (or the start of the video + the number of bytes in the video). So the last bytes in the header are something like 24 00 00 00 50 92 05 00 74 92 05 00 1a 90 ea 00

My example complete header reads:
44 50 47 30 e8 03 00 00 00 19 00 00 44 ac 00 00 01 00 00 00 24 00 00 00 50 92 05 00 74 92 05 00 1a 90 ea 00

To sumise the header:
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 = 1
the start of the wav file = 36
the end byte of the audio file = 365136
the start of the video file = 365172
end of the video file = 15372314

44 50 47 30 e8 03 00 00 00 19 00 00 44 ac 00 00 01 00 00 00 24 00 00 00 50 92 05 00 74 92 05 00 1a 90 ea 00

Tip: To find the number of bytes in your files use ls -la in the directory. You would be looking for the number of bytes on foo.mpg and output.gsm.wav in this example.

#64827 - juhees - Tue Dec 27, 2005 4:23 am

JaJa wrote: This way is long winded. Juhees is working on a utility to generate a header and a shell script to perform the conversion.
And here it is! Writen at 4AM in the morning, so don't expact a miracle ;-)
It's far from being perfect, but it's faster than messing around with a hexeditor.

First thing is a little program to produce the header:

Code: Select all

#include <stdio.h>

void putint&#40;int i, FILE* outfile&#41; &#123;
	fputc&#40;i%256, outfile&#41;;
	i /= 256;
	fputc&#40;i%256, outfile&#41;;
	i /= 256;
	fputc&#40;i%256, outfile&#41;;
	i /= 256;
	fputc&#40;i%256, outfile&#41;;
&#125;

int main&#40;int argc, char* argv&#91;&#93;&#41; &#123;
	int frames;
	int fps;
	int samples;
	int audiosize;
	int videosize;
	
	//char* filename = "header",0;
	FILE* outfile;
	
	if &#40;argc != 7&#41; &#123;
		printf&#40;"usage&#58; headermaker <#frames> <fps> <samples> <audiosize> <videosize> <filename>\n"&#41;;
		return -1;
	&#125;
	
	// read our parameters
	frames	= atoi&#40;argv&#91;1&#93;&#41;;
	fps	= atoi&#40;argv&#91;2&#93;&#41;;
	samples	= atoi&#40;argv&#91;3&#93;&#41;;
	audiosize = atoi&#40;argv&#91;4&#93;&#41;;
	videosize = atoi&#40;argv&#91;5&#93;&#41;;
	
	outfile = fopen&#40;argv&#91;6&#93;, "wb"&#41;;
	
	// magic number&#58;
	fputc&#40;0x44, outfile&#41;;
	fputc&#40;0x50, outfile&#41;;
	fputc&#40;0x47, outfile&#41;;
	fputc&#40;0x30, outfile&#41;;
	
	// #frames
	putint&#40;frames, outfile&#41;;
	
	// fps
	fputc&#40;0x00, outfile&#41;;
	fputc&#40;fps%256, outfile&#41;;
	
	fputc&#40;0x00, outfile&#41;;
	fputc&#40;0x00, outfile&#41;;
	
	// samples
	putint&#40;samples, outfile&#41;;
	
	// channels
	putint&#40;1, outfile&#41;;
	
	// begin and end audio
	putint&#40;36, outfile&#41;;
	putint&#40;36+audiosize, outfile&#41;;
	
	// begin and end video
	putint&#40;36+36+audiosize, outfile&#41;;
	putint&#40;36+audiosize+videosize, outfile&#41;;
	
	fclose&#40;outfile&#41;;
	
	return 0;
&#125;
Secound is a script, that works for me, but i don't like it, some spots are not robust enought :-(

Code: Select all

#!/bin/bash

if &#91; $# -eq 3 &#93;; then
  IF=$1
  OF=$2
  FPS=$3
  VTMP=temporary_video.mpg
  DMP=temporary_audio.dmp
  ATMP=temporary_audio.wav
  GSM=temporary.gsm.wav
  TMP=temporary.text
  HEADERTMP=temporary.head
  SAMPLES=44100
else
  echo "usage&#58; "
  echo "mpg2dpg <inputfile> <outputfile> <fps>"
  exit 1;
fi

mencoder $IF -o $VTMP -ovc lavc -lavcopts vcodec=mpeg1video&#58;vbitrate=160000 -nosound -ofps $FPS -vf scale=256&#58;192 2> $TMP &&

# this doesn't work for me &#58;-&#40;
#mplayer $IF -dumpaudio -dumpfile $DMP
#mplayer $DMP -ao pcm&#58;file=$ATMP

# this is why i use&#58;

ATMP=audiodump.wav
mplayer $IF -ao pcm&#58;file=$ATMP &&
sox $ATMP -r $SAMPLES -g -c 1 $GSM

AUDIOSIZE=`wc -c $GSM | cut -d " " -f 1`
VIDEOSIZE=`wc -c $VTMP | cut -d " " -f 1`

# this is so ugly...
NUM_FRAMES=`cat $TMP | grep frames | grep -v Flushing | cut -d " " -f 17`
headermaker $NUM_FRAMES $FPS $SAMPLES $AUDIOSIZE $VIDEOSIZE $HEADERTMP
cat $HEADERTMP $GSM $VTMP > $OF

rm $VTMP $TMP $DMP $ATMP $GSM $HEADERTMP
I had problems with framerates other that 25 (at encoding), but it's too late see whats wrong ;-)
As you can see, i had to go an other way to produce the wav, but it works. Hope it helps,

juhees

#64828 - norvan - Tue Dec 27, 2005 5:09 am

nicely done.

#64829 - tepples - Tue Dec 27, 2005 5:23 am

juhees wrote:First thing is a little program to produce the header:

Code: Select all

void putint&#40;int i, FILE* outfile&#41; &#123;
	fputc&#40;i%256, outfile&#41;;
	i /= 256;
	fputc&#40;i%256, outfile&#41;;
	i /= 256;
	fputc&#40;i%256, outfile&#41;;
	i /= 256;
	fputc&#40;i%256, outfile&#41;;
&#125;
The following may be faster and more reliable, especially with 2's complement negative numbers:

Code: Select all

void putint&#40;unsigned int i, FILE* outfile&#41; &#123;
	fputc&#40;i & 0xff, outfile&#41;;
	i >>= 8;
	fputc&#40;i & 0xff, outfile&#41;;
	i >>= 8;
	fputc&#40;i & 0xff, outfile&#41;;
	i >>= 8;
	fputc&#40;i & 0xff, outfile&#41;;
&#125;
Secound is a script, that works for me, but i don't like it, some spots are not robust enought :-(

Code: Select all

SAMPLES=44100
Does the sample rate have to be 44100? I'd guess that 32000 might work better on the DS hardware.

#64832 - brian33x51 - Tue Dec 27, 2005 7:28 am

Thanks a ton for all the work. I probably would have written everything in ruby if I had my choice but I didn't do the work.

Thanks to you all and thanks to moonshell. I'll test this tomorrow.

#64840 - JaJa - Tue Dec 27, 2005 10:32 am

Code: Select all

SAMPLES=44100
Does the sample rate have to be 44100? I'd guess that 32000 might work better on the DS hardware.
The moonshell samples use 48000.
It's only 44100 here because that was the sample rate on my test file and i suppose Juhees has copied it.

BTW Juhees, that was an awesome piece of coding for a couple of hours worth of work. It need a few changes for me (just #include at the beginning) but otherwise works great.

#64846 - juhees - Tue Dec 27, 2005 1:46 pm

Secound is a script, that works for me, but i don't like it, some spots are not robust enought :-(

Code: Select all

SAMPLES=44100
Does the sample rate have to be 44100? I'd guess that 32000 might work better on the DS hardware.[/quote]

I have only have testet it so far with that sample rate, i don't know, which rate will be the best...

juhees

#64850 - JaJa - Tue Dec 27, 2005 3:58 pm

Bit of expirimentation today shows that 22050 is best for DS speakers with 41000 for headphones.

sox output.wav -r 22050 -g -c 1 output.gsm.wav for speakers
sox output.wav -r 41000 -g -c 1 output.gsm.wav for headphones.

#64855 - brian33x51 - Tue Dec 27, 2005 6:18 pm

Update:

integrated the c code and shell script together in a ruby script.

Currently defaults to 22050Hz mono.

And a link to the ruby script

http://traeak.dyndns.org/~bolsen/mpg2dpg.rb.txt

And a sample encoded file:
http://traeak.dyndns.org/~bolsen/fire_e ... no_ken.dpg
880k

Original:
MPEG1 320x240 29.970 fps
MPEG3 48000 Hz, 2 ch, s16le, 192.0 kbit

http://traeak.dyndns.org/~bolsen/fire_e ... no_ken.mpg
9.4M

One thing that bothers me aobut the header encode is that the "fps" portion i had to encode as a big endian uint16 followed by 2 null bytes. Everything else I was able to encode as little endian uint32.

The current version of the script uses mencode for mpeg1 conversion, ffmpeg for audio extraction and sox for gsm conversion.

Not pretty.

The fire emblem demo encodes pretty well actually. I tried to encode a music video and well, that stuttered very badly.

It seems that both ffmpeg & meconder can only encode at "standard" mpeg1 rates.

UPDATE: just found the flag that allows arbitrary fps. Works great.

ffmpeg video output has tons of block artifacts at any fps or bitrate.

#64909 - juhees - Wed Dec 28, 2005 1:18 pm

brian33x51 wrote:Update:

integrated the c code and shell script together in a ruby script.

Currently defaults to 22050Hz mono.
I'm going to install ruby to test it, but from a short look at your source, i'd say it's a better solution than my script.
brian33x51 wrote:UPDATE: just found the flag that allows arbitrary fps. Works great.

ffmpeg video output has tons of block artifacts at any fps or bitrate.
For the one, who don't have ruby and are using still my version: you have to call mencoder with

Code: Select all

mencoder $IF -o $VTMP -ovc lavc -lavcopts vcodec=mpeg1video&#58;vstrict=-1&#58;vbitrate=160000 -nosound -ofps $FPS -vf scale=256&#58;192
instead of

Code: Select all

mencoder $IF -o $VTMP -ovc lavc -lavcopts vcodec=mpeg1video&#58;vbitrate=160000 -nosound -ofps $FPS -vf s
cale=256&#58;192
nice work,
juhees

UPDATE: Well, the audio was only noise :-( I had to grep the audio with mplayer again and then change the sox options to resample the audio, but not it works :-)

Code: Select all

	# extract audio as wav
	
	#audioArgs = &#91; "ffmpeg", "-y",
	#		"-i", infilename,
	#		"-vn",
	#		"-ar", ASAMPLES, 
	#		"-ac", ACHANNELS,
	#		ATMP &#93;

	tmp = "-ao pcm&#58;file="+ATMP
	audioArgs = &#91; "mplayer", infilename, tmp &#93;
	
	if ! Kernel.system&#40;audioArgs.join&#40;" "&#41;&#41;
		$stderr.puts "Error extracting audio"
		exit 1
	end

	# convert audio to gsm
	soxArgs = &#91; "sox", ATMP, "-r", ASAMPLES, "-g -c 1", GTMP &#93;
	if ! Kernel.system&#40;soxArgs.join&#40;" "&#41;&#41;
		$stderr.puts "Error converting audio to gsm"
		exit 1
	end
greetings
juhees

#64924 - brian33x51 - Wed Dec 28, 2005 4:01 pm

juhees wrote:
For the one, who don't have ruby and are using still my version: you have to call mencoder with

Code: Select all

mencoder $IF -o $VTMP -ovc lavc -lavcopts vcodec=mpeg1video&#58;vstrict=-1&#58;vbitrate=160000 -nosound -ofps $FPS -vf scale=256&#58;192
instead of

Code: Select all

mencoder $IF -o $VTMP -ovc lavc -lavcopts vcodec=mpeg1video&#58;vbitrate=160000 -nosound -ofps $FPS -vf s
cale=256&#58;192
nice work,
juhees

UPDATE: Well, the audio was only noise :-( I had to grep the audio with mplayer again and then change the sox options to resample the audio, but not it works :-)

Code: Select all

	# extract audio as wav
	
	#audioArgs = &#91; "ffmpeg", "-y",
	#		"-i", infilename,
	#		"-vn",
	#		"-ar", ASAMPLES, 
	#		"-ac", ACHANNELS,
	#		ATMP &#93;

	tmp = "-ao pcm&#58;file="+ATMP
	audioArgs = &#91; "mplayer", infilename, tmp &#93;
	
	if ! Kernel.system&#40;audioArgs.join&#40;" "&#41;&#41;
		$stderr.puts "Error extracting audio"
		exit 1
	end

	# convert audio to gsm
	soxArgs = &#91; "sox", ATMP, "-r", ASAMPLES, "-g -c 1", GTMP &#93;
	if ! Kernel.system&#40;soxArgs.join&#40;" "&#41;&#41;
		$stderr.puts "Error converting audio to gsm"
		exit 1
	end
greetings
juhees
Unfortunately I'm unable to use mplayer to extract the audio still on my athlon64 machine. It just dumps tons of errors and crashes still.

Seem my card reader at home is flakey so I couldn't test on the DS last night. Will test that today. I'll start cleaning things up.

I'm on gentoo, both ~x86 and ~amd64 so I have the luxury of easily grabbing packages if need be (for testing other encoders). Why is it so hard to extract number of frames?

#64941 - JaJa - Wed Dec 28, 2005 7:54 pm

Heheheh.
For for some reason i prefer doing commands myself rather than using either your shell script (juhees) or the ruby script.
To get the number of frames i look at the final line of mencoder.

Also mplayer sometimes has trouble working out the type of audio you have dumped. If you just get
playing output.dmp
in mplayer run the original file and look at what the audio format is.
Then change .dmp to the appropriate file type (e.g. output.ac3 or output.mp3)

#64961 - brian33x51 - Wed Dec 28, 2005 10:41 pm

JaJa wrote:Heheheh.
For for some reason i prefer doing commands myself rather than using either your shell script (juhees) or the ruby script.
To get the number of frames i look at the final line of mencoder.

Also mplayer sometimes has trouble working out the type of audio you have dumped. If you just get
playing output.dmp
in mplayer run the original file and look at what the audio format is.
Then change .dmp to the appropriate file type (e.g. output.ac3 or output.mp3)
ffmpeg's audio dumper is far more robust than mencoder's.

I'll grant you that the scripts aren't that great right now, but I figure the script actually documents what's being done. I may get off my duff and maybe even consider hacknig together some scripted gui to do this with a few basic selections.

If someone were to give you an mpeg1video and you didn't know the frames...well...

"mpeg_ps_info" from the mpeg4ip package gets you fps & number of seconds in the mpeg which can be used to compute the number of frames.

#65239 - LunarCrisis - Sun Jan 01, 2006 8:00 am

The problem with ffmpeg is that it won't play all the types of files mplayer can. In particular, it won't recognize .ogm files. I succeeded in using the ruby script by changing

Code: Select all

audioArgs = &#91; "ffmpeg", "-y",
			"-i", infilename,
			"-vn",
			"-ar", ASAMPLES, 
			"-ac", ACHANNELS,
			ATMP &#93;
to

Code: Select all

audioArgs = &#91; "mplayer", infilename, "-ao", 'pcm&#58;file="' + ATMP + '"' &#93;
Unfortunately in this case you have to put in the values for ASAMPLES and ACHANNELS which correspond to your video. (or should ACHANNELS always be 1?) (EDIT: looks like it should always be 1, since it appears that sox converts it to 1 channel anyways)

This also has the annoying side effect that mplayer opens and plays through the video silently and quickly while it's extracting the sound. The fact that it's decoding the video as well must be slowing it down, but I don't know a command line option to prevent this happening.

#65244 - JaJa - Sun Jan 01, 2006 11:57 am

To stop it "playing" the video:

Code: Select all

mplayer output.mp3 -ao pcm&#58;file=output.wav -vc dummy -vo null
although i think mplayer just ignore the video stream anyway.

And yes achannels is always one.
At least in the 3 sample dpg's i had to work with.
It might support stereo, but i'm unsure.

#65257 - brian33x51 - Sun Jan 01, 2006 4:35 pm

I've updated my script for the mplayer args and moved the audio rate, channels, video rate and size to variables at the top.

I also added in support for embedded spaces in the input and output file names. I have to yet play more with widescreen movies. I'm sure we'll need a config file or gui to handle all the options.

I personally still have ffmpeg for the audio extract. Every single time I use mplayer for this I get these messages in plenty and end up with an mplayer crash:

big_values too large! 95%
big_values too large!
big_values too large!
Blocktype == 0 and window-switching == 1 not allowed.
big_values too large!
mpg123: Can't rewind stream by 908 bits!
Blocktype == 0 and window-switching == 1 not allowed.
big_values too large! 93%
Blocktype == 0 and window-switching == 1 not allowed.
big_values too large! 93%
mpg123: Can't rewind stream by 801 bits!
big_values too large!
mpg123: Can't rewind stream by 2536 bits!
big_values too large!
mpg123: Can't rewind stream by 1737 bits!
big_values too large! 92%
mpg123: Can't rewind stream by 1071 bits!
big_values too large! 90%
Blocktype == 0 and window-switching == 1 not allowed.
.
.
.

#65308 - LunarCrisis - Sun Jan 01, 2006 11:54 pm

brian33x51 wrote:
I've updated my script for the mplayer args and moved the audio rate, channels, video rate and size to variables at the top.

I also added in support for embedded spaces in the input and output file names. I have to yet play more with widescreen movies. I'm sure we'll need a config file or gui to handle all the options.
It should be possible to get the audio rate directly from the source video somehow by looking at mplayer's output, though I don't know enough ruby to figure it out =(. I'm told that mplayer can resize automatically to within a certain size (256x192 in this case) while keeping the same aspect, and I'm told that it has something to do with the -vf dsize parameter, but I'm not quite sure how. But yeah, configurable size would be useful to use 192x144 and such =p. It would also be convenient to have a choice of subtitle (-sid #) and audio tracks (-aid #).

Quote:

I personally still have ffmpeg for the audio extract. Every single time I use mplayer for this I get these messages in plenty and end up with an mplayer crash:

big_values too large! 95%
big_values too large!
. . .
Does this happen with all videos or just some? Maybe you should try updating your version of mplayer.
_________________
If a tree falls in the forest and no one is there to hear it, why the heck do you care?

#65329 - brian33x51 - Mon Jan 02, 2006 2:02 am

LunarCrisis wrote:
Does this happen with all videos or just some? Maybe you should try updating your version of mplayer.


gentoo ~amd64

I reemerged mplayer this morning again just tomake sure.

Just tried something else and found out that the problem is directly related to the 64bit version of mplayer.

#65446 - LunarCrisis - Tue Jan 03, 2006 9:43 am

I'm not sure that this is new, but I just thought I'd share something I've observed about sound syncronization. I've found that sound synchronization can be improved by correcting the sound frequency to match the change in video frequency. The videos I were converting were in the standard 23.97 fps form (or 24000/1001 exactly), but when it's converted into a dpg the fps gets changed to 24. This doesn't seem like such a huge change, but over something like 20 minutes the sound can be a whole second out of sync. This can be corrected by multiplying the sound frequency by 1.001 ( 24/(24000/1001) ). If the sound still gets out of sync tapping left or right re-syncs it. =D
_________________
If a tree falls in the forest and no one is there to hear it, why the heck do you care?

#68842 - SeanMon - Fri Jan 27, 2006 1:28 am

I have been looking for this for a really long time!
_________________
null

#91472 - WereWolf - Fri Jul 07, 2006 11:51 am

I cannot play videos encoded with that instructions. The .dpg test movie that someone upload to that thread didn't run too. I suppose that something is bad. I don't know if you can play your old encoded videos with the new moonshell version, can you confirm that? Is it only my fault?

Sorry for my english! Thanku!

#91478 - JaJa - Fri Jul 07, 2006 12:37 pm

Whilst the header has remained the same I believe the latest moonshell uses a different audio codec.
You may need to enable support for old dpg files in the .ini file.
(I think that's an option anyway)
_________________
LAWL HOOGE
My Blog

#91480 - WereWolf - Fri Jul 07, 2006 1:10 pm

JaJa thx for your reply! Iep the error is the audio codec! yes!

I looked up a dpgenc windows encoded file, and extracted audio from it. It seems that audio is now encoded with mpg audio (mp2) i think.Someone can contrast it?

#91506 - WereWolf - Fri Jul 07, 2006 5:04 pm

After more testing I can play dpg files with the latest moonshell. Audio must to be encoded with mpeg audio (mp2), and the number of channels must to be 0 in the dpg header(?).

I have problems with videos encoded with ffmpeg, videos doesn't play ok with mooshell, some square blocks artifacts appears at the screen and video is not being decoded ok... With mencoder I have no problems... Do you know how to encode the video with ffmpeg?

#109707 - theli - Mon Nov 20, 2006 4:55 pm

i'm sorry for reviving such old thread.. but i have a question:
what should be the byte order of different header sections?

#109820 - theli - Tue Nov 21, 2006 2:00 pm

anyway ... if anyone is interested..
i've managed to create a python script which i use ofr encoding videos to DPG format on my linux box ...
is supports common set of options
and automatically embeds subtitle with matched filename
(can be turned off)
also font and subtitle encoding can be specified
and so on ....

the script can be found here:
http://theli.ho.com.ua/dpgconv/
any feedback appreciated ...

and i have one more question:
i experience a/v sync loss everytime i try to seek in dpg file ...
anyone know a possible reason of this?

#109853 - bugmenot! - Tue Nov 21, 2006 7:29 pm

theli, I just used your script to transcode a clip, and it worked flawlessly! Finally converting video on this platform is as easy as it is when using the Windows tools, if not actually easier, because it doesn't get much easier than typing in what file to convert!

I'll be using it a lot.

Edit: Got an error while converting from a Real Media file, but it's not like I've got more than one of them anyway.

Debug if you wish to do something about it:
Traceback (most recent call last):
File "dpgconv-0.1.py", line 195, in ?
conv_file(file)
File "dpgconv-0.1.py", line 159, in conv_file
write_header(frames)
File "dpgconv-0.1.py", line 140, in write_header
headerValues = [ "DPG0", int(frames), options.fps, 0, options.hz , 0 ]
ValueError: invalid literal for int():

#109881 - dude1 - Wed Nov 22, 2006 7:18 am

what is the most idiot proof way of encoding dpg's on osx

#109887 - theli - Wed Nov 22, 2006 9:58 am

i've figured out what was causing a/v sync loss on seeking and put a new version of script... now audio and video stay in sync on seeking :D
http://theli.ho.com.ua/dpgconv/

bugmenot! wrote:
Got an error while converting from a Real Media file

can you actually play that rm file in mplayer?

dude1 wrote:
what is the most idiot proof way of encoding dpg's on osx

i do not know of any tools for encoding on MACs but i'm sure my script can do this
(you'll need to install mplayer package too)

#109910 - oofrab - Wed Nov 22, 2006 6:41 pm

theli, nice little tool, was looking for something like this! Unfortunately, my mencoder does not seem to support the option "-of rawaudio" :( (Fedora Core 5)

Also, a suggestion would be to show some sort of progress output during the encoding process.

#109939 - theli - Thu Nov 23, 2006 8:38 am

oofrab wrote:
theli, nice little tool, was looking for something like this! Unfortunately, my mencoder does not seem to support the option "-of rawaudio" :( (Fedora Core 5)

what does running
mencoder -of help
outputs?
oofrab wrote:

Also, a suggestion would be to show some sort of progress output during the encoding process.

i'm thinking of it

#109941 - oofrab - Thu Nov 23, 2006 9:19 am

Ok, this was a half PICNIC error...

theli wrote:

what does running
mencoder -of help
outputs?


My version of mencoder was 1.0pre7, i.e., pretty old. This version does not support rawaudio
Code:

Available output formats:
   avi      - Microsoft Audio/Video Interleaved
   mpeg     - MPEG-1/2 system stream format
   rawvideo - (video only, one stream only) raw stream, no muxing


Somehow this was blocking yum (update manager in Fedora) resulting in me not having the latest version of mencoder. Manually deleteing the old version of mencoder and then installing the version 1.0pre8 (from the livna repository), I now have
Code:

Available output formats:
   avi      - Microsoft Audio/Video Interleaved
   mpeg     - MPEG-1/2 system stream format
   lavf     - FFmpeg libavformat muxers
   rawvideo - (video only, one stream only) raw stream, no muxing
   rawaudio - (audio only, one stream only) raw stream, no muxing


This should fix my problem! A suggestion, if you want to make the program a bit more user friendly(or idiot proof :) ), you could maybe check that rawaudio is an available output format.

#109944 - theli - Thu Nov 23, 2006 10:40 am

oofrab wrote:
This should fix my problem! A suggestion, if you want to make the program a bit more user friendly(or idiot proof :) ), you could maybe check that rawaudio is an available output format.

actually these are work-in-progress versions and i'll add errors checking next....

in the meantime you can get 0.3 version which outputs progress indication :)

#110040 - oofrab - Fri Nov 24, 2006 4:26 pm

Nice, now I see how far i have progressed...

I have some more suggestions, if you want. How about trapping the signal SIGINT so that when I press Ctrl-C dpgconv removes any temporary files?
For this, you need to import the module signal and set up the callback using "signal.signal(signal.SIGINT, cleanup_callback)" and define a function "def cleanup_callback(signal, frame):" removing the files. (Maybe also trap more signals, such as SIGTERM etc.)

#110041 - theli - Fri Nov 24, 2006 5:09 pm

oofrab wrote:
I have some more suggestions, if you want. How about trapping the signal SIGINT so that when I press Ctrl-C dpgconv removes any temporary files?
For this, you need to import the module signal and set up the callback using "signal.signal(signal.SIGINT, cleanup_callback)" and define a function "def cleanup_callback(signal, frame):" removing the files. (Maybe also trap more signals, such as SIGTERM etc.)

thanx!
(btw - it's actually my second python programming experience :) )

today i've noticed that total frames calculation is not good for any file .. this once again leads to a/v desync on seeking ...

well.. mencoder outputs bad, duplicated and skipped frames ...
transcoding one file today i've got that skipped frames number was lower than "bad frames"
and as i use
original_frames + duplicated_frames - skipped_frames
moonshell that created file has more frames than it actually has ...
but using
original_frames + duplicated_frames - bad_frames
fixed this ...
and now i'm confused how to calculate output file total frames :/
maybe just obtain ID_LENGTH from
mplayer -identify
output and multiply this with fps?
for example:
(now in my sciprt)
Original file total frames:61439
Skipped 18664 frames
Duplicated 0 frames
23001 bad frames
Output file total frames:38438

possible solution:
ID_LENGTH=2562.52
fps=15
2562.52*15=38437.80


what you think whould be better to use?

#112021 - theli - Tue Dec 12, 2006 2:54 pm

anyone knows about new dpg format used in moonshell 1.5 ?

#112051 - oofrab - Tue Dec 12, 2006 9:24 pm

theli wrote:
anyone knows about new dpg format used in moonshell 1.5 ?


I saw some info on DPG2 in the new BatchDPG thread: http://gbatmw.net/index.php?topic=2266

Is there no place, like a wiki, where one can put information like this? Stuff like the DPG1 format DPG2 format, different graphic formats specific to the DS etc.

#112105 - theli - Wed Dec 13, 2006 8:04 am

somthnig like that is here
http://en.wikipedia.org/wiki/NDs-mPeG

#112121 - oofrab - Wed Dec 13, 2006 1:11 pm

theli wrote:
somthnig like that is here
http://en.wikipedia.org/wiki/NDs-mPeG


Hmm, oki, not optimal since it is very hard to find other related info, but still I guess it's better than nothing.

So, shall we start documenting the DPG2 format there (I don't know if it even qualifies as a 'new' format).

#112129 - tepples - Wed Dec 13, 2006 3:06 pm

Format details don't belong in an encyclopedia.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#112138 - oofrab - Wed Dec 13, 2006 4:50 pm

So, what existent alternatives are there for format documentation?

#112139 - Lick - Wed Dec 13, 2006 4:55 pm

TXT documents. XD
_________________
http://licklick.wordpress.com

#112141 - oofrab - Wed Dec 13, 2006 5:08 pm

Well, from the posts above, it seems as if the best way to RE the 'new' DPG format is to start a thread and try to submit findings along the way. Then if we finally reach our goal of understanding the format we write it in a TXT file and send it floating around the internet! Hmm...

Somehow, this doesn't strike me as an effective strategy, although it is nice way of having it forgotten or 'lost'. In my opinion, a DS wiki with all kinds of information (yes, even formats) is a lot more effective.

#112144 - Firon - Wed Dec 13, 2006 5:53 pm

Maybe you can stick it onto the wiki of some piracy-related site?

#112150 - tepples - Wed Dec 13, 2006 7:07 pm

Firon wrote:
Maybe you can stick it onto the wiki of some piracy-related site?

Bad idea, when there exist non-pirate DS-oriented wikis.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#112330 - oofrab - Fri Dec 15, 2006 8:39 am

theli wrote:
anyone knows about new dpg format used in moonshell 1.5 ?


After a look at the source code to dpgtools (Moonshell sources), the new format seems to add a GOP ("Group Of Pictures" is a video encoding term) list to the DPG file. The header has increased by 8 bytes to 48 bytes in total. The changes to the header are that "pixel format" at offset 36 in the DPG1 file has moved to offset 44 and that, in the new DPG2 header, the two dwords at offset 36 and 40 contain the offset and the size of the GOP list in the DPG file.

The GOP list is appended at the end of the DPG file. I have not yet had time to check the format of the GOP list. It seems as if the GOP list has been added to enable seeking during playback.

The thing I do not understand is why the new header does not append the extra info about the offset and size of the GOP list at the end of the header. Instead the choice was made to move the offset of the "pixel format" field by 8 bytes and insert the GOP data before this field.

Also the header description of the DPG header in wikipedia (linked above) seems to be wrong. Way too many padding zeros, making the total size wrong.

#112331 - theli - Fri Dec 15, 2006 8:50 am

oofrab wrote:
Also the header description of the DPG header in wikipedia (linked above) seems to be wrong. Way too many padding zeros, making the total size wrong.

may be.. i haven't looked at it closely .. i was reffering to makeheader.c source from batchdpg when i was writing my python script :)

too bad i cannot test new format as moonshell doesn't work on G6 yet

#112371 - Firon - Fri Dec 15, 2006 8:00 pm

http://ls5.cydonianknight.com/index.php?download=BatchDPG_v1.3_alpha_A.rar

mpeg_stat is also available as a *nix program (BatchDPG is using it for the m1v parsing for the GOP list creation) http://bmrc.berkeley.edu/ftp/pub/multimedia/mpeg/stat/

Note that the DPG2s produced aren't technically valid: they go out of sync. The GOP list generation is correct (output was identical between this and dpgenc), as is the header creation, but something else is messed up.

I know BatchDPG is a Windows program, but you can examine it to figure out the GOP list structure. Also, 1.3a has an updated headermaker.c which supports DPG2.

#112605 - oofrab - Mon Dec 18, 2006 3:14 pm

Some info I gathered on the DPG[012] file format. Please comment if you find anything wrong.

Code:

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.

#112625 - Firon - Mon Dec 18, 2006 8:08 pm

http://ls5.cydonianknight.com/index.php?download=BatchDPG_v1.3_beta_3.exe
http://ls5.cydonianknight.com/index.php?download=BatchDPG_v1.3_beta_3_source.rar

DPG2 is now working properly.

oofrab: your description of the header is spot on.

#112937 - oofrab - Thu Dec 21, 2006 8:15 pm

Firon: Nice to see that BatchDPG works. Does the dpg still go out of sync?

But, I was still curious as to what was in the GOP list, so here comes some more info I have found:

Code:
The GOPList contains a frame number and offset within the video stream
(offset 0 is at beginning of the video stream). The question is what
within the video stream do we give the offset of. It turns out to be
the offset to the "sequence header code" and NOT the "group start
code" (identifies the GOP) or the "picture start code" (identifies a
frame). These start codes are unique and byte-aligned(!) within the
video stream.

The "sequence header code" is identified by the value 0x000001B3 (big
endian). So to find the offset to put in the, so called, GOP list,
search the video stream for a byte aligned value of 0x000001B3 and
these will be the offsets to write into the dpg file.

The GOP list also holds a frame index. This can be calculated by
counting how many frames (or pictures) have been seen in the video
stream up until the current "sequence header code". This means that
the first "sequence header code" has a frame index of zero. Pictures
(i.e. I-, P-, B-frames ...), can be identified by the "picture start
code", which is also unique. This code is 0x00000100 and also
byte-aligned.

#112963 - LS5 - Fri Dec 22, 2006 12:20 am

To generate the GOP list for BatchDPG, I used the above mentioned mpeg_stat and scanned its output using this piece of code:
Code:
$stats = FileOpen($temp & ".off", 0)
$gopList = FileOpen($temp & ".gop", 2)
$frames = 0
While 1
   $line = StringSplit(FileReadLine($stats), " ")
   If $line[0] < 2 Then ExitLoop
   If $line[1] = "picture" Then $frames += 1
   If $line[1] = "gop" Then
      FileWrite($gopList, BinaryString($frames))
      FileWrite($gopList, BinaryString(Number(String($line[2] / 8 - 140))))
   EndIf
WEnd
FileClose($stats)
FileClose($gopList)

Why substract 140? That's exactly the value that was needed to make the output equal to dpgenc's output. Thanks to your documentation I now know why this was necessary; I searched for the 'gop' lines when I actually had to search for 'sequence'. Thanks again.

#113008 - oofrab - Fri Dec 22, 2006 9:59 am

Glad that you could use the info!

Technically, you can have several GOPs within a sequence. I believe that the choice to use a sequence was done because GOPs can be "open", meaning they can reference data within other GOPs. This would make it difficult to jump to a certain GOP in the video stream if data was needed from a previous, skipped, GOP. This seems to be rarely the case, though, since in my two short examples, I only saw one GOP for each sequence.

Now if only this made it to a linux converter... (hehe)

#113288 - brian33x51 - Tue Dec 26, 2006 3:30 am

Sort of off topic...how do you guys install moonshell?
It's a damn shame it's a windows setup program. Under wine all I get is a black window.

Answered my own question: changing from winxp to win98 emulation made it work properly.

#113653 - theli - Fri Dec 29, 2006 1:42 pm

oofrab wrote:
Now if only this made it to a linux converter... (hehe)

as i have now moonshell 1.6b working on my G6 i'll implement this .. though adding another dependancy on mpeg_stat doesn't looks nice to me :(

#113654 - Firon - Fri Dec 29, 2006 2:08 pm

Well, mpeg_stat is also a *nix program, so at least you won't need to use wine to run it. :P The -offset option has the most useful information.

#113656 - theli - Fri Dec 29, 2006 2:30 pm

Firon wrote:
Well, mpeg_stat is also a *nix program, so at least you won't need to use wine to run it. :P The -offset option has the most useful information.

yeah .. actually now (as i already depend on it) i can use mpeg_stat for getting frame count ... and not using (original frames - bad frames) :)

#113705 - oofrab - Fri Dec 29, 2006 10:23 pm

theli wrote:
as i have now moonshell 1.6b working on my G6 i'll implement this .. though adding another dependancy on mpeg_stat doesn't looks nice to me :(


Well, as I see it you do not actually have to depend on mpeg_stat. All information needed to find the 'sequence' offset for the GOP list and also the offsets to the picture frames for the total number of frames was given in my previous post. Then again, searching the binary stream in your python script might make it a tad bit larger. (I also now assume that all frames in the stream are displayed, which I do not know for sure is the case in mpeg.)

#113755 - theli - Sat Dec 30, 2006 9:20 am

well ... anyway .. this is a version which depends on mpeg_stat ... and adds support for DPG1 and DPG2 ....

http://theli.ho.com.ua/dpgconv/
http://theli.ho.com.ua/dpgconv/dpgconv-0.4.py
Quote:
dpgconv 0.4
Added support for DPG1 and DPG2.
Pixel format setting for DPG1 and DPG2.
Now using mpeg_stat for calculating frame count and GOPs.
Cleanup on SIGINT and SIGTERM.

#115248 - relaxed - Sun Jan 14, 2007 4:17 am

You can get the frame count by running:

Code:
mencoder movie.mpg -oac copy -ovc copy -o /dev/null


This will output:

Code:
Video stream:  722.069 kbit/s  (90258 B/s)  size: 62518457 bytes  692.659 secs  20759 frames


20759 frames. Hope this helps.

#115293 - theli - Sun Jan 14, 2007 8:24 pm

i CAN get frame count postprocessing temporary raw mpeg stream with mencoder/mplayer ... the main reason for depending on mpeg_stat is GOPlist creating for DPG2.

#115295 - relaxed - Sun Jan 14, 2007 8:42 pm

@theli
Ahh, I see. Well the current solution works well.

I searched for some info on best encoding options for the ds and was wondering if you might know. I'm looking for high quality settings and I noticed your script in "-q" mode use a vbitrate of 256 where the windows program batchdpg does 384. Is there any reason to use a lower vbitrate? I'm aware you can change it but didn't know myabe you've found the sweet spot is 256.

Is there anyway to play dpg files with mplayer? All I get is audio and -identify doesn't list anything about mpeg1.

Thanks again for your time and the great transcoder. :)

--
relaxed

#115296 - theli - Sun Jan 14, 2007 9:10 pm

normal/low/high quality settings do not affect video or audio bitrate settings..
they affect other things .. dithering for example ...

there are aeparate settings for video/audio bitrate though:
Quote:
-v,--vbps xxx
sets video stream bps in kb/s(default: 256)
-a,--abps xxx
sets audio stream bps kb/s (default: 128)

#115879 - steveox28 - Fri Jan 19, 2007 10:30 pm

Say, I want to encode right from a DVD, will this work using a vob which was ripped as a source file?

#115880 - Firon - Fri Jan 19, 2007 10:36 pm

Assuming he's using mplayer/mencoder to handle things, yes, actually.

#115882 - theli - Fri Jan 19, 2007 10:40 pm

yes
you can also use transcoding from dvd
something like
dpgconv dvd://02
(for a particular (second here) chapter)

#116144 - steveox28 - Mon Jan 22, 2007 2:15 pm

I tried encoding an mpeg4 file and was able to do it with BatchDPG v1.2
http://utorrent.com/BatchDPG_v1.2.7z

However I needed DPG2 support so I installed BatchDPG v1.3 beta 3 in a different location. When it gets to encoding the video I get a message it couldn't find the proper codec.

I didn't change anything, I have the K-Lite Codec Pack 2.82 Full installed without any changes for the first one.

I have the same Video setting except the Resizer, which is new.

Any Idea what I am missing?

Thank you,

Steve

#116169 - steveox28 - Mon Jan 22, 2007 8:50 pm

Theli,

Using your python script I get the following.
Code:

dpgconv-0.4.py home/harry_potter_chamber_of_secrets-001.avi hp_chamber_secrets.avi
Converting home/harry_potter_chamber_of_secrets-001.avi
Transcoding video:   done
Transcoding audio:   done
Creating header
Creating harry_potter_chamber_of_secrets-001.dpg
Removing temporary files
Done converting "home/harry_potter_chamber_of_secrets-001.avi" to "harry_potter_chamber_of_secrets-001.dpg"
Converting hp_chamber_secrets.avi
Transcoding video:   done
Transcoding audio:   done
Traceback (most recent call last):
  File "/usr/local/bin/dpgconv-0.4.py", line 321, in ?
    conv_file(file)
  File "/usr/local/bin/dpgconv-0.4.py", line 273, in conv_file
    frames = mpeg_stat()
  File "/usr/local/bin/dpgconv-0.4.py", line 253, in mpeg_stat
    frames = m.group(1)
AttributeError: 'NoneType' object has no attribute 'group'


The resulting .dpg is about 420mb and when I play it in mplayer it says no video and plays the audio.

I tried playing with moonshell and my NDS just locks up.

I did download mpeg_stat and installed it in /usr/local/bin along with dpgconv-0.4.py

I have tried doing it straight from my dvd, as well as an mpeg4 file.

Thank you,

Steve

#116214 - theli - Tue Jan 23, 2007 6:23 am

as for mplayer ... it behaves in such way (playing only audio) with any dpg file...
as for lockup - are you using latest stable 1.6 moonshell?

#116268 - sinclair44 - Tue Jan 23, 2007 10:56 pm

I'm having a few sound issues... moonshell will play the video fine, but the sound is about 2x too fast and eventually it locks up after about 5 seconds. Encoding the audio myself with twolame works fine.

I'd much appreciate a twolame-audio option, or even a "here's the audio track, I encoded it myself external to the script, use it" option. Come to think of it, I could probably make the changes to the script myself and submit a patch to you or something.

In any case, the script is awesome if the audio would work!
_________________
Inter arma enim silent leges

#116284 - steveox28 - Wed Jan 24, 2007 2:40 am

theli wrote:
as for mplayer ... it behaves in such way (playing only audio) with any dpg file...
as for lockup - are you using latest stable 1.6 moonshell?


Yes, I am using the latest stable 1.6 moonshell. I have a regular DS an M3 Game Player 3rd and a passcard.

I have tried converting several types of movies but nothing plays. I am not even sure the moonshell is working properly as only the touch screen is on. Whereas the howto's I have seen and pictures show the top screen on as well.

#116297 - HyperHacker - Wed Jan 24, 2007 7:04 am

The top screen should be showing a file browser or if nothing else some debug text. You'd have to have edited the configuration to put the file browser on the bottom for that, so you'd probably know if that was the case.
_________________
I'm a PSP hacker now, but I still <3 DS.

#116307 - theli - Wed Jan 24, 2007 8:32 am

so, steveox28, i assume you have problems running moonshell itself ... and not with videos

#116330 - steveox28 - Wed Jan 24, 2007 1:30 pm

theli wrote:
so, steveox28, i assume you have problems running moonshell itself ... and not with videos


I am able to play mp3's with moonshell.

The top screen goes off when the passcard is booted. I get into moonshell by selecting extended from the menu. Is the ds supposed to boot into moonshell directly?

#116332 - theli - Wed Jan 24, 2007 1:54 pm

steveox28 wrote:
theli wrote:
so, steveox28, i assume you have problems running moonshell itself ... and not with videos


I am able to play mp3's with moonshell.

The top screen goes off when the passcard is booted. I get into moonshell by selecting extended from the menu. Is the ds supposed to boot into moonshell directly?

MultiMedia Extended built in some M3 and G6 flashcarts is not moonshell but their own clone ... it doesn't support dpg2 ...
you can try to convert video for it passing
--dpg 0
to the script
like
dpgconv.py --dpg 0 video.avi

#116346 - Firon - Wed Jan 24, 2007 5:59 pm

You have to install the real Moonshell and load the appropriate NDS. You cannot use "Extend".

#117574 - jjlawren - Mon Feb 05, 2007 9:59 pm

steveox28 wrote:
Theli,

Using your python script I get the following.
Code:

dpgconv-0.4.py home/harry_potter_chamber_of_secrets-001.avi hp_chamber_secrets.avi
Converting home/harry_potter_chamber_of_secrets-001.avi
Transcoding video:   done
Transcoding audio:   done
Creating header
Creating harry_potter_chamber_of_secrets-001.dpg
Removing temporary files
Done converting "home/harry_potter_chamber_of_secrets-001.avi" to "harry_potter_chamber_of_secrets-001.dpg"
Converting hp_chamber_secrets.avi
Transcoding video:   done
Transcoding audio:   done
Traceback (most recent call last):
  File "/usr/local/bin/dpgconv-0.4.py", line 321, in ?
    conv_file(file)
  File "/usr/local/bin/dpgconv-0.4.py", line 273, in conv_file
    frames = mpeg_stat()
  File "/usr/local/bin/dpgconv-0.4.py", line 253, in mpeg_stat
    frames = m.group(1)
AttributeError: 'NoneType' object has no attribute 'group'


The resulting .dpg is about 420mb and when I play it in mplayer it says no video and plays the audio.

I tried playing with moonshell and my NDS just locks up.

I did download mpeg_stat and installed it in /usr/local/bin along with dpgconv-0.4.py

I have tried doing it straight from my dvd, as well as an mpeg4 file.

Thank you,

Steve

Has anyone found a fix for this issue?

#117636 - theli - Tue Feb 06, 2007 5:57 am

what issue?

#117637 - mobad - Tue Feb 06, 2007 6:15 am

this error

Traceback (most recent call last):
File "/usr/local/bin/dpgconv-0.4.py", line 321, in ?
conv_file(file)
File "/usr/local/bin/dpgconv-0.4.py", line 273, in conv_file
frames = mpeg_stat()
File "/usr/local/bin/dpgconv-0.4.py", line 253, in mpeg_stat
frames = m.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

i have it too and i have mpeg_stat mencoder and mplayer installed
it worked before but now its not :/ at least for me
i doubt its a problem on your part just i have no idea hot to get it to work probably just a package install

UPDATE:
reinstalled mpeg_stat and mpeg_stat.1 in /usr/local/bin and /usr/bin and now
it seems to work!

#117647 - theli - Tue Feb 06, 2007 10:04 am

with such errors (when needed executables are not in path)
just edit this lines in script with full paths:

Code:
MENCODER="mencoder"
MPLAYER="mplayer"
MPEG_STAT="mpeg_stat"

#117674 - jjlawren - Tue Feb 06, 2007 2:53 pm

mobad wrote:
this error

Traceback (most recent call last):
File "/usr/local/bin/dpgconv-0.4.py", line 321, in ?
conv_file(file)
File "/usr/local/bin/dpgconv-0.4.py", line 273, in conv_file
frames = mpeg_stat()
File "/usr/local/bin/dpgconv-0.4.py", line 253, in mpeg_stat
frames = m.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

i have it too and i have mpeg_stat mencoder and mplayer installed
it worked before but now its not :/ at least for me
i doubt its a problem on your part just i have no idea hot to get it to work probably just a package install

UPDATE:
reinstalled mpeg_stat and mpeg_stat.1 in /usr/local/bin and /usr/bin and now
it seems to work!

Looks like my problem the whole time was that I read the instructions as "dpgconv.py <source> <destination>". Since the destination was always an empty file, everyone would complain.

#117677 - theli - Tue Feb 06, 2007 3:16 pm

hm .. i suppose i should check all needed tools' and files' existance ;)

#117683 - steveox28 - Tue Feb 06, 2007 4:56 pm

Firon wrote:
You have to install the real Moonshell and load the appropriate NDS. You cannot use "Extend".


I have been looking but can't seem to find how to do this. Do you have a link that might describe how to do this?

I followed the tutorial at http://www.m3wiki.com/index.php?title=TheStick's_MoonShell_Tutorial:_How_to_install%2C_customize%2C_use%2C_and_more

It doesn't say how you are supposed to launch Moonshell. Probably because it is supposed to be so obvious that I should know. For some reason I am missing this.

#117687 - Firon - Tue Feb 06, 2007 5:55 pm

Once it's installed properly, launch the NDS as you would for any other ROM.

#119617 - oofrab - Sat Feb 24, 2007 8:26 pm

Today, I had a problem with a video I created, containing duplicate frames. It seems as if though dpgconv-0.4.py produces dpgs which were completely out of sync.

My solution was to add the 'harddup' filter to the call to mencoder in dpgconv, to actually duplicate these frames and it seems to fix this problem,

mencoder ... -vf ...,harddup ...

#119628 - theli - Sat Feb 24, 2007 9:47 pm

hm ...i wonder... what was the fps of your input video and what fps settings you used for transcode?

#119630 - Firon - Sat Feb 24, 2007 10:09 pm

You shouldn't be setting the output FPS as higher than the source.

#119631 - theli - Sat Feb 24, 2007 10:11 pm

maybe i should add some warning when output fps set higher than input ...

#119632 - Firon - Sat Feb 24, 2007 10:43 pm

You actually should just not allow it. It's a waste.

#119720 - oofrab - Sun Feb 25, 2007 3:50 pm

theli wrote:
hm ...i wonder... what was the fps of your input video and what fps settings you used for transcode?


Well, I had created a video from a bunch of pictures. The framerate was pretty low, something like 10-15 fps. Then I edited the video in Cinelerra, and finally added sound using ffmpeg to put it all together. I'm no expert on video editing or processing, but the final xvid video with mp3 sound played fine in mplayer(no warnings) and had a framerate of 29.970 fps. Taking this and converting it into dpg with 15 fps, moonshell played the video at a faster rate and the music was out of sync with the video. haddup fixed that for me, indicating that moonshell must be skipping empty duplicate frames, since harddup duplicates these.

Firon wrote:
You actually should just not allow it. It's a waste.


In this case, I prefer a synced video. Size is not an issue... ;P

#119759 - Firon - Sun Feb 25, 2007 11:34 pm

I meant not allowing a higher output FPS than the source FPS.

#127405 - Sigma83 - Wed May 02, 2007 7:22 am

I just caught up with this thread and would really appreciate any direction in how to go about doing a DPG convert in linux. I grabbed the version 4.0 of the script back on page 3 or 4ish, but really am too noob to know what to do with it. I have just been using linux for about a week now, using Debian with KDE file manager. I understand how to get packages etc but just not how to use this script.

Any help and direction would be incredibly appreciated.

Thank you very much.

Sigma

#127452 - oofrab - Wed May 02, 2007 4:46 pm

Well, the script you got is a python script (version 0.4 of dpgconv by theli). You need to use this from the command line in a terminal, there is no graphical user interface unfortunately. For example, in KDE you can start 'Konsole'. The steps you will need to take are:

1. Save script to a file
2. Make file executable
3. Run file from the command line in a terminal (e.g. Konsole)

You will also need some programs installed:
mplayer
mencoder
mpeg_stat (this dependency could be removed, but the script would have to be changed)

All of this is off the top of my head, so I may have missed some things. But ask and someone will surely answer.

#127535 - Sigma83 - Thu May 03, 2007 3:30 am

thank you for your reply. I downloaded dpgconv.py and dropped that into /usr/bin and chmod 777'd the file. I dropped the mpeg_stat and mpeg_stat1 files in there as well. It seems mencoder is already a part of mplayer? (just the impression I got). I then tried...

dpgconv.py ./myavifile.avi ./myaviconvert.avi

and received the following error:

Code:

Converting ./24422.avi
Transcoding video:   done
Transcoding audio:   done
Traceback (most recent call last):
  File "/usr/bin/dpgconv.py", line 321, in ?
    conv_file(file)
  File "/usr/bin/dpgconv.py", line 273, in conv_file
    frames = mpeg_stat()
  File "/usr/bin/dpgconv.py", line 253, in mpeg_stat
    frames = m.group(1)
AttributeError: 'NoneType' object has no attribute 'group'



If anyone has any suggestions I'd really appreciate it as I'm really trying to get comfortable in the linux environment.

Thanks again.

Greg

#127550 - Sigma83 - Thu May 03, 2007 6:05 am

I managed to find a source that provides mencoder and now it's working very well. It seems only the resolution needs adjustment so I'm hoping I can just adjust the script file to account for this.

Thank you for this awesome script. Any tips on adjusting for resolution would be great as well, but i'll take a look at the script myself.

:)

Greg


EDIT: This is such a fantastic script!!!!!!!!! I have nothing but appreciation for the open source community producing quality stuff like this. Thanks again.

#127557 - theli - Thu May 03, 2007 7:32 am

Sigma83 wrote:
and received the following error:
Code:

Converting ./24422.avi
Transcoding video:   done
Transcoding audio:   done
Traceback (most recent call last):
  File "/usr/bin/dpgconv.py", line 321, in ?
    conv_file(file)
  File "/usr/bin/dpgconv.py", line 273, in conv_file
    frames = mpeg_stat()
  File "/usr/bin/dpgconv.py", line 253, in mpeg_stat
    frames = m.group(1)
AttributeError: 'NoneType' object has no attribute 'group'


this just means that it can't find mpeg_stat to run ...
also this proves that i'm to lazy to add at least minimal error checking :(

#127558 - theli - Thu May 03, 2007 7:35 am

btw.. i remember that moonshell supports ogg for audio streams in DPG...
i wonder should i add support for ogg or it is not worth it?

#127687 - Sigma83 - Fri May 04, 2007 1:39 am

I don't know if there's much of an advantage to use ogg. This is working great. If anything, I'd just throw together a simple gui for this :)....or package all these programs into one bundle. Had a hard time finding mencoder.

#127722 - oofrab - Fri May 04, 2007 9:19 am

mencoder should be installable through your linux distributions' package system.
The dependency on mpeg_stat can, as I said earlier, be removed, but this requires some more code in dpgconv.

Now, theli, if you want to support ogg, the differences in the file format of DPG3 , compared to DPG2, according to the Moonshell 1.71 source are:
- New 'Identifier' (offset 0 in header) with value 0x33475044
- Put an ogg audio stream instead of mp2
- Change 'Number of audio channels' (at offset 16 in header) to 3 (?!?)

#127752 - theli - Fri May 04, 2007 2:45 pm

oofrab wrote:
if you want to support ogg

i just wonder if it needed .. does it brings some advantages ?

#127755 - oofrab - Fri May 04, 2007 4:00 pm

Well apart from licensing and patent issues, I believe that the ogg audio support of dpg in Moonshell is suboptimal and that MP2 is currently the better format in dpg used with Moonshell. So, no, I see no reason to implement it yet, unless you want to support the DPG3 format.

#128699 - shadowofdarkness - Mon May 14, 2007 6:12 am

I have a question about the dpg output from this script. How come the output is not always capable of being viewed with mplayer. I would think with the same settings they should turn capable of being viewed with mplayer.

I converted 3 files (all played in mplayer fine)
a flv from youtube (cp'd .flv from /tmp after the file finished downloading in browser)
a dvd complient mpg (made myself from dv camcorder)
a avi (video from net )

after converting to dpg
the dvd complient mpg showed video but no sound in mplayer
both the flv and avi played sound but no video

all worked in moonshell

I would like to test all output before taking the time to copy to my microsd card.

#129136 - JaJa - Sat May 19, 2007 2:09 pm

You can't check a file with mplayer.
Mplayer doesn't understand the DPG container format.

Sometimes it will find a stream it understands and play it (normally the video stream).

There is a tool under windows dpgview.exe iirc that plays them. Maybe it would work under wine?
_________________
LAWL HOOGE
My Blog

#130654 - Mr. Picklesworth - Wed Jun 06, 2007 5:03 am

The site hosting mpeg_stat appears to be dead, and everything talking about it just links to the original (currently dead) web site. Just to rub it in, I guess, it was available in the Ubuntu repos (sudden glimmer of hope), but only for the ancient Warty release, and every single mirror was therefore a broken link! :(

Could someone please post that file here?

Great script, by the way! It was much faster than DPGEncode on Windows all the way up until I realized I didn't have mpeg_stat.
I've been looking for a Linux CLI vs. Windows GUI comparison that makes my choice OS look good, and this seems to be it!

Edit:
Found it on this ugly web site: http://hpux.cs.utah.edu/hppd/hpux/Development/Tools/mpeg_stat-2.2b/
_________________
Thanks!
MKDS Friend Code: 511165-679586
MP:H Friend Code: 2105 2377 6896


Last edited by Mr. Picklesworth on Wed Jun 06, 2007 6:26 am; edited 1 time in total

#130655 - theli - Wed Jun 06, 2007 5:19 am

http://www.google.com.ua/search?q=mpeg_stat-2.2b-src.tar.gz&sourceid=opera&num=%i&ie=utf-8&oe=utf-8

as i can see mpeg_stat is availible in freebsd mirrors :)

#130658 - Mr. Picklesworth - Wed Jun 06, 2007 7:21 am

Okay, I have a few DPGs created with this script now and the video part is fine. However, for audio all it has is a constant, unrelenting noise... a lot like that from a very bad TV / radio connection.

This is playibg in Moonshell 1.7. (I think that's the number? Latest one, anyway).

I wish I could help more with this, but I don't know what else to tell you...
Help, please? :)
_________________
Thanks!
MKDS Friend Code: 511165-679586
MP:H Friend Code: 2105 2377 6896

#130665 - oofrab - Wed Jun 06, 2007 9:11 am

Do all your DPGs result in bad audio?

Do you have (or can create) a small sample of either the source file or the resulting DPG showing the problem and post it somewhere? That would enable someone who has this working to see if there is a problem with the files or the script.

#130669 - theli - Wed Jun 06, 2007 12:25 pm

yeah .. cause i have no idea what is wrong :(

edit: btw, what script are you talking about? ones from the first pages or the one written in python (dpgconv) ?

#130674 - Mr. Picklesworth - Wed Jun 06, 2007 3:42 pm

I can't send you the ones that messed up because they are huge files and it would be illegal to distribute them, but I will try to find a small video to do this with.

This is with the DPGConv Python script.
Code:
python dpgconv-0.4.py 'myVideo' -f 20 --hq


One incredible discovery: It does not happen when there is no audio in the file to begin with! (Okay, not much of a revelation, but it's something).

Yes, every DPG encoded so far that has audio does this. They are all like this:
Code:
Duration: 44 minutes

Video codec: DivX Mpeg-4 Version 5
Framerate: 24 Frames per second

Audio bitrate: 96 kbps
Codec: Mpeg-1 Layer 3
Sample Rate: 32000 Hz
Channels: 2
The reason I started doing this via Linux was because of something wrong with DivX, using DPGEncode in Windows, that caused the system to die at a certain point near the end of encoding the video.
This video plays fine, with working audio, using mplayer.
_________________
Thanks!
MKDS Friend Code: 511165-679586
MP:H Friend Code: 2105 2377 6896

#131549 - weux - Sun Jun 17, 2007 4:50 am

I have a video about 20 minutes long and at the begining the audio and video are synced, but then if you skip to the end the video becomes later than the audio. Is this just how dpgs are or is there a fix for this. Any help would be appreciated.

#131634 - maya - Mon Jun 18, 2007 9:46 am

I was converting some clips to dpg and some videos converted unexpectedly. The video is okay although audio sounds wrong.

Here is an example, I used default options

Source http://dylema.maya.googlepages.com/pianovictim2.mpeg
Converted http://dylema.maya.googlepages.com/pianovictim2.dpg

Yes, the video shows almost pitch black.

Can anyone convert this clip and see you have the same problem?

I am using the following versions
Code:

MEncoder 2:1.0~rc1-0ubuntu9.1 (C) 2000-2006 MPlayer Team
CPU: AMD Athlon(tm)  (Family: 6, Model: 6, Stepping: 2)
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 0
Compiled with runtime CPU detection.


Code:

MPlayer 2:1.0~rc1-0ubuntu9.1 (C) 2000-2006 MPlayer Team
CPU: AMD Athlon(tm)  (Family: 6, Model: 6, Stepping: 2)
CPUflags:  MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 0
Compiled with runtime CPU detection.


Code:

mpeg_stat -- MPEG Analyzer for MPEG I video streams (version 2.2b)


Code:

dpgconv.py 0.4

#131649 - oofrab - Mon Jun 18, 2007 7:28 pm

I played your dpg file and hear the problem with the sound. Then I did my own conversion using dpgconv and the end result was good. I would imagine that the mplayer/mencoder version is to blame. Can you upgrade and retry converting?

My program versions that work converting the file:
Code:

MPlayer SVN-r23545 rpm.livna.org (C) 2000-2007 MPlayer Team

Code:

MEncoder SVN-r23545 (C) 2000-2007 MPlayer Team

Code:

mpeg_stat -- MPEG Analyzer for MPEG I video streams (version 2.2)


By the way, excellent info. Makes it much easier to debug.

#131717 - maya - Tue Jun 19, 2007 10:48 am

I checked out the latest dev version, MPlayer dev-SVN-r23581-4.1.2, but the problem still occurs. I twisted the dpgconv.py so I could see temp files.

I played mp2tmp.mp2 file with normal mpeg player and it worked okay. Also I checked mpgtmp.mpg and it was okay too.

So I assume there is some error around header?

Here is some more info. (if i convert the above file to dpg)

gop.tmp
Code:

0000000: 0000 0000 c280 c3bf c3bf c3bf c3ba 0000  ................
0000010: 0074 c3a0 0100 c3b4 0100 007e c38e 0300  .t.........~....
0000020: c3ae 0200 00c2 92c2 bb05 00c3 a803 0000  ................
0000030: 2cc2 ac07 00c3 a204 0000 c3b6 c2a4 0900  ,...............
0000040: 0a                                       .


header.tmp
Code:

0000000: 4450 4732 c2b1 0500 0000 0f00 0000 7d00  DPG2..........}.
0000010: 0000 0000 0030 0000 0000 c2bb 1700 30c2  .....0........0.
0000020: bb17 00c3 8d52 0b00 c3bd 0d23 0030 0000  .....R.....#.0..
0000030: 0003 0000 000a                           ......


oofrab, can you please compare these files with yours?

Thanks

#131723 - theli - Tue Jun 19, 2007 2:01 pm

weux wrote:
I have a video about 20 minutes long and at the begining the audio and video are synced, but then if you skip to the end the video becomes later than the audio. Is this just how dpgs are or is there a fix for this. Any help would be appreciated.

if you used dpgconv
this may be caused by source file having lower fps than value specified to script (default is 15)

#131726 - theli - Tue Jun 19, 2007 2:23 pm

hm ... i have this issue with above file too ...
dpg and mp2tmp.mp2 sound different in moonshell ....
though both report correct frequency ...

#131736 - oofrab - Tue Jun 19, 2007 4:20 pm

Hmm, I am currently at work so I cannot fully test this, but here are the two headers of the dpg files. The first from your supplied dpg and the other from my coversion of the mpeg file.

Header from mayas dpg file from above:
Code:

00000000  44 50 47 32 b1 05 00 00  00 0f 00 00 00 7d 00 00  |DPG2.........}..|
00000010  00 00 00 00 30 00 00 00  40 d8 17 00 70 d8 17 00  |....0...@...p...|
00000020  d8 50 0b 00 48 29 23 00  40 00 00 00 03 00 00 00  |.P..H)#.@.......|


Header from my conversion of mayas mpeg file from above:
Code:

00000000  44 50 47 32 b1 05 00 00  00 0f 00 00 00 7d 00 00  |DPG2.........}..|
00000010  00 00 00 00 30 00 00 00  00 bb 17 00 30 bb 17 00  |....0.......0...|
00000020  cd 52 0b 00 fd 0d 23 00  30 00 00 00 03 00 00 00  |.R....#.0.......|


They don't seem to match your header though. Your header seems to be much bigger than 48 bytes? Why?

Look at the header description:
http://forum.gbadev.org/viewtopic.php?t=7897&start=48

What type of machine do you have? Is this a 64-bit problem?

I'll look into this in more detail later.

#131802 - theli - Wed Jun 20, 2007 7:37 am

strange ...
i and maya both got 1562688 audiosize ... but you got 1555200 ...

though i can't see a problem .. mp2tmp (at least my) is really 1562688 bytes ....
these causes the differences in headers
also sizes of video streams are also different

#131807 - theli - Wed Jun 20, 2007 8:48 am

there is something wrong either with input file or mencoder

oofrab, can you, please, post mencoder output when converting audio?

#131868 - oofrab - Wed Jun 20, 2007 9:30 pm

Ok, there seems to be some confusion here and several files mencoder versions etc.

The header I posted above was from a Fedora Core 6 distribution with mplayer/mencoder from the livna repository and the version stated in my previous mail. This produced a different sized file than what you two had. Let us for the sake of clarity forget this file, even though it works fine! I believe that the newer mplayer handles the errors in the original stream slightly differently.

I want to also disregard the second post by maya, where the gop and header is shown. Since the header doesn't make sense to me, it is too long, I'll ignore it for now.

At home, I reinstalled my system very recently and now I run Ubuntu. Converting the original mpeg file gives me the EXACT SAME header and file size (2304392) as the first post from maya, BUT there are still differences! The header is the same, the gop-list is the same and the video stream is the same in the dpg files. The only difference is the audio stream! My dpg file works, and maya's above does not. So the question is, what corrupts the audio for maya?

Theli, does your converted dpg file sound like maya's? (Don't be fooled by the same length and header or even the music(?) :) ). The output from the audioconversion is a bit long, so I'll spare you. This is the audio command at least:
Code:

mencoder "pianovictim2.mpeg" -v -of rawaudio -oac lavc -ovc copy -lavcopts acodec=mp2:abitrate=128 -o mp2tmp.mp2 -af channels=2,resample=32000:1:2

with audio data (mp2tmp.mp2) beginning with
Code:

00000000  ff fd 88 04 55 33 33 44  22 44 33 22 33 33 33 6d  |....U33D"D3"333m|
00000010  b6 e3 6c 90 00 00 00 00  00 00 ff f0 0f ff f0 f0  |..l.............|
00000020  fa af f9 46 94 68 09 80  98 cc 8c c9 12 3e 44 8f  |...F.h.......>D.|

The difference from maya's audio can already be seen in this excerpt if one compares the audio stream from the dpg in maya's post.

Oh, and maya? Are you sure you haven't done something to the script to produce the "incorrect" headers? What did you change between first posting your files and after upgrading mplayer/mencoder, posting the gop and header?

(One sidenote. Having a fresh system _without_ mencoder and trying to convert the mpeg file, the script seemed to pass the video and audio encoding states, but complained in the mpeg_stat state. This had me confused for a while and it was not obvious that the error was a missing mencoder. Oh, and theli, the mpeg_stat link on the webpage of dpgconv does not work.)

#131905 - maya - Thu Jun 21, 2007 8:10 am

As I stated earlier mp2 file works okay in Moonshell
Code:

0000000: fffd 8804 5533 3344 2244 3322 3333 336d  ....U33D"D3"333m
0000010: a6e4 6c90 0000 0000 0000 fff0 0fff f005  ..l.............
0000020: ffaf f946 9468 0980 98cc 8cc9 123e 448f  ...F.h.......>D.
0000030: 9d56 2755 8c18 c18b 9bb9 bbdd bddb 61b6  .V'U..........a.
0000040: 1c6a 9f1a a7e3 7cb8 df2d 73d7 3d72 d72d  .j....|..-s.=r.-


and my linux system is
Code:

Linux calvin-ubuntu 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux


only thing that i have changed after installing dev version of mencoder and mplayer is the following
Code:

MP2TMP="/tmp/mp2tmp.mp2"
MPGTMP="/tmp/mpgtmp.mpg"
HEADERTMP="/tmp/header.tmp"
GOPTMP="/tmp/gop.tmp"
STATTMP="/tmp/stat.tmp"

MENCODER="/usr/local/bin/mencoder"
MPLAYER="/usr/local/bin/mplayer"
MPEGSTAT="/usr/local/bin/mpeg_stat"


and i just converted the file again, it works lol
the header is
Code:

0000000: 4450 4732 b105 0000 000f 0000 007d 0000  DPG2.........}..
0000010: 0000 0000 3000 0000 00bb 1700 30bb 1700  ....0.......0...
0000020: cd52 0b00 fd0d 2300 3000 0000 0300 0000  .R....#.0.......

which is exactly same as oofrab's

*sigh*

#131922 - theli - Thu Jun 21, 2007 12:14 pm

oofrab wrote:

Theli, does your converted dpg file sound like maya's? (Don't be fooled by the same length and header or even the music(?) :) ).

it does.. however the same stream played separatly with the same moonshell sounds fine

however that DPG result i got on windows in cygwin ...
i forgot to check it on my home linux system
oofrab wrote:

The output from the audioconversion is a bit long, so I'll spare you. This is the audio command at least:
Code:

mencoder "pianovictim2.mpeg" -v -of rawaudio -oac lavc -ovc copy -lavcopts acodec=mp2:abitrate=128 -o mp2tmp.mp2 -af channels=2,resample=32000:1:2


i meant ... did mencoder spit any errors .. cause mine did.

oofrab wrote:

(One sidenote. Having a fresh system _without_ mencoder and trying to convert the mpeg file, the script seemed to pass the video and audio encoding states, but complained in the mpeg_stat state. This had me confused for a while and it was not obvious that the error was a missing mencoder.

i know dpgconv misses some checks and errors reporting in some places ... just too lazy to fix it ... patches are welcome :D
oofrab wrote:

Oh, and theli, the mpeg_stat link on the webpage of dpgconv does not work.)

but do you know some other mpeg_stat's homepage?


anyway it seems maya's problem is "solved" now .... somehow ...

#131931 - oofrab - Thu Jun 21, 2007 1:13 pm

Good to hear that it works.

As I wrote in my previous post, your initial dpg file was almost correct, but with a bad audio stream. Extracting the stream from the file, I could not get it to play in mplayer. I do not know why Moonshell would play it fine though. Are you sure? (I cannot test it right now.) You could try extracting it from the dpg
Code:

dd ibs=1 skip=48 count=1562688 if=pianovictim2.dpg of=audioStream

and try playing the audiostream in mplayer. It sounds awful.

Theli, yeah mencoder shows many errors during the conversion. Strange that you also get bad audio. Does the audio stream sound ok when player through mplayer?

#131941 - theli - Thu Jun 21, 2007 1:55 pm

oofrab wrote:
Theli, yeah mencoder shows many errors during the conversion. Strange that you also get bad audio. Does the audio stream sound ok when player through mplayer?

audio stream extracted from mine dpg (which doesn't sound good in moonshell) sounds fine with mplayer ... a pure magic ;)

#131958 - oofrab - Thu Jun 21, 2007 5:27 pm

Bah! I'll give up until someone has a problem with this again.

Butchered highlights:

oofrab wrote:
[Maya]I played your dpg file and hear the problem with the sound. Then I did my own conversion using dpgconv and the end result was good.


maya wrote:
I played mp2tmp.mp2 file with normal mpeg player and it worked okay.


maya wrote:
As I stated earlier mp2 file works okay in Moonshell


theli wrote:
oofrab wrote:
Theli, does your converted dpg file sound like maya's?[i.e. bad]
it does.. however the same stream played separatly with the same moonshell sounds fine


oofrab wrote:
Extracting the stream from the file, I could not get it to play in mplayer.


theli wrote:
audio stream extracted from mine dpg (which doesn't sound good in moonshell) sounds fine with mplayer ... a pure magic ;)


Honestly, can all this info be correct at the same time? :)

#132615 - Mr. Picklesworth - Thu Jun 28, 2007 5:27 am

I am on an Ubuntu Feisty system as well, so presumably I have the same version as Maya started with here. (Will double check. Just have to reboot).

For me, every video I have encoded (even completely unrelated ones) has come out with the garbled audio.

If there is anything I can do to provide you with more information here, I will happily do so :)
_________________
Thanks!
MKDS Friend Code: 511165-679586
MP:H Friend Code: 2105 2377 6896

#132653 - oofrab - Thu Jun 28, 2007 12:51 pm

I think we can begin with a sample source file and the resulting dpg. Then someone can maybe try to reproduce the audio problem. I myself have not yet managed to reproduce the bad audio, but have seen it in maya's dpg above.

#132809 - Mr. Picklesworth - Fri Jun 29, 2007 6:02 pm

Okay, just looking for a smaller video that causes a problem...

The one I just tried is an mp4 file, with Mpeg-4 AAC Audio, 2 channels, 48000 Hz. It worked out right, though!

The two others that have gone wrong have been:
- MPEG-1 layer 3, 2 channels, 96 kbps, 32000 Hz
- MPEG-1 layer 3, 2 channels, 104 kbps, 48000 Hz
_________________
Thanks!
MKDS Friend Code: 511165-679586
MP:H Friend Code: 2105 2377 6896

#138107 - techforumz - Sun Aug 19, 2007 10:28 pm

My movie file has about 170,000 frames while only a 16-bit frame counter exists in the header. Any way to get around this without splitting the file?
Also the audio is scrambled. Not noise but its skipping and distorted. I played the file in VLC and it works fine.

Edit: Juhees code won't compile on my box and I don't know how to fix or make c++ code. It has the following errors:
headermaker.cpp: In function ?int main(int, char**)?:
headermaker.cpp:29: error: ?atoi? was not declared in this scope

#138172 - oofrab - Mon Aug 20, 2007 6:49 pm

The number of frames is a 32-bit number (see header). No problem there.

About the audio being scrambled, I have no clue. Some have had trouble with this, as you can read above, but no conclusions can be drawn with the available information.

Quote:

Edit: Juhees code won't compile on my box and I don't know how to fix or make c++ code. It has the following errors:
headermaker.cpp: In function ?int main(int, char**)?:
headermaker.cpp:29: error: ?atoi? was not declared in this scope


It is actually plain C code and you need to include the stdlib header to get the atoi function:
Code:

#include <stdlib.h>

(in C++ the library is cstdlib instead of stdlib.h)

Also you may want to take a look at theli's python script, dpgconv: http://theli.ho.com.ua/dpgconv

#138456 - Thanatos-Drive - Fri Aug 24, 2007 9:08 am

Are people still working on these problems? I'm on Ubuntu Feisty, I could help test. I don't know much about mencoder/ffmpeg/dpg files though.

#138638 - techforumz - Mon Aug 27, 2007 3:39 am

thanks oofrab I will try that. One last question, is there any tool that will automatically convert decimal numbers to hexadecimal numbers?

Thanatos-Drive, I'm on feisty too and I'll let you know what works for me.

Edit: Oh, I tried the python script but I can't compile python, dont know how and cant find the right tools, I will stick with the C version or the manual version for now.

Edit: tried the header code. Compiled fine. Won't run though.
Code:

headermaker.out: 1: Syntax error: "(" unexpected

I used:
Code:
gcc headermaker.c
[/code]

#138643 - Mr. Picklesworth - Mon Aug 27, 2007 5:00 am

Techforumz, Python does not need compiling. It is an interpreted language. (Though just-in-time compiling does happen in some experimental interpreters, but that's another story).

Just run the script with "python myscript.py" in the terminal to execute the Python interpreter with the script.
_________________
Thanks!
MKDS Friend Code: 511165-679586
MP:H Friend Code: 2105 2377 6896

#138698 - techforumz - Tue Aug 28, 2007 12:48 am

I tried the python script with
Code:
python dpgconv 0.4.py foo.ogm out.dpg

Works fine.
Thanatos-Drive, try this it may work for you.
Edit: Will transcode but starts acting up at header.

#138755 - theli - Tue Aug 28, 2007 7:18 pm

techforumz wrote:
I tried the python script with
Code:
python dpgconv.py foo.ogm out.dpg

Works fine.
Thanatos-Drive, try this it may work for you.
Edit: Will transcode but starts acting up at header.

?

by the way ... ( i think i should really change help of dpgconv ...)
you shouldn't run
python dpgconv.py foo.ogm out.dpg

but just

python dpgconv.py foo.ogm

or

python dpgconv.py file1 file2 file3 file4 file5 ... fileN

you shouldn't specify output filename

#138794 - techforumz - Wed Aug 29, 2007 4:56 am

theli wrote:
techforumz wrote:
I tried the python script with
Code:
python dpgconv.py foo.ogm out.dpg

Works fine.
Thanatos-Drive, try this it may work for you.
Edit: Will transcode but starts acting up at header.

?

by the way ... ( i think i should really change help of dpgconv ...)
you shouldn't run
python dpgconv.py foo.ogm out.dpg

but just

python dpgconv.py foo.ogm

or

python dpgconv.py file1 file2 file3 file4 file5 ... fileN

you shouldn't specify output filename

tried that too:

Code:
Traceback (most recent call last):
  File "dpgconv-0.4.py", line 321, in <module>
    conv_file(file)
  File "dpgconv-0.4.py", line 273, in conv_file
    frames = mpeg_stat()
  File "dpgconv-0.4.py", line 253, in mpeg_stat
    frames = m.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Edit: I installed python2.4 to see if that helped.

#138795 - theli - Wed Aug 29, 2007 5:05 am

it seems it can't find mpeg_stat

#138801 - RoxBahamut - Wed Aug 29, 2007 7:17 am

I am new to this, and I am wondering if someone could post a link for mpeg_stat, as I cant find it any where.

Or if possible, could someone write a python script with a basic gui, for feisty, that could do batches of files.

If thats not possible, what about a port of BatchDPG?

Please help, I really need this.

#138838 - theli - Wed Aug 29, 2007 6:00 pm

you can get mpeg_stat at any FreeBSD mirror ... like
ftp://ftp.riken.go.jp/pub/FreeBSD/distfiles/mpeg_stat-2.2b-src.tar.gz

and this file can do batches of files

just run
Code:
dpgconv file1 file2 file3 ... fileN

i can't see any reason for gui version :)

#139023 - techforumz - Fri Aug 31, 2007 8:28 pm

mpeg_stat wont compile for me, is there a deb file?

#139151 - oofrab - Sun Sep 02, 2007 8:59 pm

If you really, really want a solution without mpeg_stat, here is a patch to dpgconv v0.4. This is going to be slow, very slow, but it will give you a dpg without mpeg_stat. After the two transcoding steps for video and audio, the program will seem to hang, but it is just stepping though the mpeg video stream in search of the start codes to put in the GOP list.

My python skills are not good and I would gladly take suggestions to optimizing this. One solution would be to write a small C program for the start code search, a little like a bare bones mpeg_stat.

Here is the patch, but beware, it has not been tested much:
(Add the lines begining with '+' and remove the ones begining with a '-')
Code:

+# Find start codes in mpeg stream
+def findNextStartCode(file):
+
+       r  = file.read(4)
+       sc = struct.unpack('!L',r)[0]
+
+        while True:
+               if (sc >= 0x00000100) and (sc <= 0x000001FF):
+                       return sc;
+               else:
+                       new = file.read(1)
+                       if len(new) == 0:
+                               break
+                       r = r[1] + r[2] + r[3] + new
+                       sc = struct.unpack('!L',r)[0]
+
+        return 0
+
+
+# Find number of frames and sequence start codes in mpeg stream
+def analyze_mpeg():
+
+       frameCnt = 0
+       mpgFile = open(MPGTMP,'rb');
+       gopFile  = open(GOPTMP, 'wb')
+
+       while True:
+               startCode = findNextStartCode(mpgFile)
+               offset    = mpgFile.tell() - 4
+
+               if startCode == 0:
+                       break
+               elif startCode == 0x00000100: # Picture start code
+                       frameCnt += 1
+               elif startCode == 0x000001B3: # Sequence header code
+                       if options.dpg == 2 :
+                               gopFile.write (struct.pack ( "<l" , frameCnt ))
+                               gopFile.write (struct.pack ( "<l" , offset   ))
+
+       gopFile.close()
+       mpgFile.close()
+       return frameCnt
+
 
 def conv_file(file):
        print "Converting " + file
        conv_vid (file)
        conv_aud(file)
-       frames = mpeg_stat()
+       frames = analyze_mpeg()
        write_header(frames)
        dpgname = os.path.basename ( os.path.splitext ( file )[0] ) + ".dpg"

#139877 - techforumz - Tue Sep 11, 2007 3:43 am

I can handle the encoding that's easy linux CLI. I just need something that will generate a header for me. Why won't the header code work anyways? What am I not doing?
Edit: I created a debian package from the source-code for those who don't know how to compile C code.
http://www.freewebs.com/techforumz/mpeg%2Dstat%5F1%2D1%5Fall.deb
Edit: I tried installing mpeg_stat (and it worked) and I tried v0.3 which gave a similar error:
Code:
Traceback (most recent call last):
  File "dpgconv-0.3.py", line 220, in <module>
    conv_file(file)
  File "dpgconv-0.3.py", line 182, in conv_file
    frames = conv_vid (file)
  File "dpgconv-0.3.py", line 116, in conv_vid
    origframes = int(m.group(1))
AttributeError: 'NoneType' object has no attribute 'group'
[/i]

#139888 - theli - Tue Sep 11, 2007 6:14 am

soo... it worked with 0.4+mpeg_stat and is not working with 0.3 for you?

#139949 - techforumz - Tue Sep 11, 2007 11:53 pm

no it doesn't work in 0.4 or 0.3 (or 0.2/0.1 for that matter). I installed the debian that I posted, but it still won't recognize mpeg_stat. I tried a non-mpeg_stat version and that doesn't work either. About the patch, I'm not sure what to add. You said it was C code but you want me to add and remove stuff. And where do I add and remove that stuff anyways?

#140005 - theli - Wed Sep 12, 2007 5:56 pm

open dpgconv-0.4 in some editor and edit this line
MPEG_STAT="mpeg_stat"
so that it points to your mpeg_stat binary ...
something like
MPEG_STAT="/usr/local/bin/mpeg_stat"

#140012 - theli - Wed Sep 12, 2007 7:18 pm

techforumz, please, try
http://theli.ho.com.ua/dpgconv/dpgconv-0.41.py

#140038 - nornagon - Wed Sep 12, 2007 11:33 pm

I tried converting a .flv to a .dpg the other day and the end result was a wickedly skewed video -- the sound kept on drifting way behind the video. I'm running Debian unstable and dpgconv-0.4.

#140072 - theli - Thu Sep 13, 2007 5:41 am

norangon, try updating mencoder .. or maybe ffmpeg ..i think mencoder uses ffmpeg for decoding flv

#140180 - ninjalj - Fri Sep 14, 2007 2:37 am

Here's a patch which allows encoding files with no audio:

Code:

--- dpgconv-0.41.py   2007-09-13 19:16:44.000000000 +0200
+++ dpgconv-0.41_noaudio.py   2007-09-14 02:06:45.000000000 +0200
@@ -8,7 +8,7 @@
 dpgconv.py file1 file2 file3 ... fileN
 command line options:
    --dpg
-      0,1,2 sets DPG version.. default is DPG2
+      0,1,2,3 sets DPG version.. default is DPG2
    
    --pf
       sets pixel format, default is 3
@@ -27,6 +27,10 @@
       sets video stream bps in kb/s(default: 256)
    -a,--abps xxx
       sets audio stream bps kb/s (default: 128)
+   --noaudio
+      create a DPG with no audio
+      (this option really encodes a dummy,
+      highly compressible file with no audio)
    -f,--fps xx
       sets video frames per second (default:15)
    -z,--hz
@@ -79,6 +83,8 @@
 MENCODER="mencoder"
 MPLAYER="mplayer"
 MPEG_STAT="mpeg_stat"
+OGGENC="oggenc"
+DD="dd"
 
 
 
@@ -159,7 +165,7 @@
 
    print "Transcoding video:   done"
 
-def conv_aud(file):
+def conv_mp2(file):
    a_cmd = ( MENCODER + " \"" +file + "\" -v -of rawaudio -oac lavc -ovc copy -lavcopts acodec=mp2:abitrate=" + `options.abps` + " -o " + MP2TMP )
    identify = commands.getoutput( MPLAYER + " -frames 0 -vo null -ao null -identify \"" + file + "\" | grep -E \"^ID|VIDEO|AUDIO\"")
    p = re.compile ("([0-9]*)( ch)")
@@ -191,13 +197,42 @@
    print "Transcoding audio:   done"
 
 
+def conv_noaudio(file):
+   if options.dpg != 3:
+      print "no audio requires DPG3\n"
+      cleanup_callback (0,0)
+      exit(0)
+
+   frames = mpeg_stat()
+   length = options.hz * 1 * 2 * int(frames)
+   a_cmd = ( DD + " if=/dev/zero count=1 bs="+`length`+" | " + OGGENC + " --raw --raw-bits=16 -o " + MP2TMP + " --raw-rate="+`options.hz`+" --raw-chan=1 -q -1 - ")
+
+   proc = subprocess.Popen(a_cmd,shell=True,stdout=subprocess.PIPE,universal_newlines=True,stderr=subprocess.STDOUT)
+
+   v_out = ""
+   
+   p = re.compile ("Encoding \[(.*)\]")
+   for line in proc.stdout:
+      m = p.search( line )
+      if m:
+         print "Transcoding audio: " + m.group(1) + "\r" ,
+   print "Transcoding audio:   done"
+
+
+def conv_aud(file):
+   if options.noaudio:
+      return conv_noaudio(file)
+   else:
+      return conv_mp2(file)
+
+
 def write_header(frames):
    print "Creating header"
 
    audiostart=36
    if options.dpg == 1:
       audiostart += 4
-   elif options.dpg == 2:
+   elif options.dpg >= 2:
       audiostart += 12
    
    audiosize = os.stat(MP2TMP)[stat.ST_SIZE]
@@ -206,7 +241,11 @@
    videoend = videostart + videosize
    f=open(HEADERTMP, 'wb')
    DPG = "DPG" + `options.dpg`
-   headerValues = [ DPG, int(frames), options.fps, 0, options.hz , 0 ,int(audiostart), int(audiosize), int(videostart), int(videosize) ]
+   if options.noaudio:
+      channels = 3
+   else:
+      channels = 0
+   headerValues = [ DPG, int(frames), options.fps, 0, options.hz , channels ,int(audiostart), int(audiosize), int(videostart), int(videosize) ]
    
    f.write (struct.pack( "4s" , headerValues[0]))
    f.write (struct.pack ( "<l" , headerValues[1]))
@@ -221,7 +260,7 @@
 
    if options.dpg == 0:
       f.write (struct.pack ( "<l" , options.pf ))
-   if options.dpg == 2:
+   if options.dpg >= 2:
       gopsize = os.stat(GOPTMP)[stat.ST_SIZE]
       f.write (struct.pack ( "<l" , videoend ))
       f.write (struct.pack ( "<l" , gopsize))
@@ -235,7 +274,7 @@
    m = p.search( s_out )
    if m:
       frames = m.group(1)
-      if options.dpg == 2:
+      if options.dpg >= 2:
          gop=open(GOPTMP, 'wb')
          stat=open(STATTMP, 'rb')
          frame = 0
@@ -270,7 +309,7 @@
    
    print "Creating " + dpgname
    commands.getoutput( "cat \"" + HEADERTMP + "\" \"" + MP2TMP + "\" \"" + MPGTMP + "\" > \"" + dpgname + "\"")
-   if options.dpg == 2:
+   if options.dpg >= 2:
       commands.getoutput( "cat \"" + GOPTMP + "\" >> \"" + dpgname + "\"")
    
    cleanup_callback (0,0)
@@ -285,6 +324,7 @@
 parser.add_option("-l","--lq",action="store_true", dest="lq", default=False)
 parser.add_option("-v","--vbps", type="int", dest="vbps", default=256)
 parser.add_option("-a","--abps", type="int", dest="abps", default=128)
+parser.add_option("--noaudio", action="store_true", dest="noaudio")
 parser.add_option("--height", type="int", dest="height", default=192)
 parser.add_option("--width", type="int", dest="width", default=256)
 parser.add_option("-z","--hz", type="int", dest="hz", default=32000)
@@ -306,7 +346,7 @@
 signal.signal(signal.SIGTERM, cleanup_callback)
 
 import commands,re,stat,struct,subprocess
-if options.dpg > 2:
+if options.dpg > 3:
    options.dpg = 2
 if options.dpg < 0:
    options.dpg = 2
@@ -336,6 +376,15 @@
    print "Error:"
    print test
    exit (0)
+if options.noaudio:
+   test = commands.getoutput( OGGENC + " -v" )
+   m = re.compile ("OggEnc (.*)").search(test)
+   if m:
+      print m.group(0)
+   else:
+      print "Error:"
+      print test
+      exit (0)
 print "It seems we found all programs :)...continuing"
 print "______________________________________________"
 


In fact, it creates a dummy ogg with no sound, which compresses quite well.

I've had mixed results with the video quality depending on the audio sampling rate (I've used either 4000 or 32000 Hz, each of my 3 test videos works well in 4000 Hz XOR 32000 Hz). So if you have trouble, try with -z xxx, where xxx is the sampling rate.


P.S.: DPG, just what the world needed, pr0n for the DS :)

P.S.S.: Spain's gonna win the Eurobasket.

#140218 - theli - Fri Sep 14, 2007 8:00 am

ninjalj, that's nice ... but can you update it so it doesn't use oggenc... because adding another dependacy just for creating dummy audio file :D....

#140230 - nornagon - Fri Sep 14, 2007 2:19 pm

theli wrote:
norangon, try updating mencoder .. or maybe ffmpeg ..i think mencoder uses ffmpeg for decoding flv


I'm getting my mencoder/ffmpeg from http://www.debian-multimedia.org, that's ffmpeg 20070903 and mencoder 1.0-rc1svn20070903. Are those new enough?

#140261 - theli - Fri Sep 14, 2007 9:19 pm

nornagon wrote:
I'm getting my mencoder/ffmpeg from http://www.debian-multimedia.org, that's ffmpeg 20070903 and mencoder 1.0-rc1svn20070903. Are those new enough?

i have no idea ... i only suggested :)

#140266 - oofrab - Fri Sep 14, 2007 9:57 pm

Here is a small patch to fix a somewhat incorrect GOP-list created by dpgconv-0.41.py (and previous versions too).

Code:

--- dpgconv-0.41.py     2007-09-14 22:28:46.000000000 +0200
+++ dpgconv-0.41.py.patched     2007-09-14 22:47:16.000000000 +0200
@@ -243,9 +243,9 @@
                                sline = line.split()
                                if sline[0] == "picture" :
                                        frame += 1
-                               elif sline[0] == "gop":
+                               elif sline[0] == "sequence":
                                        gop.write (struct.pack ( "<l" , frame ))
-                                       gop.write (struct.pack ( "<l" , int(sline[1])/8 - 140 ))
+                                       gop.write (struct.pack ( "<l" , int(sline[1])/8 )) # mpeg_stat shows bit offsets
                        gop.close()
                        stat.close()
        else:

#140292 - ninjalj - Sat Sep 15, 2007 1:42 am

Quote:
ninjalj, that's nice ... but can you update it so it doesn't use oggenc... because adding another dependacy just for creating dummy audio file :D....


The other options are using MP2 (big file, constant bitrate) and avoiding audio at all (moonshell crashes with DPGs with no audio http://mdxonline.dyndns.org/archives/2007/03/moonshell_1.shtml)

In fact, I add another dependency (dd), but I didn't add a test for it.

#140293 - tepples - Sat Sep 15, 2007 1:50 am

ninjalj wrote:
In fact, I add another dependency (dd), but I didn't add a test for it.

dd(1) is covered by the dependency on an environment implementing POSIX utilities.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#140322 - theli - Sat Sep 15, 2007 9:51 am

ninjalj wrote:
The other options are using MP2 (big file, constant bitrate) and avoiding audio at all (moonshell crashes with DPGs with no audio

i mean't why not encode dummy ogg with mencoder :)

#140388 - ninjalj - Sun Sep 16, 2007 12:54 am

Quote:
i mean't why not encode dummy ogg with mencoder :)


Uh? My mencoder doesn't support vorbis output. It supports copy, pcm, mp3lame, faac and lavc (mp2, mp3, ac3, adpcm_ima_wav, sonic).

Oh! Apparently they added "preliminary vorbis encoder" on 1.0rc1. My mencoder is 1.0pre8. I guess I should update and test that encoder.

#140428 - theli - Sun Sep 16, 2007 9:49 am

hm .. and won't encoding a dummy mp3 work?
actually ... i don't that's a big deal depending on oggenc .. i think most users already have it installed (or not?)

btw , oofrab, thanks for patch :)

#144006 - techforumz - Sun Oct 28, 2007 3:42 am

Yippy! I manually converted my first Full-length Movie into DPG! I couldn't get any converter working so I just used the power of the linux command line. That and some insight on the header code. A better model for the header code is available:
http://www.howforge.com/how-to-convert-avi-to-dpg-in-linux

#144010 - techforumz - Sun Oct 28, 2007 4:11 am

I wrote my own guide. For practical purposes I added it to my website instead of here.
http://www.freewebs.com/techforumz/computernewz.htm

#144027 - oofrab - Sun Oct 28, 2007 10:48 am

Those links only cover the old DPG0 format. More recent versions of Moonshell also support DPG1 and DPG2 (and DPG3) file formats.

For a more complete header description, look at posts earlier in this thread.

#157202 - HyperHacker - Tue May 20, 2008 9:25 am

So...

Code:
hyperhacker@Mercury:~/Desktop/junk$ mplayer output.dmp -ao pcm:file=output.wav
MPlayer 1.0rc2-4.2.3 (C) 2000-2007 MPlayer Team
CPU: AMD Sempron(tm) Processor 2800+ (Family: 15, Model: 28, Stepping: 0)
CPUflags:  MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing output.dmp.
libavformat file format detected.
[mp3 @ 0x8804034]Could not find codec parameters (Audio: mp1, 64 kb/s)
LAVF_header: av_find_stream_info() failed


Exiting... (End of file)


Code:
hyperhacker@Mercury:~/Desktop/junk$ python dpgconv.py smw.mp4
Converting smw.mp4
Transcoding video:   done
Transcoding audio:   done
Traceback (most recent call last):
  File "dpgconv.py", line 321, in <module>
    conv_file(file)
  File "dpgconv.py", line 273, in conv_file
    frames = mpeg_stat()
  File "dpgconv.py", line 253, in mpeg_stat


I'd guess the script doesn't work because it depends on mpeg_stat which as I understand no longer exists or something? It's not in the package manager at any rate.

Also, on this step:
Code:
mencoder foo.avi  -o foo.mpg -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=160000 -nosound -ofps 25 -vf scale=256:192
It says "skipping frame" after every line, but the resulting mpg file plays fine... O_o
_________________
I'm a PSP hacker now, but I still <3 DS.

#157206 - ninjalj - Tue May 20, 2008 11:03 am

HyperHacker wrote:

I'd guess the script doesn't work because it depends on mpeg_stat which as I understand no longer exists or something? It's not in the package manager at any rate.

There's a link to mpeg_stat on this thread somewhere.
Quote:


Also, on this step:
Code:
mencoder foo.avi  -o foo.mpg -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=160000 -nosound -ofps 25 -vf scale=256:192
It says "skipping frame" after every line, but the resulting mpg file plays fine... O_o

I think that's because mencoder detects duplicated frames or something like that, sth about pulldown/telecine ...

#160953 - Cartman! - Thu Jul 24, 2008 9:46 pm

Hi people, my first post here :)

I am busy with the dpgconv script and it works like a charm. But i do get problems with short movies and i dont know why... i am converting some flv movies to dpg and the ones that are a few MB are working fine but i tried some short movies (>30sec) which result in movies under 1MB. And when I try to play them... moonshell just hangs. Next boot it looks for that movie again, and hangs. I have to remove the file from the SD card and then moonshell will work again. Is this a common problem, or is there any way i can fix it? The file itself is allright, it works when i try to watch it with a dpg player on windows. It drives me nuts... anyone knows what is wrong?

btw, i tried an R4DS and Cyclo DS Evo with 1.41 menu, i dont think any other card will have a good result on it (i am not going to try all my other cards since they use mostly the same version of moonshell).

update:
i just figured it out :) the video not working is an .flv without audio in it. So..i will need to make a fix for it, think i saw it in this topic already so i'll have to edit the python script for it.

#162108 - D_S - Mon Aug 25, 2008 11:37 pm

Hey all,

I've been trying to create a small script to convert video files to dpg on my mac. I realise that the python script above can be run on my mac, but i'm keen to try and sort my own solution out.

Anyway I'm having real problems even doing the conversion manually at the moment. I can create the header (dpg0 for the time being), the audio file (mp2) and the video file (m1v) using a combination of mencoder and ffmpegx and a hex editor, and cat them all together to a dpg file. When I try and run this on my DS however, it plays, but really jerky, as in pauses every second or so, even though the quality of the video itself seems pretty good.

My first thought was that there was a problem with my header, but I'm pretty sure it fits the DPG0 specification. Tried all sorts of ways of creating the video but this doesn't help. Also I know the mp2 file works fine because I transfered one to the DS and it plays fine. The video files also play fine when I play them through VLC.

Does anyone have any suggestions as to what's causing the video to skip? Sorry if I left out any important information.

Thanks

D_S

edit: after weeks of trying, i finally managed to get a working dpg about an hour or so after making this post, trying now to figure out what setting changes made the difference

thanks anyway

D_S

#163668 - NorQue - Wed Oct 08, 2008 1:05 pm

Does anyone else have sync issues with dpgconv encoded DPGs? Because I'm really wondering now, I've encoded several files to DPGs with different framerate, bitrate and quality settings and it always loses sync after a while and I have no idea why.

Here's some info from one of the original videos:
Code:
ID_DEMUXER=avi
ID_VIDEO_FORMAT=XVID
ID_VIDEO_BITRATE=851312
ID_VIDEO_WIDTH=640
ID_VIDEO_HEIGHT=352
ID_VIDEO_FPS=25.000
ID_VIDEO_ASPECT=0.0000
ID_AUDIO_FORMAT=85
ID_AUDIO_BITRATE=127336
ID_AUDIO_RATE=0
ID_AUDIO_NCH=0
ID_LENGTH=2946.04

I assume the videos audio might be in variable bitrate MP3, I remember that generated some problems back in the days when I used TMPGEnc to encode to MPEG1... might that be part of the problem?

And, on a sidenote, I've added 2-pass encoding support to dpgenc, will post the patch here once I got a not out-of-sync video. I assume that doesn't have anything to do with my problem though, as video and audio isn't in synch with --lq and --hq settings, either.

#163677 - ninjalj - Wed Oct 08, 2008 5:32 pm

NorQue wrote:
Does anyone else have sync issues with dpgconv encoded DPGs?


Happens also to me. Not on all DPGs, tough. Normally after ~15 mins, I think mostly on high motion videos. Probably it's moonshell being unable to cope with the video realtime and losing sync.

#163680 - NorQue - Wed Oct 08, 2008 6:42 pm

I don't think Moonshell is the bottleneck, especially not at 256/128 constant bitrate - back when I encoded with BatchDPG I remember Moonshell decoding variable average bitrates of up to 300 kBit/s with maximum bitrate set to 450 at 25 FPS in a 256*144 Video without problem. I assume something else is causing these sync problems.

I've just set up an experiment involving encoding audio differently. I'll report back how it went...

[EDIT]
K, my little theory that involved variable bitrate audio being the culprit turned out to be wrong. Decoding to WAV and reencoding to MP2 manually didn't help at all. :(

#163952 - theli - Thu Oct 16, 2008 4:04 pm

about ot-of-sync-question
ninjalj, NorQue
could this be the same issue? :
http://forum.gbadev.org/viewtopic.php?p=119617#119617

cause i just had the same issue myself ... and that was not the same issue as when input file had lower fps than dpgconv's default 15 ... i've tried to encode an rm file (mplayer reported 30fps) without harddup filter - i had an out-f-sync issue ... i've reencoded the same file with harddup filter - issue gone :)

#163961 - theli - Thu Oct 16, 2008 7:36 pm

NorQue wrote:
And, on a sidenote, I've added 2-pass encoding support to dpgenc, will post the patch here once I got a not out-of-sync video. I assume that doesn't have anything to do with my problem though, as video and audio isn't in synch with --lq and --hq settings, either.

as i read/understand multi-pass encoding doesn't make any sense with cbr video... don't we get cbr here?

#163962 - NorQue - Thu Oct 16, 2008 7:39 pm

No, unfortunately it's not that problem. :(

Mencoder does indeed show some dupe frames, but with one every odd hundred encoded frames that's nowhere enough to cause the sync issues I get. And the files I want to encode definitely are 25 FPS and I'm also encoding them to 25 FPS.

I wanted to try if changing the pixel format helps today, but it looks like --pf doesn't work, or does it just not work how I think it does?

The mencoder command line I get with --hq is
Code:
mencoder  "myvideo.avi" -v -ofps 25 -sws 9 -vf format=rgb18,scale=256:144:::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 mpgtmp.mpg -of rawvideo
which leads to this mencoder output:
Code:
MEncoder 2:1.0~rc2-0ubuntu13+medibuntu1 (C) 2000-2007 MPlayer Team
CPU: Genuine Intel(R) CPU           T2400  @ 1.83GHz (Family: 6, Model: 14, Stepping: 8)
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
Option fmt: unknown format name: 'rgb18'
Option vf: Error while parsing format parameter fmt (rgb18)

Exiting... (error parsing command line)
mencoder -vf format=fmt=help also doesn't know this colorspace, setting rgb15 or 16 yields output that is, well, a little bit to long to quote.

Would providing a sample file be of any help?

[EDIT]
Sorry, hit "Submit" before I saw your second post...
theli wrote:
as i read/understand multi-pass encoding doesn't make any sense with cbr video... don't we get cbr here?
We get CBR with the original mencoder options from your dpgconv, yes... but with changed options and a second pass we get variable bitrates. :D

Not that much difference in picture quality, though. Just a very tiny little bit less artifacting. :(

[Even moar EDIT]
Here's what I got so far... but I get sync issues with both, cbr and vbr files.

#163963 - theli - Thu Oct 16, 2008 7:54 pm

NorQue wrote:
what I got so far... but I get sync issues with both, cbr and vbr files.

please, try this version and tell me if it fixes your sync issues
http://theli.ho.ua/dpgconv/dpgconv-8.py

#163965 - NorQue - Thu Oct 16, 2008 8:04 pm

Nooo waaay, you're kidding me... it works! In sync! So it were the dupe frames after all? Damn!

Thanks! :D

#163966 - theli - Thu Oct 16, 2008 8:57 pm

NorQue wrote:
I wanted to try if changing the pixel format helps today, but it looks like --pf doesn't work, or does it just not work how I think it does?

errm... i really do not remember anything about it :D
it seems i blindly took supported in dpg1/2 pixel formats into script not looking into whether mencoder supports them

i, actually, do not use moonshell/dpgconv .... :)

though... my mencoder knows at least rgb15,rgb16,rgb24(and do not know about rgb18 and rgb21 :-/ ) formats... and i just tried format=rgb15 and mencoder refused to transcode :(

#163984 - NorQue - Fri Oct 17, 2008 3:58 pm

theli wrote:
NorQue wrote:
I wanted to try if changing the pixel format helps today, but it looks like --pf doesn't work, or does it just not work how I think it does?

errm... i really do not remember anything about it :D
it seems i blindly took supported in dpg1/2 pixel formats into script not looking into whether mencoder supports them
Haha. :P
theli wrote:
i, actually, do not use moonshell/dpgconv .... :)
You really should, it works pretty good. I love watching an episode of a TV series on my DS before sleeping.
theli wrote:
though... my mencoder knows at least rgb15,rgb16,rgb24(and do not know about rgb18 and rgb21 :-/ ) formats... and i just tried format=rgb15 and mencoder refused to transcode :(
Same here. MPlayer man page says that -format combined with scale filter should actually do colorspace conversion. No idea why that doesn't work either, I already experimented with different sws/scale/spp settings but I'm completely out of ideas currently.

Anyways, I've now borrowed all the high quality settings for 2-pass encoding from BatchDPG and created a mod of your original script. Here's the download and here's the diff to your version if you want to integrate the changes (can't put it in code tags, it breaks the layout of the forum :( ).

So, and now I'm going to find out how BatchDPG manages to encode MP2s with the original DS DAC samplerate of 32768 Hz with twolame... it's incredible how much better that sounds.

#164076 - ninjalj - Mon Oct 20, 2008 10:45 am

theli wrote:
about ot-of-sync-question
ninjalj, NorQue
could this be the same issue? :
http://forum.gbadev.org/viewtopic.php?p=119617#119617

cause i just had the same issue myself ... and that was not the same issue as when input file had lower fps than dpgconv's default 15 ... i've tried to encode an rm file (mplayer reported 30fps) without harddup filter - i had an out-f-sync issue ... i've reencoded the same file with harddup filter - issue gone :)


It works OK with harddup. Thanks!

#164094 - theli - Mon Oct 20, 2008 5:20 pm

NorQue wrote:
Here's the download and here's the diff to your version if you want to integrate the changes (can't put it in code tags, it breaks the layout of the forum :( ).

with your patch i get segfault with
[mpeg1video @ 0xa7f49e0]MPEG1/2 does not support 15/1 fps

#164100 - NorQue - Mon Oct 20, 2008 6:46 pm

theli wrote:
with your patch i get segfault with
[mpeg1video @ 0xa7f49e0]MPEG1/2 does not support 15/1 fps

I also get that when encoding with such weird framerates. Try it with something closer to the original, 25 FPS for PAL and 24 FPS for NTSCfilm works for me. Or if you insist on that framerate you could leave out vb_strategy=2 for pass 1.

btw, I found out how BatchDPG does its 32768 Hz samplerate trick. It converts audio to 32768 Hz, pretends the rate is 32kHz straight to twolame, which happily encodes all the samples at the slower speed and tells Moonshell the real samplerate via the DPG header afterwards.

[EDIT]
Maybe I should tell, too, that encoding with true stereo (-m s) instead of joint stereo (-m j) improved audio much more than the samplerate, for my ears. No idea why, since joint stereo should yield much better results... most likely I'm just imagining that.

#165617 - gspawn - Tue Dec 30, 2008 3:55 am

I'm also getting some minor out of sync issues, and i'm using the latest v8 of dpgconv.

I originally used
Code:
$ ./dpgconv-8.py --height 144 filename.avi


Which fixed my problem with the 16:9 aspect ratio, but the audio is just slightly ahead of the video, and the video was a little choppy for my tastes, so I tried this:

Code:
$ ./dpgconv-8.py --height 144 --fps 24 filename.avi


Which made the video run perfect, but now the sound is almost a second out of sync with the video. Is there some setting I can use to fix this?

#165621 - theli - Tue Dec 30, 2008 10:04 am

gspawn wrote:
[skipped]
the audio is just slightly ahead of the
[skipped]
but now the sound is almost a second out of sync with the video

that is strange...
i've recently used dpgconv to watch some anime episodes and had no sync issues at all ...

#165623 - gspawn - Tue Dec 30, 2008 10:43 am

What setting did you use?

#165631 - ninjalj - Tue Dec 30, 2008 10:41 pm

Have you tried the harddup option mentioned above? If that doen't work, maybe mplayer's -delay option will work. If that also doesn't work, maybe you can do some manual correction adding/cutting from the audio stream with dd.

#165632 - gspawn - Wed Dec 31, 2008 12:51 am

No, I haven't tried that. At the risk of sounding totally newbish, how do I use the harddup option with dpgconv? I haven't seen any reference to it in the documentation.

#165634 - ninjalj - Wed Dec 31, 2008 2:58 am

My bad. The harddup fix is already applied to 0.8. You could still try the -delay thingie adding it to the options dpgconv passes to mplayer (v_cmd variable).

#165635 - gspawn - Wed Dec 31, 2008 6:04 am

Will that work if the audio is ahead of the video?

#165637 - theli - Wed Dec 31, 2008 9:42 am

gspawn wrote:
What setting did you use?

default
gspawn wrote:
Will that work if the audio is ahead of the video?

is original video running without any sync issues?

#165641 - gspawn - Wed Dec 31, 2008 6:01 pm

Yes, there are no sync issues in the original video. Here's another interesting thing. These 2 videos Are the only ones that I have this problem with, and it's only really bad in the one. All other videos I've made are perfectly fine.

#170455 - theli - Sun Sep 27, 2009 10:32 am

http://theli.is-a-geek.org/files/dpgconv/dpgconv-9.py.bz2
--keep-aspect for keeping aspect ratio
--volnorm for volume normalization
DPG4+preview thumbnail by Guillaume Bedot
doublepass encoding by NorQue

#170635 - Hatta - Fri Oct 09, 2009 1:59 am

I am having trouble with dpgconv. Here is the output:

Code:
hatta@iblis:~/dpgconv$ ./dpgconv-0.43.py test.avi
mpeg_stat -- MPEG Analyzer for MPEG I video streams (version 2.2)
MPlayer SVN-r29746 (C) 2000-2009 MPlayer Team
Error:
MPlayer SVN-r29746 (C) 2000-2009 MPlayer Team
No file given

Exiting... (error parsing command line)


When I try to encode manually with mencoder using the example on Wikipedia, I get the following error:
Code:
hatta@iblis:~/dpgconv$ mencoder test.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 -of mpeg
MPlayer SVN-r29746 (C) 2000-2009 MPlayer Team
success: format: 0  data: 0x0 - 0xae2c800
AVI file format detected.
[aviheader] Video stream found, -vid 0
[aviheader] Audio stream found, -aid 1
VIDEO:  [XVID]  512x384  12bpp  29.970 fps  988.8 kbps (120.7 kbyte/s)
[V] filefmt:3  fourcc:0x44495658  size:512x384  fps:29.970  ftime:=0.0334
PACKET SIZE: 2048 bytes, deltascr: 245760
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 0
Opening video filter: [scale w=256 h=192]
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)
==========================================================================
Limiting audio preload to 0.4s.
Increasing audio density to 4.
[mpeg4 @ 0x263be90]Invalid and inefficient vfw-avi packed B frames detected
Movie-Aspect is 1.33:1 - prescaling to correct movie aspect.
[swscaler @ 0x269b840]BICUBIC scaler, from yuv420p to yuv420p using MMX2
videocodec: libavcodec (256x192 fourcc=3167706d [mpg1])
[mpeg1video @ 0x263b240]MPEG1/2 does not support 18/1 fps
Could not open codec.
FATAL: Cannot initialize video driver.

Exiting...
hatta@iblis:~/dpgconv$


What am I doing wrong? The file plays fine in mplayer.

#170641 - theli - Fri Oct 09, 2009 6:21 am

Hatta wrote:
I am having trouble with dpgconv. Here is the output:

Code:
hatta@iblis:~/dpgconv$ ./dpgconv-0.43.py test.avi
mpeg_stat -- MPEG Analyzer for MPEG I video streams (version 2.2)
MPlayer SVN-r29746 (C) 2000-2009 MPlayer Team
Error:
MPlayer SVN-r29746 (C) 2000-2009 MPlayer Team
No file given

Exiting... (error parsing command line)



try to delete the follogwing code from dpgconv (near the end of file) :
Code:
test = commands.getoutput ( MPEG_STAT + " --" )
m = re.compile ("mpeg_stat --(.*)").search(test)
if m:
        print m.group(0)
else:
        print "Error:"
        print test
        exit (0)
test = commands.getoutput ( MPLAYER )
m = re.compile ("^MPlayer.*").search(test)
if m:
        print m.group(0)
else:
        print "Error:"
        print test
        exit (0)
test = commands.getoutput ( MENCODER)
m = re.compile ("^MEncoder.*").search(test)
if m:
        print m.group(0)
else:
        print "Error:"
        print test
        exit (0)

#171877 - WalterCool! - Wed Dec 30, 2009 11:03 pm

Some method using only ffmpeg??

I dont wanna use mplayer due licencing issues.

Thanks.

#172443 - xukosky - Sat Feb 06, 2010 12:12 pm

Hi everyone,

I know I am late, so I wonder if anyone would be still interested on this topic.

Some months ago, when I was encoding my videos with the great dpgconv, I though it would be great to include some more features. Mainly a GUI. So I started my own project, and here is the result:

https://sourceforge.net/projects/dpg4x/

It uses a lot of code from dpgconv, and some of the new code is also based on this topic, I just joined them. Thank you.

The most important new features are:
- GUI based on wxwidgets (looks like gtk).
- Can replace mpeg_stat with it's own code, but mpeg_stat is still used if present (as it's faster).
- Audio is encoded in a different thread for better performance.
- Multilanguage based on gettext.
- Replaces the PIL dependency with wxwidgets code.
- Fixes the header problems with DPG1, at least in my DS.

It's only the first version, it works for me, but won't be surprised if it's full of bugs. You can use the tracker to submit them :)

Best regards.

#172578 - theli - Tue Feb 16, 2010 12:53 pm

WalterCool! wrote:
Some method using only ffmpeg??

I dont wanna use mplayer due licencing issues.

Thanks.
i wonder why is that ..
mplayer relies on ffmpeg for audio/video codecs

#172841 - hramrach - Mon Mar 08, 2010 2:59 am

Thanks for the dpgconv script.

It makes converting videos so much easier.

There were some issues with the script on my system but after some patching and getting the mpeg_stat which I could not find in Debian nor Debian Multimedia I can now convert videos nearly automagically.

Edit:

I talked with theli on icq and was able to resolve my issue with subtitles. To encode a mkv file which contains subtitles just extract them to a separate file and explicitly specify that file to dpgconv. Check which track to extract with mkvinfo.

Code:
mkvextract video.mkv 3:video.mkv.ssa
dpgconv video.mkv -s video.mkv.ssa


For some reason my mencoder hates subtitles inside mkv files or there is something else I missed.

Theli says he is no longer converting videos for the DS and no longer works on dpgconv so I post a link to the updated script below.

I fixed these issues in dpgconv
* My mencoder says it is mplayer which makes dpgconv fail. Added a pattern for that.
* When PIL is not installed the video is encoded and then dpgconv fails while creating the thmbnail. Check for PIL on the start.
* Add a 1px black stripe at the bottom of wedescreen videos to prevent the video from "pouring" over the bottom of screen in Moonshell
* Added an option to expand widescreen videos to make room for subtitles.

The remaining issue is that with some older mplayer version dpgconv cannot create the thumbnail and fails. As the thumbnail is created from the encoded video it fails after encoding. Fixing this requires more Python skill than I have.

Here is the updated dpgconv-9.1.py and for those who are wondering mpeg_stat-2.2b.tar.gz