Hacking Ubuntu Linux? Convert movies to DPG

Kestol

Well-Known Member
OP
Newcomer
Joined
Jan 31, 2008
Messages
88
Trophies
0
XP
96
Country
Hey everyone,
I recently switched to Ubuntu... BUt i dont know how to convert movies to DPG so i can play them in moonshell
wacko.gif

What should i do?
As far as i know BatchDPG doesnt work under linux
wacko.gif


Grats:D
 
D

Deleted User

Guest
Kestol said:
Hey everyone,
I recently switched to Ubuntu... BUt i dont know how to convert movies to DPG so i can play them in moonshell
wacko.gif

What should i do?
As far as i know BatchDPG doesnt work under linux
wacko.gif


Grats:D
Have you tried installing WINE, the Windows "Layer Support" that allows you to run EXEs?

EDIT: I tried it and it works, but you need to install AviSynth as well.
 

arctic_flame

GBAtemp ATMEGA8 Fan
Member
Joined
Nov 4, 2006
Messages
2,835
Trophies
0
Age
30
Location
England land
XP
148
Country
I prefer flexibility. And BatchDPG is slow, and the "author" of all the recent revisions refuses to release the source code, despite it being open source to begin with.
 

leinad

Well-Known Member
Member
Joined
Apr 30, 2007
Messages
408
Trophies
0
Website
Visit site
XP
233
Country
Gambia, The
Get mencoder , ffmpeg , mplayer and python.

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->#! /usr/bin/python
# DPG Converter by Anton Romanov © 2006
# released under GPL-2
#
"""A script to transcode video files to DPG format suitable for
ÂÂ Nintendo DS (tm)
ÂÂ
dpgconv.py file1 file2 file3 ... fileN
command line options:
ÂÂÂÂ--dpg
ÂÂÂÂÂÂÂÂ0,1,2 sets DPG version.. default is DPG2
ÂÂÂÂ
ÂÂÂÂ--pf
ÂÂÂÂÂÂÂÂsets pixel format, default is 3
ÂÂÂÂÂÂÂÂ0ÂÂÂÂÂÂÂÂRGB15
ÂÂÂÂÂÂÂÂ1ÂÂÂÂÂÂÂÂRGB18
ÂÂÂÂÂÂÂÂ2ÂÂÂÂÂÂÂÂRGB21
ÂÂÂÂÂÂÂÂ3ÂÂÂÂÂÂÂÂRGB24

ÂÂÂÂ-q,--hq
ÂÂÂÂÂÂÂÂhigh quality video
ÂÂÂÂ-l,--lq
ÂÂÂÂÂÂÂÂlow quality video(takes no effect when --hq,-q is set)]
ÂÂÂÂdefault is normal quality
ÂÂÂÂ
ÂÂÂÂ-v,--vbps xxx
ÂÂÂÂÂÂÂÂsets video stream bps in kb/s(default: 256)
ÂÂÂÂ-a,--abps xxx
ÂÂÂÂÂÂÂÂsets audio stream bps kb/s (default: 128)
ÂÂÂÂ-f,--fps xx
ÂÂÂÂÂÂÂÂsets video frames per second (default:15)
ÂÂÂÂ-z,--hz
ÂÂÂÂÂÂÂÂsets audio frequency (default:32000)
ÂÂÂÂ-c,--channels
ÂÂÂÂÂÂÂÂ2 - stereo, 1 - mono
ÂÂÂÂÂÂÂÂdefault is to leave as is unless input audio channels
ÂÂÂÂÂÂÂÂnumber is bigger then 2 ... then default is stereo
ÂÂÂÂ--height xxx
ÂÂÂÂÂÂÂÂdestination video height
ÂÂÂÂ--width xxx
ÂÂÂÂÂÂÂÂdestination video width

ÂÂÂÂ--mv
ÂÂÂÂÂÂÂÂadditional parameters for mencoder for video

ÂÂÂÂ--ma
ÂÂÂÂÂÂÂÂadditional parameters for mencoder for audio
ÂÂÂÂ
ÂÂÂÂHardcoding subtitles
ÂÂÂÂ--nosub
ÂÂÂÂÂÂÂÂdo no try autoloading of subtitles
ÂÂÂÂÂÂÂÂ(default is to try to load subtitle with matching filename)
ÂÂÂÂ--sub,-s xxx
ÂÂÂÂÂÂÂÂSpecify subtitles for hardcoding into video output
ÂÂÂÂÂÂÂÂ(is obviously only usable if you specify one file at a time)
ÂÂÂÂ--subcp xxx
ÂÂÂÂÂÂÂÂspecify subtitles encoding
ÂÂÂÂ--font xxx
ÂÂÂÂÂÂÂÂspecify font for subtitles
ÂÂEXAMPLE:
ÂÂÂÂ--font ~/arial-14/font.desc
ÂÂÂÂ--font ~/arialuni.ttf
ÂÂÂÂ--font 'Bitstream Vera Sans'

ÂÂYou can specify font, subcp and other additional mencoder parameters in
ÂÂÂÂ~/.mplayer/mencoder.conf
ÂÂEXAMPLE:
ÂÂÂÂfont=/usr/local/share/fonts/msfonts/comic.ttf
ÂÂÂÂsubcp=cp1251

"""
import sys, os, optparse
MP2TMP="mp2tmp.mp2"
MPGTMP="mpgtmp.mpg"
HEADERTMP="header.tmp"
GOPTMP="gop.tmp"
STATTMP="stat.tmp"

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




