pantson.MPEG v2

BlitzMax Forums/BlitzMax Programming/pantson.MPEG v2

PantsOn(Posted 2007) [#1]
OK I should say its 0.2, but its a vast improvemnt on the last one.

- It can now stream from the internet.. use the command OpenMPEG("http::movie.mpg")
- It can now do fullscreen playback easily. This is after an update to pantson.YUV
- If there are puases in the system, the movie will skip so that sound stays synced.
- Closes movies off properly so it shouldn't eat memory ;-)
- auto detects dimensions and fps of mpeg file
- black and white playback, by setting tmpeg.color to false
- Full command set.. See docs
OpenMPEG(filename)
CloseMPEG(Tmpeg)
DrawMPEG(tpixmap,tmpeg)
StartMPEG(Tmpeg)
MPEGwidth(tmpeg,height)
MPEGheight(tmpeg,width)

I've made some example movies for playback. These are hosted on rapidshare (to save my bandwidth)
There are 4 examples now in the archive. basic, sound, fullscreen and streaming. The do what they say on the tin. ;-)

To obtain a valid MPEG file use the following command lines for FFMPEG
video
ffmpeg -i movie.avi -b 600 -an -vcodec mpegvideo -f mpeg2video test.mpg


sound
ffmpeg -i movie.avi -vn test.ogg

There are still problems restarting movies using the StartMPEG command. I'll be fixing this later. In the meantime close the move, and reopen it.

PS I think I might have found a way to play all movie formats... but will require a lot more development. I'll keep people posted.

Once finalised I will release the code.

enjoy


klepto2(Posted 2007) [#2]
WOW, this works great. I have some questions ;)

Is it possible to have a function to get specific frames or frame ranges? I mean currently it is automatically synced as far as I have noticed.

Also if you have released the source may I be able to release it together with miniB3D? Yesterday I was playing around with your mod and I have managed to get it to work with miniB3D so If i could provide your source later on minib3d will have movie playback capabilities for textures. Naturally you would be fully credited.

Keep up the good work.

Just if your are interrested here is a modified basic.bmx which will show your video on a rotating cube. You may have to comment out the mode2D() stuff to get it work.

Strict

Import pantson.mpeg
Import klepto.minib3d


Local m:TMpeg
Local p:TPixmap
Local ticks:Int=0

' load in movie
m = Openmpeg("..\drwho.mpg")

Graphics3D 800,600,16,2
ClearTextureFilters()


Local Cam:TCamera = CreateCamera()
CameraClsColor Cam,255,0,0
CreateLight()

Local Cube:TMesh = CreateCube()

ScaleEntity cube,5,5,5

PositionEntity cam,0,0,-30

Local movietex:TTexture = CreateTexture(m.width,m.height)

ScaleTexture movietex,.10,.10

EntityTexture cube,movietex

p = CreatePixmap(m.width,m.height,PF_BgRA8888)

startmpeg(m)
While Not EOM(m) And Not KeyDown(key_escape)
		

	If DrawMPEG(m,p) = True
		
		TurnEntity cube,0.5,0.2,0.6
		
		UpdateWorld()
		RenderWorld()
		
		UploadTexture movietex,p
		
		Mode2D()
		'DrawPixmap p,0,0

		DrawText "frames = "+m.frames,20,300
		DrawText "  time = "+m.frames/m.fps,20,320
		DrawText " ticks = "+ticks Mod 10000000,20,340
		´
		'Mode3D()
		
		Flip 0
	EndIf
	
	If KeyDown(KEY_UP) Then MoveEntity cam,0,0,.2
	If KeyDown(KEY_Down) Then MoveEntity cam,0,0,-.2

	ticks:+1
Wend

m.close()

End

Function UploadTexture(tex:TTexture,P:TPixmap)
	glBindtexture GL_TEXTURE_2D,tex.gltex[0]

	p=TTexture.AdjustPixmap(p)
	tex.width=p.width
	tex.height=p.height

	
	
	Local mip_level=0
	glPixelStorei GL_UNPACK_ROW_LENGTH,p.pitch/BytesPerPixel[p.format]
	glTexImage2D GL_TEXTURE_2D,mip_level,GL_RGBA8,tex.width,tex.height,0,GL_BGRA,GL_UNSIGNED_BYTE,p.pixels
	
	
	
	glbindtexture GL_TEXTURE_2D,0

End Function



PantsOn(Posted 2007) [#3]
oops there was a spelling error in one of the examples.
The file should say
http::www.pantson.com/examples/drwho.mpg

I have updated the archive with the correct address.


PantsOn(Posted 2007) [#4]
klepto2..
When you say get frames or frame ranges... do you mean play specific frames. ie start the movie where-ever and finish where-ever?
Or do you mean return the frames as images?

I've nearly got rewind and fast forward working already. Unfortunately I have no control over the sound.. so sound will suddenly become out of sync.

I'd love to see the spinning cube... unfortunaely I get a AdjustPixmap not found error. Have I got an old minib3d mod?


klepto2(Posted 2007) [#5]
Well a small function to retrieve specific ranges of frames or 1 single frame would be great. I mean the people who use this function will have to keep track of the sound sync themselves.

also some kinf of frame independent playback would be nice. currently your app sync the framerate to the current videoframerate but thats not good for using it in 3D ;)

thx


PantsOn(Posted 2007) [#6]
- I can write a function ie MPEGframe(movie:tmpeg,p:pixmap,time:int) that would display the frame at a certain time into the film on the pixmap.
Currently random accessing an MPEG can be quite difficult due to variable bit rates.

- I can do frame independent playback no problem (the harder bit was keeping it sync lol)

Surely you want the video to play at the same speed though?
Ie if the 3D ran at 1 frame a second, then currently the movie would also play at 25fps but only display 1 frame a second, so it looks like the movie is running at the normal speed.

Do you have a latest minib3d (as I can't get your example working)


PantsOn(Posted 2007) [#7]
Good news from my MAC tester... all good there too.
Once I finalise the code I'll release the full mod + source.


klepto2(Posted 2007) [#8]
I'm using my extended Version but if you kill these commands:

Mode2D()
		'DrawPixmap p,0,0

		DrawText "frames = "+m.frames,20,300
		DrawText "  time = "+m.frames/m.fps,20,320
		DrawText " ticks = "+ticks Mod 10000000,20,340
		´
		'Mode3D()


it should work.


PantsOn(Posted 2007) [#9]
i'm getting int can't be indexed error. (if i rem out that line then I get a AdjustPixmap can not be found)
	glBindtexture GL_TEXTURE_2D,tex.gltex[0]
'       ^^^^index error here
	p=TTexture.AdjustPixmap(p)