pantson.MPEG - finished + source

BlitzMax Forums/BlitzMax Programming/pantson.MPEG - finished + source

PantsOn(Posted 2007) [#1]
Hi

This is now complete.
See the link at the end to get the module with source code.
It has been tested on Windows, Linux and MAC and no problems have been detected yet.
Each module (contains YUV module too) is fully documented and there are clear examples in the archive as well.

commandset
OpenMPEG
DrawMPEG
PauseMPEG
StartMPEG
CloseMPEG
MPEGwidth
MPEGheight

mpeg.sync = true - if set to false then the movie will play as fast as possible.
mpeg.color = true - if set to false then movie will be in greyscale

Have fun...

PS If you find your mpeg files do not play. There is something wrong with the packets inside your movie. I am looking into this.. but in the meantime if you use the following for ffmpeg, it will fix the packet issue.
ffmpeg -i <input file> -vcodec mpegvideo -f mpeg2video -b <bitrate> output.mpg



Nigel Brown(Posted 2007) [#2]
Pressing 'Q' causes the stream to restart at the specified position. Think this is set beyond the end of file in the example fullscreen.bmx. However if you reduce the re-start to fall within the file length on the third re-start it always crashes?


PantsOn(Posted 2007) [#3]
i've not had that at all...
Will check tonight. I tested it on Mepis (maybe that works different to SuSE)


PantsOn(Posted 2007) [#4]
which movie file are you using?
local or web?

web streams aren't seekable.. this is something I can fix.


mongia2(Posted 2007) [#5]
my test video not work

http://www.pippoplutoeda.altervista.org/PITOS.MPG

thanks
mongia


PantsOn(Posted 2007) [#6]
I can't download the movie to test it.
Its just a webpage. sorry.


klepto2(Posted 2007) [#7]
This is coming along very nicely :)

I have a small addition on the openGL side.
You will notice that the DrawPixmap command is very slow and is much slower on low pc specs (a friend of mine got just around 19 fps).

With this small function at the and of the code the fps is about 3 to 4 times faster on lower end machines and incredible faster on mid and highend machines. Instead of Drawing the pixmap an Image with the pixmap uploaded as a texture is drawn.

SuperStrict

Framework brl.max2d

Import brl.glmax2d
Import pantson.mpeg
Import pub.glew



SetGraphicsDriver(GLMax2DDriver())

Local m:Tmpeg
Local p:TPixmap

m = OpenMPEG("intro.mpg")

If m <> Null
	Graphics 640, 480, 0,-1
	
	
	Local P:TPixmap = CreatePixmap(640,MPEGheight(m,640),PF_BGRA8888)
	Local Img:TImage = LoadImage(P)
		
	StartMPEG(m)
	
	
	While Not EOM(m) And Not KeyDown(KEY_ESCAPE)
		
		If DrawMPEG(m,P) = True	
			UploadPixtoImg(Img,P)	
			
		EndIf
		
		
		Cls
		
		SetBlend AlphaBlend
					
		
		DrawImage Img,0,0
						
    	DrawText "Test",20,20
	
		Flip 0
		
		
	Wend
	
	
	CloseMPEG(m)
Else
	DebugStop()
EndIf

End


Function UploadPixtoImg(tex:TImage,Pixmap:TPixmap)
	Local ImgF:TGLImageFrame = TGLImageframe(tex.frame(0))
	Local mip_level:Int = 0

		If ImgF <> Null Then
			glBindtexture GL_TEXTURE_2D,ImgF.name
			glPixelStorei GL_UNPACK_ROW_LENGTH,pixmap.pitch/BytesPerPixel[pixmap.format]
			glTexSubImage2D GL_TEXTURE_2D,mip_level,0,0,pixmap.width,pixmap.height,GL_BGRA,GL_UNSIGNED_BYTE,pixmap.pixels
			glPixelStorei GL_UNPACK_ROW_LENGTH,0
			glBindtexture GL_TEXTURE_2D,0
		EndIf
End Function


I hope this is useful for some people.


mongia2(Posted 2007) [#8]
thanks klepto2
i attend ypur minib3d!

fast fast!!


jhans0n(Posted 2007) [#9]
klepto2, your addition is definitely faster, but it seems like, at least on my old G4 Mac, if I remove the line that says 'DrawText "Test",20,20', it stops working. Any idea why?


klepto2(Posted 2007) [#10]
No, not exactly. I have found this issue shortly after posting this code. But there is small work around for this. Just add the following line at the end of the UploadPixtoImg Function:

DrawText " ",-20,-20


There will be no text, but the bug is (more or less) fixed.


PantsOn(Posted 2007) [#11]
@nigel brown

I tested the mod on Mepis fully last night and didn't get a crash.
I will have to install SuSE to trouble shoot further.


mongia2(Posted 2007) [#12]
pantson test your mod with may mpg
thanks

dont work


www.pippoplutoeda.altervista.org/PITOS.MPG


jhans0n(Posted 2007) [#13]
@klepto2 - Yeah, I did basically the same thing. I was just curious why everything would be dependent on running the DrawText command.


MGE(Posted 2007) [#14]
Klepto: DX7 enabled?


PantsOn(Posted 2007) [#15]
@mongia2
That link doesn't work for me...
It forwards to http://it.altervista.org/ and I aint understanding italian ;-)
Can you post it up onto www.rapidhsare.com please?


klepto2(Posted 2007) [#16]
@PantsOn:
You have to copy the url and then copy it into a new Browser tab. But as far as I have tested it, it seems he didn't convert it like you posted in the mpeg V2 thread. Maybe you should edit the primary post and add this part.

@MGE Developer:
Why do you think about DX7, it is raw OpenGL. No DX7 at all. I guess it is some states which are not reseted or not setted. I haven't found out yet which one it is.


mongia2(Posted 2007) [#17]
http://www.mnzdigital.com/mnzsoftware/PITOS.MPG

link work

test my mpg


PantsOn(Posted 2007) [#18]
@mongia2
there is something wrong with the packet headers inside your file.
My program checks for a valid packet header to get width/height/fps attributes and if it can't find a a valid one it will fail (return null).

If I convert you movie using ffmpeg using
ffmpeg -i pitos.mpg -vcodec mpegvideo -f mpeg1video -b 600 output.mpg

I get a valid file I can play.

What program did you use to create your MPEG?
In the meantiome I will closely at the format of your file to why it doesn't play.
If you can use ffmpeg to convert your movies my mod will be able to play em.

@klepto2
your right.. I forgot to add the conversion stuff into my original post.


MGE(Posted 2007) [#19]
"Why do you think about DX7.." Sometimes OGL fails depending on the gpu, driver, etc. Would be good to have a fall back system in place.