#Print a help message if requested.
if "-h" in sys.argv or "-help" in sys.argv or "--help" in sys.argv:
ÂÂÂÂprint __doc__
ÂÂÂÂraise SystemExit

def cleanup_callback(a,b):
ÂÂÂÂprint "Removing temporary files"
ÂÂÂÂif os.path.lexists ( MPGTMP ):
ÂÂÂÂÂÂÂÂos.unlink ( MPGTMP )
ÂÂÂÂif os.path.lexists ( MP2TMP ):
ÂÂÂÂÂÂÂÂos.unlink ( MP2TMP )
ÂÂÂÂif os.path.lexists ( HEADERTMP ):
ÂÂÂÂÂÂÂÂos.unlink ( HEADERTMP )
ÂÂÂÂif os.path.lexists ( GOPTMP ):
ÂÂÂÂÂÂÂÂos.unlink ( GOPTMP )
ÂÂÂÂif os.path.lexists ( STATTMP ):
ÂÂÂÂÂÂÂÂos.unlink ( STATTMP )

def conv_vid(file):
ÂÂÂÂif options.dpg == 0:
ÂÂÂÂÂÂÂÂv_pf = "format=rgb24,"
ÂÂÂÂÂÂÂÂoptions.pf = 3
ÂÂÂÂelif options.pf == 3:
ÂÂÂÂÂÂÂÂv_pf = "format=rgb24,"
ÂÂÂÂelif options.pf == 2:
ÂÂÂÂÂÂÂÂv_pf = "format=rgb21,"
ÂÂÂÂelif options.pf == 1:
ÂÂÂÂÂÂÂÂv_pf = "format=rgb18,"
ÂÂÂÂelif options.pf == 0:
ÂÂÂÂÂÂÂÂv_pf = "format=rgb15,"
ÂÂÂÂelse:
ÂÂÂÂÂÂÂÂv_pf = "format=rgb24,"
ÂÂÂÂÂÂÂÂoptions.pf = 3

