play AVI win32
Posted: Wed Dec 03, 2008 1:58 am
Might be useful - especially if you wanted to use an AVI as a texture in a game for instance.
updated : import path
[/code]
updated : import path
Code: Select all
Structure AVI_RECT
left.l
top.l
right.l
bottom.l
EndStructure
Structure AVI_STREAM_INFO
fccType.l
fccHandler.l
dwFlags.l
dwCaps.l
wPriority.w
wLanguage.w
dwScale.l
dwRate.l
dwStart.l
dwLength.l
dwInitialFrames.l
dwSuggestedBufferSize.l
dwQuality.l
dwSampleSize.l
rcFrame.AVI_RECT
dwEditCount .l
dwFormatChangeCount.l
szName.s{64}
EndStructure
Global pavi.l
Global psi.AVI_STREAM_INFO
Global pgf.l
Global gSizeAVIData
Global *pAviData
Global gmpf.l
Global srcImg.l
Global glastframe.l
Global gbPlay.l
Import #PB_Compiler_Home + "Purelibraries\windows\libraries\avifil32.lib"
AVIStreamOpenFromFileA.l(*avi,szFile.s,fccType.l,lParam.l,mode.l,*clsidHandler)
AVIStreamSampleToTime.l(*avi,lSample.l)
AVIFileInit()
AVIStreamGetFrameOpen.l(*AVIStream,bih.l)
AVIStreamGetFrame.l(*GetFrameObj,lPos.l)
AVIStreamGetFrameClose.l(*GetFrameObj)
AVIStreamInfoA.l(*AVIStream,*psi,lSize.l)
AVIStreamStart.l(*avi)
AVIStreamLength.l(*avi)
AVIStreamRelease.l(*avi)
AVIFileRelease.l(*file)
AVIFileExit()
EndImport
; Import "msvfw32.lib"
; DrawDibOpen.l()
; DrawDibDraw.l(hdd.l,hdc.l,xDst.l,yDst.l,dxDst.l,dyDst.l,*lpbi,lpBits.l,xSrc.l,ySrc.l,dxSrc.l,dySrc.l,wFlags.l)
; DrawDibClose.l(hdd.l)
; EndImport
#streamtypeVIDEO = 1935960438
Procedure CopyMemoryToImage(Memory, ImageNumber)
Protected TemporaryDC.L, TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO
TemporaryDC = CreateDC_("DISPLAY", #Null, #Null, #Null)
GetObject_(ImageID(ImageNumber), SizeOf(BITMAP), TemporaryBitmap.BITMAP)
TemporaryBitmapInfo\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
TemporaryBitmapInfo\bmiHeader\biWidth = TemporaryBitmap\bmWidth
TemporaryBitmapInfo\bmiHeader\biHeight = TemporaryBitmap\bmHeight
TemporaryBitmapInfo\bmiHeader\biPlanes = 1
TemporaryBitmapInfo\bmiHeader\biBitCount = 24
TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
SetDIBits_(TemporaryDC, ImageID(ImageNumber), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS)
DeleteDC_(TemporaryDC)
EndProcedure
Procedure OpenAVI(szFile.S)
AVIFileInit()
AVIStreamOpenFromFileA(@pavi, szFile, #streamtypeVIDEO, 0, #OF_READ, #Null)
If pavi
AVIStreamInfoA(pavi, @psi, SizeOf(psi))
srcAviWidth = psi\rcFrame\right - psi\rcFrame\left
srcAviHeight = psi\rcFrame\bottom - psi\rcFrame\top
glastframe = AVIStreamLength(pavi)
gmpf = AVIStreamSampleToTime(pavi, glastframe) / glastframe
gSizeAVIData = srcAviWidth * srcAviHeight * 3
srcImg = CreateImage(#PB_Any,srcAviWidth,srcAviHeight,24)
*pAVIdata = AllocateMemory(gSizeAVIData)
pgf = AVIStreamGetFrameOpen(pavi, $0)
EndIf
EndProcedure
Procedure GrabAVIFrame(frame.l)
lpbi.l
mybi.BITMAPINFOHEADER
gbPlay = #True
lt = GetTickCount_()
While gbPlay And a < glastframe
If GetTickCount_() > lt
a+1
lt + gmpf
lpbi = AVIStreamGetFrame(pgf, a)
CopyMemory(lpbi,@mybi,SizeOf(mybi))
Offset = mybi\biSize + (mybi\biClrUsed * SizeOf(RGBQUAD))
CopyMemorytoImage(lpbi+offset,srcImg)
SetGadgetState(2,ImageID(srcImg))
EndIf
Delay(1)
Wend
EndProcedure
Procedure CloseAVI()
AVIStreamGetFrameClose(pgf)
AVIStreamRelease(pavi)
AVIFileExit()
EndProcedure
If OpenWindow(0, 300, 200, 640, 500, "test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(0))
ButtonGadget(1,10, 480, 50, 20, "open")
ButtonGadget(3,70, 480, 50, 20, "stop")
ImageGadget(2,0,0,640,480,0)
EndIf
Repeat
Event = WaitWindowEvent()
GadgetID = EventGadget()
If Event = #PB_Event_Gadget
Select GadgetID
Case 1
sfile$ = OpenFileRequester("open file","","*.avi",1)
openavi(sfile$)
CreateThread(@GrabAVIFrame(),1)
Case 3
gbplay = #False
closeAvi()
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf