Capturing Max window to video example

BlitzMax Forums/BlitzMax Programming/Capturing Max window to video example

Hi. Just a quick update on what I'm working on.
You can give it a window handle, and then just dump it to an AVI using most installed codecs.

Output example here: http://www.furi.dk/files/AVIWriteTest.avi
(714k/Intel Indeo 5 codec so all can use it)
' Include AVITool
Include "AVITool.bmx"

' Create AVI Writer class
Global AVIWriter:TAVIWriter = New TAVIWriter

' Never forget this one
If (Not AVITool_Init())

	Notify("Failed to init AVITool! See debug log for more info.")
	Return

End If

' Setup windowed graphics
Graphics 640,480

' HWND comes from DirectX. TODO: Fix to work in GL mode too.
Local hWnd:Int = Primarydevice.hwnd

' Init AVI writer
If (Not AVIWriter.Open("test.avi", 640, 480, 60, hWnd))

	Notify("Failed to open file for writing!")
	Return

End If


' Loop until escape, recording every step of the way
While(Not KeyHit(KEY_ESCAPE))
	
	' Random square color
	SetColor(Rand(0,255), Rand(0,255), Rand(0,255))
	
	' Random square
	DrawRect(Rand(0, 640), Rand(0, 480),10,10)
	
	' Set white color for text
	SetColor(255,255,255)
	
	' Draw text
	DrawText("Hello this!", Rand(0, 640), Rand(0, 480))
		
	' Update screen
	Flip()
	
	' Write to AVI
	AVIWriter.WriteFrame()

Wend

' Close AVI writer. Never forget this or file will be corrupt.
AVIWriter.Close()


This looks intresting. How dose it effect performance of the app running? i.e. how fast is it?

Depends on how heavy your app is. Most Max2D apps should run without delay.

I added AVI reading too btw:
' Include AVITool
Include "AVITool.bmx"

' Create AVI Reader class
Global AVIReader:TAVIReader = New TAVIReader

' Never forget this one
If (Not AVITool_Init())

	Notify("Failed to init AVITool! See debug log for more info.")
	Return

End If

' Setup windowed graphics
Graphics 640,480

' Init AVI reader and store number of frames
Global numFrames:Int = AVIReader.Open("test.avi", 640, 480)
If (numFrames = 0)

	Notify("Init error!")
	Return

End If

' Keep track of current frame
Global curFrame:Int = 0

' Loop until escape is pressed
While(Not KeyHit(KEY_ESCAPE))
	
	' Clear screen
	Cls
	
	' Read frame
	Local frame:Byte Ptr = AVIReader.ReadFrame(curFrame)
	
	' Bump frame count
	curFrame:+1
	
	' Beyond numframes? If so, reset
	If (curFrame > numFrames)
	
		curFrame = 0
	
	End If
	
	' Use software render
	AVIReader.DrawSoftware(frame)		
					
	' Update screen
	Flip()

Wend

' Close AVI reader
AVIReader.Close()


Well, it requires a CODEC that you need to purchase. Is there a way to user an older version of Indeo or another codec? What about NO Codec?

Would be nice if the Codec was selectable.

What? The Indeo codec comes free with Windows. Always been this way.

Choosing no codec is possible, although it just dumps a video full of uncompressed BMP frames which takes up a whole lotta space ;)

Arcadenut: Download the AVIWriteTest.avi and playit not click and play :)

Aaah!!!

Arcadenut: Download the AVIWriteTest.avi and playit not click and play :)

Alienforce: Cheers - I can see it now!

Well, if I try to play the sample posted here, it pops up and tells me that I don't have the required CODEC (Running WinXP Pro SP2) and it points me to the Indeo web site where I can purchase the CODEC for $15.

What am I missing? (besides the CODEC <G>)

Seems handy.

On the Mac, what I usually do is just grab and save off each frame to a file, either RAW or PNG, then use a free program GQConvert() to turn it into either a quicktime or avi or other file.

I'm on Windows XP here too and have the indeo codec. Did you install media player as it usually contains the most used codecs. I mean, who wan't to pay 15 bucks for some old obsolete codec? ;)