ÂÂÂÂif options.hq:
ÂÂÂÂÂÂÂÂv_cmd =ÂÂ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + "scale=" + `options.width` + ":" + `options.height` +":::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:vbitrat
=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo" )
ÂÂÂÂelif options.lq:
ÂÂÂÂÂÂÂÂv_cmd = ( " \"" + file + "\" -v -ofps " + `options.fps` + " -vf " + v_pf + "scale=" + `options.width` + ":" + `options.height` + " -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo" )
ÂÂÂÂelse :
ÂÂÂÂÂÂÂÂv_cmd = ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + "scale=" + `options.width` + ":" + `options.height` + ":::3 -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:cmp=2:subcmp=2:Precmp=2:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo")
ÂÂÂÂ
ÂÂÂÂif options.nosub:
ÂÂÂÂÂÂÂÂif options.sub != None:
ÂÂÂÂÂÂÂÂÂÂÂÂv_cmd = " -sub \"" + options.sub + "\" " + v_cmd
ÂÂÂÂelse:
ÂÂÂÂÂÂÂÂbasename = os.path.splitext ( file )[0]
ÂÂÂÂÂÂÂÂif options.sub != None:
ÂÂÂÂÂÂÂÂÂÂÂÂv_cmd = " -sub \"" + options.sub + "\" " + v_cmd
ÂÂÂÂÂÂÂÂelif os.path.exists ( basename + ".ass" ):
ÂÂÂÂÂÂÂÂÂÂÂÂv_cmd = " -sub \"" + basename + ".ass" + "\" " + v_cmd
ÂÂÂÂÂÂÂÂelif os.path.exists ( basename + ".srt" ):
ÂÂÂÂÂÂÂÂÂÂÂÂv_cmd = " -sub \"" + basename + ".srt" + "\" " + v_cmd
ÂÂÂÂÂÂÂÂelif os.path.exists ( basename + ".sub" ):
ÂÂÂÂÂÂÂÂÂÂÂÂv_cmd = " -sub \"" + basename + ".sub" + "\" " + v_cmd
ÂÂÂÂÂÂÂÂelif os.path.exists ( basename + ".ssa" ):
ÂÂÂÂÂÂÂÂÂÂÂÂv_cmd = " -sub \"" + basename + ".ssa" + "\" " + v_cmd
ÂÂÂÂ
ÂÂÂÂif options.subcp != None:
ÂÂÂÂÂÂÂÂv_cmd = " -subcp " + options.subcp + v_cmd
ÂÂÂÂif options.font != None:
ÂÂÂÂÂÂÂÂv_cmd = " -font \"" + options.font + "\"" + v_cmd

ÂÂÂÂv_cmd = MENCODER + " " + v_cmd
ÂÂÂÂproc = subprocess.Popen(v_cmd,shell=True,stdout=subprocess.PIPE,universal_newlines=True
stderr=open('/dev/null', 'w'))
ÂÂÂÂ
ÂÂÂÂp = re.compile ("f (\(.*%\))")
ÂÂÂÂfor line in proc.stdout:
ÂÂÂÂÂÂÂÂm = p.search( line )
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂif m:
ÂÂÂÂÂÂÂÂÂÂÂÂprint "Transcoding video: " + m.group(1) + "\r" ,



ÂÂÂÂprint "Transcoding video:ÂÂ done"

def conv_aud(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)")
ÂÂÂÂm = p.search( identify )
ÂÂÂÂif m:
ÂÂÂÂÂÂÂÂc = m.group(1)
ÂÂÂÂÂÂÂÂif options.channels == None:
ÂÂÂÂÂÂÂÂÂÂÂÂif c > 2:
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂa_cmd = a_cmd + " -af channels=2,resample=" +`options.hz`+ ":1:2"
ÂÂÂÂÂÂÂÂÂÂÂÂelse:
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂa_cmd = a_cmd + " -af resample=" +`options.hz`+ ":1:2"
ÂÂÂÂÂÂÂÂelif options.channels >= 2:
ÂÂÂÂÂÂÂÂÂÂÂÂa_cmd = a_cmd + " -af channels=2,resample=" +`options.hz`+ ":1:2"
ÂÂÂÂÂÂÂÂelse:
ÂÂÂÂÂÂÂÂÂÂÂÂa_cmd = a_cmd + " -af channels=1,resample=" +`options.hz`+ ":1:2"
ÂÂÂÂelse:
ÂÂÂÂÂÂÂÂprint "Error running mplayer:"
ÂÂÂÂÂÂÂÂprint identify

ÂÂÂÂproc = subprocess.Popen(a_cmd,shell=True,stdout=subprocess.PIPE,universal_newlines=True
stderr=subprocess.STDOUT)

ÂÂÂÂv_out = ""
ÂÂÂÂ
ÂÂÂÂp = re.compile ("f (\(.*%\))")
ÂÂÂÂfor line in proc.stdout:
ÂÂÂÂÂÂÂÂm = p.search( line )
ÂÂÂÂÂÂÂÂif m:
ÂÂÂÂÂÂÂÂÂÂÂÂprint "Transcoding audio: " + m.group(1) + "\r" ,
ÂÂÂÂprint "Transcoding audio:ÂÂ done"


def write_header(frames):
ÂÂÂÂprint "Creating header"

ÂÂÂÂaudiostart=36
ÂÂÂÂif options.dpg == 1:
ÂÂÂÂÂÂÂÂaudiostart += 4
ÂÂÂÂelif options.dpg == 2:
ÂÂÂÂÂÂÂÂaudiostart += 12
ÂÂÂÂ
ÂÂÂÂaudiosize = os.stat(MP2TMP)[stat.ST_SIZE]
ÂÂÂÂvideosize = os.stat(MPGTMP)[stat.ST_SIZE]
ÂÂÂÂvideostart = audiostart + audiosize
ÂÂÂÂ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) ]
ÂÂÂÂ
ÂÂÂÂf.write (struct.pack( "4s" , headerValues[0]))
ÂÂÂÂf.write (struct.pack ( "<l" , headerValues[1]))
ÂÂÂÂf.write (struct.pack ( ">h" , headerValues[2]))
ÂÂÂÂf.write (struct.pack ( ">h" , headerValues[3]))
ÂÂÂÂf.write (struct.pack ( "<l" , headerValues[4]))
ÂÂÂÂf.write (struct.pack ( "<l" , headerValues[5]))
ÂÂÂÂf.write (struct.pack ( "<l" , headerValues[6]))
ÂÂÂÂf.write (struct.pack ( "<l" , headerValues[7]))
ÂÂÂÂf.write (struct.pack ( "<l" , headerValues[8]))
ÂÂÂÂf.write (struct.pack ( "<l" , headerValues[9]))

ÂÂÂÂif options.dpg == 0:
ÂÂÂÂÂÂÂÂf.write (struct.pack ( "<l" , options.pf ))
ÂÂÂÂif options.dpg == 2:
ÂÂÂÂÂÂÂÂgopsize = os.stat(GOPTMP)[stat.ST_SIZE]
ÂÂÂÂÂÂÂÂf.write (struct.pack ( "<l" , videoend ))
ÂÂÂÂÂÂÂÂf.write (struct.pack ( "<l" , gopsize))
ÂÂÂÂÂÂÂÂf.write (struct.pack ( "<l" , options.pf ))


ÂÂÂÂf.close()
def mpeg_stat():
ÂÂÂÂp = re.compile ("frames: ([0-9]*)\.")
ÂÂÂÂs_out = commands.getoutput( MPEG_STAT + " -offset " + STATTMP + " " + MPGTMP )
ÂÂÂÂm = p.search( s_out )
ÂÂÂÂif m:
ÂÂÂÂÂÂÂÂframes = m.group(1)
ÂÂÂÂÂÂÂÂif options.dpg == 2:
ÂÂÂÂÂÂÂÂÂÂÂÂgop=open(GOPTMP, 'wb')
ÂÂÂÂÂÂÂÂÂÂÂÂstat=open(STATTMP, 'rb')
ÂÂÂÂÂÂÂÂÂÂÂÂframe = 0
ÂÂÂÂÂÂÂÂÂÂÂÂfor line in stat:
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsline = line.split()
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂif sline[0] == "picture" :
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂframe += 1
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂelif sline[0] == "sequence":
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgop.write (struct.pack ( "<l" , frame ))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgop.write (struct.pack ( "<l" , int(sline[1])/8 )) # mpeg_stat shows bit offsets
ÂÂÂÂÂÂÂÂÂÂÂÂgop.close()
ÂÂÂÂÂÂÂÂÂÂÂÂstat.close()
ÂÂÂÂelse:
ÂÂÂÂÂÂÂÂprint s_out
ÂÂÂÂÂÂÂÂreturn 0
ÂÂÂÂreturn frames

def conv_file(file):
ÂÂÂÂif not (os.path.lexists ( file )):
ÂÂÂÂÂÂÂÂprint "File " + file + " doesn't exist"
ÂÂÂÂÂÂÂÂreturn
ÂÂÂÂprint "Converting " + file
ÂÂÂÂconv_vid (file)
ÂÂÂÂconv_aud(file)
ÂÂÂÂframes = mpeg_stat()
ÂÂÂÂif frames == 0:
ÂÂÂÂÂÂÂÂprint "Error using mpeg_stat ... see error above"
ÂÂÂÂÂÂÂÂcleanup_callback (0,0)
ÂÂÂÂÂÂÂÂreturn
ÂÂÂÂwrite_header(frames)
ÂÂÂÂdpgname = os.path.basename ( os.path.splitext ( file )[0] ) + ".dpg"
ÂÂÂÂ
ÂÂÂÂprint "Creating " + dpgname
ÂÂÂÂcommands.getoutput( "cat \"" + HEADERTMP + "\" \"" + MP2TMP + "\" \"" + MPGTMP + "\" > \"" + dpgname + "\"")
ÂÂÂÂif options.dpg == 2:
ÂÂÂÂÂÂÂÂcommands.getoutput( "cat \"" + GOPTMP + "\" >> \"" + dpgname + "\"")
ÂÂÂÂ
ÂÂÂÂcleanup_callback (0,0)
ÂÂÂÂprint "Done converting \"" + file + "\" to \"" + dpgname + "\""



from optparse import OptionParser
parser = OptionParser()
parser.add_option("-f","--fps", type="int", dest="fps" , default=15)
parser.add_option("-q","--hq",action="store_true", dest="hq", default=False)
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("--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)
parser.add_option("-c","--channels", type="int", dest="channels")
parser.add_option("--subcp", dest="subcp")
parser.add_option("-s","--sub", dest="sub")
parser.add_option("--font", dest="font")
parser.add_option("--mv", dest="mv")
parser.add_option("--ma", dest="ma")
parser.add_option("--nosub",action="store_true", dest="nosub", default=False)
parser.add_option("--dpg", type="int" , dest="dpg", default=2)
parser.add_option("--pf", type="int" , dest="pf", default=3)

(options, args) = parser.parse_args()

import signal

signal.signal(signal.SIGINT, cleanup_callback)
signal.signal(signal.SIGTERM, cleanup_callback)

import commands,re,stat,struct,subprocess
if options.dpg > 2:
ÂÂÂÂoptions.dpg = 2
if options.dpg < 0:
ÂÂÂÂoptions.dpg = 2


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)
print "It seems we found all programs :)...continuing"
print "______________________________________________"

for file in args:
ÂÂÂÂconv_file(file)<!--c2--></div><!--ec2-->

save that code into "dpg.py" or smthing like that.
Then open the console and type in " python /path/to/the/dpg.py /first/video.avi /second/video.rm /third/movie.mkv" , ... , the .dpg files will be saved where you have runned the python script
 
General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: Why was Michael Jackson, kicked out of boy scouts? He was up to a pack a day!!