$IFNDEF __RQINC2
TYPE TBITMAP
bmType AS LONG
bmWidth AS LONG
bmHeight AS LONG
bmWidthBytes AS LONG
bmPlanes AS WORD
bmBitsPixel AS WORD
bmBits AS LONG
END TYPE
DECLARE FUNCTION GetCurrentObject LIB "gdi32" ALIAS "GetCurrentObject" (hdc AS LONG,uObjectType AS LONG) AS LONG
DECLARE FUNCTION GetObject LIB "gdi32" ALIAS "GetObjectA" (hObject AS LONG,nCount AS LONG, lpObject AS TBITMAP) AS LONG
FUNCTIONI UDTPTR(...) AS LONG
RESULT = PARAMVAL(1)
END FUNCTION
$DEFINE pf8bit 3
$DEFINE pf24bit 6
$DEFINE pf32bit 7
$ENDIF
$IFNDEF __WIN32API
TYPE BITMAPINFOHEADER
biSize AS LONG
biWidth AS LONG
biHeight AS LONG
biPlanes AS WORD
biBitCount AS WORD
biCompression AS LONG
biSizeImage AS LONG
biXPelsPerMeter AS LONG
biYPelsPerMeter AS LONG
biClrUsed AS LONG
biClrImportant AS LONG
END TYPE
$DEFINE DIB_RGB_COLORS 0&
$DEFINE DIB_PAL_COLORS 1&
$DEFINE BI_RGB 0&
$DEFINE BI_RLE8 1&
$DEFINE BI_RLE4 2&
$DEFINE BI_bitfields 3&
DECLARE FUNCTION mmioStringToFOURCC LIB "winmm.dll" ALIAS "mmioStringToFOURCCA" (BYVAL sz AS STRING, BYVAL uFlags AS LONG) AS LONG
$DEFINE OF_READ &H0
$DEFINE OF_WRITE &H1
$DEFINE OF_READWRITE &H00000002
$DEFINE OF_SHARE_COMPAT &H00000000
$DEFINE OF_SHARE_EXCLUSIVE &H00000010
$DEFINE OF_SHARE_DENY_WRITE &H20
$DEFINE OF_SHARE_DENY_READ &H00000030
$DEFINE OF_SHARE_DENY_NONE &H00000040
$DEFINE OF_PARSE &H00000100
$DEFINE OF_DELETE &H00000200
$DEFINE OF_VERIFY &H00000400
$DEFINE OF_CANCEL &H00000800
$DEFINE OF_CREATE &H1000
$DEFINE OF_PROMPT &H00002000
$DEFINE OF_EXIST &H00004000
$DEFINE OF_REOPEN &H00008000
$ENDIF
TYPE AVI_STREAM_INFO
fccType AS LONG
fccHandler AS LONG
dwFlags AS LONG
dwCaps AS LONG
wPriority AS WORD
wLanguage AS WORD
dwScale AS LONG
dwRate AS LONG
dwStart AS LONG
dwLength AS LONG
dwInitialFrames AS LONG
dwSuggestedBufferSize AS LONG
dwQuality AS LONG
dwSampleSize AS LONG
Left AS LONG
Top AS LONG
Right AS LONG
Bottom AS LONG
dwEditCount AS LONG
dwFormatChangeCount AS LONG
szName AS STRING * 64
END TYPE
TYPE AVI_FILE_INFO
dwMaxBytesPerSecond AS LONG
dwFlags AS LONG
dwCaps AS LONG
dwStreams AS LONG
dwSuggestedBufferSize AS LONG
dwWidth AS LONG
dwHeight AS LONG
dwScale AS LONG
dwRate AS LONG
dwLength AS LONG
dwEditCount AS LONG
szFileType AS STRING * 64
END TYPE
TYPE AVI_COMPRESS_OPTIONS
fccType AS LONG
fccHandler AS LONG
dwKeyFrameEvery AS LONG
dwQuality AS LONG
dwBytesPerSecond AS LONG
dwFlags AS LONG
lpFormat AS LONG
cbFormat AS LONG
lpParms AS LONG
cbParms AS LONG
dwInterleaveEvery AS LONG
END TYPE
DECLARE FUNCTION VideoForWindowsVersion LIB "msvfw32.dll" ALIAS "VideoForWindowsVersion"() AS LONG
DECLARE SUB AVIFileInit LIB "avifil32.dll" ALIAS "AVIFileInit"()
DECLARE FUNCTION AVIFileOpen LIB "avifil32.dll" ALIAS "AVIFileOpen"(ByRef ppfile AS LONG, BYVAL szFile AS STRING, BYVAL uMode AS LONG, BYVAL pclsidHandler AS LONG) AS LONG
DECLARE FUNCTION AVIFileInfo LIB "avifil32.dll" ALIAS "AVIFileInfo"(BYVAL pfile AS LONG, pfi AS AVI_FILE_INFO, BYVAL lSize AS LONG) AS LONG
DECLARE FUNCTION AVIFileCreateStream LIB "avifil32.dll" ALIAS "AVIFileCreateStreamA" (BYVAL pfile AS LONG, Byref ppavi AS LONG, ByRef psi AS AVI_STREAM_INFO) AS LONG
DECLARE FUNCTION AVISaveOptions LIB "avifil32.dll" ALIAS "AVISaveOptions"(BYVAL hWnd AS LONG, _
BYVAL uiFlags AS LONG, _
BYVAL nStreams AS LONG, _
ByRef ppavi AS LONG, _
ByRef ppOptions AS LONG) AS LONG
DECLARE FUNCTION AVISave LIB "avifil32.dll" ALIAS "AVISaveVA" (BYVAL szFile AS STRING, _
BYVAL pclsidHandler AS LONG, _
BYVAL lpfnCallback AS LONG, _
BYVAL nStreams AS LONG, _
ByRef ppaviStream AS LONG, _
ByRef ppCompOptions AS LONG) AS LONG
DECLARE FUNCTION AVISaveOptionsFree LIB "avifil32.dll" ALIAS "AVISaveOptionsFree"(BYVAL nStreams AS LONG, _
ByRef ppOptions AS LONG) AS LONG
DECLARE FUNCTION AVIMakeCompressedStream LIB "avifil32.dll" ALIAS "AVIMakeCompressedStream"(ByRef ppsCompressed AS LONG, _
BYVAL psSource AS LONG, _
ByRef lpOptions AS AVI_COMPRESS_OPTIONS, _
BYVAL pclsidHandler AS LONG) AS LONG
DECLARE FUNCTION AVIStreamSetFormat LIB "avifil32.dll" ALIAS "AVIStreamSetFormat"(BYVAL pavi AS LONG, _
BYVAL lPos AS LONG, _
lpFormat AS BITMAPINFOHEADER, _
BYVAL cbFormat AS LONG) AS LONG
DECLARE FUNCTION AVIStreamWrite LIB "avifil32.dll" ALIAS "AVIStreamWrite"(BYVAL pavi AS LONG, _
BYVAL lStart AS LONG, _
BYVAL lSamples AS LONG, _
BYVAL lpBuffer AS LONG, _
BYVAL cbBuffer AS LONG, _
BYVAL dwFlags AS LONG, _
BYVAL plSampWritten AS LONG, _
BYVAL plBytesWritten AS LONG) AS LONG
DECLARE FUNCTION AVIStreamReadFormat LIB "avifil32.dll" ALIAS "AVIStreamReadFormat"(BYVAL pAVIStream AS LONG, _
BYVAL lPos AS LONG, _
BYVAL lpFormatBuf AS LONG, _
ByRef sizeBuf AS LONG) AS LONG
DECLARE FUNCTION AVIStreamRead LIB "avifil32.dll" ALIAS "AVIStreamRead"(BYVAL pAVIStream AS LONG, _
BYVAL lStart AS LONG, _
BYVAL lSamples AS LONG, _
BYVAL lpBuffer AS LONG, _
BYVAL cbBuffer AS LONG, _
ByRef pBytesWritten AS LONG, _
ByRef pSamplesWritten AS LONG) AS LONG
DECLARE FUNCTION AVIStreamGetFrameOpen LIB "avifil32.dll" ALIAS "AVIStreamGetFrameOpen"(BYVAL pAVIStream AS LONG, BYVAL lpbih AS LONG) AS LONG
DECLARE FUNCTION AVIStreamGetFrame LIB "avifil32.dll" ALIAS "AVIStreamGetFrame"(BYVAL pGetFrameObj AS LONG, _
BYVAL lPos AS LONG) AS LONG
DECLARE FUNCTION AVIStreamGetFrameClose LIB "avifil32.dll" ALIAS "AVIStreamGetFrameClose"(BYVAL pGetFrameObj AS LONG) AS LONG
DECLARE FUNCTION AVIFileGetStream LIB "avifil32.dll" ALIAS "AVIFileGetStream"(BYVAL pfile AS LONG, ByRef ppaviStream AS LONG, BYVAL fccType AS LONG, BYVAL lParam AS LONG) AS LONG
DECLARE FUNCTION AVIMakeFileFromStreams LIB "avifil32.dll" ALIAS "AVIMakeFileFromStreams"(ByRef ppfile AS LONG, BYVAL nStreams AS LONG, BYVAL pAVIStreamArray AS LONG) AS LONG
DECLARE FUNCTION AVIStreamInfo LIB "avifil32.dll" ALIAS "AVIStreamInfo"(BYVAL pAVIStream AS LONG, ByRef psi AS AVI_STREAM_INFO, BYVAL lSize AS LONG) AS LONG
DECLARE FUNCTION AVIStreamStart LIB "avifil32.dll" ALIAS "AVIStreamStart"(BYVAL pavi AS LONG) AS LONG
DECLARE FUNCTION AVIStreamLength LIB "avifil32.dll" ALIAS "AVIStreamLength"(BYVAL pavi AS LONG) AS LONG
DECLARE FUNCTION AVIStreamRelease LIB "avifil32.dll" ALIAS "AVIStreamRelease"(BYVAL pavi AS LONG) AS LONG
DECLARE FUNCTION AVIStreamClose LIB "avifil32.dll" ALIAS "AVIStreamRelease" (BYVAL pavi AS LONG) AS LONG
DECLARE FUNCTION AVIFileRelease LIB "avifil32.dll" ALIAS "AVIFileRelease"(BYVAL pfile AS LONG) AS LONG
DECLARE FUNCTION AVIFileClose LIB "avifil32.dll" ALIAS "AVIFileRelease" (BYVAL pfile AS LONG) AS LONG
DECLARE SUB AVIFileExit LIB "avifil32.dll" ALIAS "AVIFileExit"()
DECLARE FUNCTION AVIMakeStreamFromClipboard LIB "avifil32.dll" ALIAS "AVIMakeStreamFromClipboard"(BYVAL cfFormat AS LONG, BYVAL hGlobal AS LONG, ByRef ppstream AS LONG) AS LONG
DECLARE FUNCTION AVIPutFileOnClipboard LIB "avifil32.dll" ALIAS "AVIPutFileOnClipboard"(BYVAL pAVIFile AS LONG) AS LONG
DECLARE FUNCTION AVIGetFromClipboard LIB "avifil32.dll" ALIAS "AVIGetFromClipboard"(ByRef ppAVIFile AS LONG) AS LONG
DECLARE FUNCTION AVIClearClipboard LIB "avifil32.dll" ALIAS "AVIClearClipboard"() AS LONG
$DEFINE AVIERR_UNSUPPORTED &H80044065
$DEFINE AVIERR_BADFORMAT &H80044066
$DEFINE AVIERR_MEMORY &H80044067
$DEFINE AVIERR_INTERNAL &H80044068
$DEFINE AVIERR_BADFLAGS &H80044069
$DEFINE AVIERR_BADPARAM &H8004406A
$DEFINE AVIERR_BADSIZE &H8004406B
$DEFINE AVIERR_BADHANDLE &H8004406C
$DEFINE AVIERR_FILEREAD &H8004406D
$DEFINE AVIERR_FILEWRITE &H8004406E
$DEFINE AVIERR_FILEOPEN &H8004406F
$DEFINE AVIERR_COMPRESSOR &H80044070
$DEFINE AVIERR_NOCOMPRESSOR &H80044071
$DEFINE AVIERR_READONLY &H80044072
$DEFINE AVIERR_NODATA &H80044073
$DEFINE AVIERR_BUFFERTOOSMALL &H80044074
$DEFINE AVIERR_CANTCOMPRESS &H80044075
$DEFINE AVIERR_USERABORT -2147204922
$DEFINE AVIERR_OK 0&
$DEFINE AVIERR_NoDecompressor &H2
$DEFINE AVIFILEINFO_HASINDEX &H10
$DEFINE AVIFILEINFO_MUSTUSEINDEX &H20
$DEFINE AVIFILEINFO_ISINTERLEAVED &H100
$DEFINE AVIFILEINFO_WASCAPTUREFILE &H10000
$DEFINE AVIFILEINFO_COPYRIGHTED &H20000
$DEFINE AVIFILECAPS_CANREAD &H1
$DEFINE AVIFILECAPS_CANWRITE &H2
$DEFINE AVIFILECAPS_ALLKEYFRAMES &H10
$DEFINE AVIFILECAPS_NOCOMPRESSION &H20
$DEFINE AVICOMPRESSF_INTERLEAVE &H1
$DEFINE AVICOMPRESSF_DATARATE &H2
$DEFINE AVICOMPRESSF_KEYFRAMES &H4
$DEFINE AVICOMPRESSF_VALID &H8
$DEFINE AVIIF_KEYFRAME &H10
CONST streamtypeVIDEO AS LONG = 1935960438
CONST streamtypeAUDIO AS LONG = 1935963489
CONST streamtypeMIDI AS LONG = 1935960429
CONST streamtypeTEXT AS LONG = 1937012852
$DEFINE AVIGETFRAMEF_BESTDISPLAYFMT 1
$DEFINE ICMF_CHOOSE_KEYFRAME &H1
$DEFINE ICMF_CHOOSE_DATARATE &H2
$DEFINE ICMF_CHOOSE_PREVIEW &H4
$DEFINE ICMF_CHOOSE_ALLCOMPRESSORS &H8
TYPE QAVI EXTENDS QOBJECT
PRIVATE:
Retrn AS LONG
pAVIFile AS LONG
pAVIStream AS LONG
pAVICompress AS LONG
FileInfo AS AVI_FILE_INFO
StreamInfo AS AVI_STREAM_INFO
SampleWritten AS LONG
PUBLIC:
NumFrames AS LONG
FirstFrame AS LONG
ERROR AS STRING
ShowError AS INTEGER
Width AS LONG
Height AS LONG
Left AS LONG
Right AS LONG
Top AS LONG
Bottom AS LONG
FPS AS LONG
FileType AS STRING
Quality AS LONG
bpp AS LONG
SampleSize AS LONG
FramesWritten AS LONG
BytesWritten AS LONG
ShowDialog AS INTEGER
UseCompression AS INTEGER
PRIVATE:
FUNCTION CheckAVIError () AS LONG
RESULT = 0
IF QAVI.Retrn <> AVIERR_OK THEN
RESULT = 1
IF (QAVI.pAVIStream <> 0) THEN AVIStreamRelease(QAVI.pAVIStream)
IF (QAVI.pAVICompress <> 0) THEN AVIStreamRelease(QAVI.pAVICompress)
IF (QAVI.pAVIfile <> 0) THEN AVIFileClose(QAVI.pAVIfile)
AVIFileExit
SELECT CASE QAVI.Retrn
CASE AVIERR_UNSUPPORTED
QAVI.ERROR ="unsupported"
CASE AVIERR_BADFORMAT
QAVI.ERROR ="bad format"
CASE AVIERR_BADFLAGS
QAVI.ERROR ="bad flags"
CASE AVIERR_BADPARAM
QAVI.ERROR ="bad parameters"
CASE AVIERR_MEMORY
QAVI.ERROR ="out of memory"
CASE AVIERR_INTERNAL
QAVI.ERROR ="internal error'
CASE AVIERR_BADSIZE
QAVI.Error ="bad "size
CASE AVIERR_BADHANDLE
QAVI.Error ="bad "handle
CASE AVIERR_FILEREAD, AVIERR_FILEWRITE, AVIERR_FILEOPEN, AVIERR_READONLY, AVIERR_NODATA
QAVI.Error ="file READ/write ERROR OR no "data
CASE AVIERR_COMPRESSOR, AVIERR_NOCOMPRESSOR, AVIERR_CANTCOMPRESS
QAVI.Error ="bad compression OR "codec
CASE AVIERR_BUFFERTOOSMALL
QAVI.Error ="buffer too "small
CASE AVIERR_USERABORT
QAVI.Error ="user "aborted
CASE AVIERR_NoDecompressor
QAVI.Error ="No suitable decompressor found FOR this video "stream
END SELECT
QAVI.Error = "AVI FUNCTION: " + QAVI.Error
IF QAVI.ShowError THEN SHOWMESSAGE QAVI.Error
END IF
END SUB
'====================================================================
' Get pointer to the bitmap data
'====================================================================
FUNCTION BMPpointer(TheBitmap AS QBITMAP) AS LONG
DIM hBM AS LONG
DIM hObj AS LONG
DIM Binfo AS TBITMAP
RESULT = 0
IF TheBitmap.Width > 0 AND TheBitmap.Height > 0 THEN 'forget null bitmap
'handle to bitmap in Device context, 7 =OBJ_BITMAP
hBM = GetCurrentObject(TheBitmap.Handle, 7): IF hBM = 0 THEN EXIT FUNCTION
hObj = GetObject(hBM, SIZEOF(BInfo), BInfo): IF hObj = 0 THEN EXIT FUNCTION
RESULT = BInfo.bmBits
END IF
END FUNCTION
PUBLIC:
'====================================================================
' Close File, release memory and COM interface, close library
'====================================================================
FUNCTION CloseAVIFile() AS LONG
WITH QAVI
IF .pAVIStream THEN AVIStreamRelease (.pAVIStream)
IF .pAVICompress THEN AVIStreamRelease (.pAVICompress)
If .pAVIfile THEN AVIFileClose(.pAVIfile)
AVIFileExit ' releases AVIFile library
.pAVIStream = 0
.pAVICompress = 0
.pAVIfile = 0
END WITH
RESULT = 1
END FUNCTION
'======================================================
' Create File, open library, set options, & allocate memory
'======================================================
FUNCTION CreateAVIFile(szFile As STRING, TheWidth AS INTEGER, TheHeight AS INTEGER, Bpp AS INTEGER, fps AS INTEGER) AS LONG
Dim opts As AVI_COMPRESS_OPTIONS
Dim pOpts AS LONG
Dim BI As BITMAPINFOHEADER
DIM DialogForm AS QFORM
MEMSET(opts, 0, SizeOf(opts)) 'clear mem
MEMSET(BI, 0, SizeOf(BI))
QAVI.FramesWritten = 0
RESULT = 0 'failed = 0
AVIFileInit ' opens AVIFile library
' Open the file for writing
QAVI.Retrn = AVIFileOpen(QAVI.pAVIFile, szFile, OF_WRITE Or OF_CREATE, 0&)
IF QAVI.CheckAVIError THEN EXIT FUNCTION
If QAVI.fps > 60 Then QAVI.fps = 60 'do some error checking
' Fill in the header for the video stream
With QAVI.StreamInfo
.fccType = streamtypeVIDEO 'mmioStringToFOURCC(""vids, 0&) ' stream type video
.fccHandler = mmioStringToFOURCC("DIB ", 0&) '"DIB " Device independent bitmap 0&= default AVI handler
.dwScale = 1
.dwRate = fps ' fps
.dwStart = 0
.dwQuality = QAVI.Quality 'compression quality 0 - 10000
.dwLength = QAVI.numFrames 'number of frames, can be 0
.dwSampleSize = TheWidth * TheHeight * bpp/8 'can be non-zero for fixed size frames
.dwSuggestedBufferSize = TheWidth * TheHeight * bpp/8 ' size of one frame pixels
' rectangle for stream
IF QAVI.Top THEN .Top = QAVI.Top ELSE .Top = 0&
IF QAVI.Left THEN .Left = QAVI.Left ELSE .Left = 0&
IF QAVI.Right THEN .Right = QAVI.Right ELSE .Right = TheWidth
IF QAVI.Bottom THEN .Bottom = QAVI.Bottom ELSE .Bottom = TheHeight
End With
' create the stream
QAVI.Retrn = AVIFileCreateStream(QAVI.pAVIfile, QAVI.pAVIStream, QAVI.StreamInfo)
IF QAVI.CheckAVIError THEN EXIT FUNCTION
' ------ if you create a stream you must set pixel format for AVI stream ------------------
With BI
.biBitCount = Bpp
.biClrImportant = 0&
.biClrUsed = 0&
IF bpp = 8 THEN
.biCompression = BI_RLE8 '8 bit RLE
ELSE
.biCompression = BI_RGB 'no compression
END IF
.biHeight = TheHeight
.biWidth = TheWidth
.biPlanes = 1
.biSize = SIZEOF(BI)
.biSizeImage = (TheHeight * TheWidth * bpp\8 ) 'can be set to 0 for BI_RGB compression
.biXPelsPerMeter = 0&
.biYPelsPerMeter = 0&
End With
'set the format of the compressed stream
QAVI.Retrn = AVIStreamSetFormat(QAVI.pAVIStream, 0&, BI, SIZEOF(BI))
IF QAVI.CheckAVIError THEN EXIT FUNCTION
' ----------------------------------------------
' ------------------------------------------------------------------------------------
'user sets compression options, this part is tricky, work in progress
' --------------------------------------------------------------------------------------
IF QAVI.UseCompression THEN
WITH Opts
.fccType = mmioStringToFOURCC(""vids, 0&)
.fccHandler = mmioStringToFOURCC("RLE ", 0&) '0& ' compressor run length encoded
.dwKeyFrameEvery = 0& 'used only if the AVICOMPRESSF_KEYFRAMES flag set
.dwQuality = QAVI.Quality 'compress quality 0-10,000
.dwBytesPerSecond = 0& 'used only if the AVICOMPRESSF_DATARATE flag is set
.dwFlags = AVICOMPRESSF_VALID 'see docs
.lpFormat = 0& 'Pointer to a structure defining the data format. For an audio stream, this is an LPWAVEFORMAT
.cbFormat=0& 'Size, in bytes, of the data referenced by lpFormat
.lpParms =0& 'internal compressor options
.cbParms=0&
.dwInterleaveEvery=0& 'only if the AVICOMPRESSF_INTERLEAVE flag is set.
END WITH
' 'make compressed stream
QAVI.Retrn = AVIMakeCompressedStream(QAVI.pAVICompress, QAVI.pAVIStream, Opts, 0&)
IF QAVI.CheckAVIError THEN EXIT FUNCTION
IF QAVI.pAVICompress THEN QAVI.UseCompression = 1 'crashes
END IF
' ------------------------------------------------------------------------------------
'get compression options from the user dialog, API requires a pointer to a UDT pointer
' --------------------------------------------------------------------------------------
IF QAVI.ShowDialog THEN
pOpts = UDTPTR(opts)
IF AVISaveOptions(DialogForm.Handle, _
ICMF_CHOOSE_KEYFRAME Or ICMF_CHOOSE_DATARATE Or ICMF_CHOOSE_ALLCOMPRESSORS, _
1, _
QAVI.pAVIStream, _
pOpts) <> 1 Then 'returns TRUE if User presses OK, FALSE if Cancel, or error code
AVISaveOptionsFree(1, pOpts)
QAVI.Retrn = AVIERR_USERABORT
QAVI.CheckAVIError
END IF
IF (Opts.fccHandler <> mmioStringToFOURCC("DIB ", 0&)) THEN
QAVI.UseCompression = 1
QAVI.Retrn = AVIMakeCompressedStream(QAVI.pAVICompress, QAVI.pAVIStream, Opts, 0&)
END IF
AVISaveOptionsFree(1, pOpts)
QAVI.Retrn = AVIStreamSetFormat(QAVI.pAVIStream, 0&, BI, SIZEOF(BI))
IF QAVI.CheckAVIError THEN EXIT FUNCTION
END IF 'show dialog
QAVI.Width = TheWidth 'worked, now save them
QAVI.Height = TheHeight
QAVI.bpp = bpp
RESULT = 1
END SUB
'======================================================
' Get info from AVI File, set QAVI properties
'======================================================
FUNCTION GetAVIFileInfo(szFile As STRING) AS LONG
RESULT = 0 'failed = 0
AVIFileInit ' opens AVIFile library
WITH QAVI
.Retrn = AVIFileOpen(.pAVIFile, szFile, OF_SHARE_DENY_WRITE, 0&)
IF .CheckAVIError THEN EXIT FUNCTION
'Get the first available video stream (PAVISTREAM)
.Retrn = AVIFileGetStream(.pAVIFile, .pAVIStream, streamtypeVIDEO, 0&)
IF .CheckAVIError THEN EXIT FUNCTION
'get the starting position of the stream (some streams may not start simultaneously)
.firstFrame = AVIStreamStart(.pAVIStream) 'this function returns -1 on error
IF .firstFrame = -1 Then .Retrn = AVIERR_BADPARAM: .CheckAVIError : EXIT FUNCTION
'get the length of video stream in frames
.NumFrames = AVIStreamLength(.pAVIStream) ' this function returns -1 on error
If .NumFrames = -1 Then .Retrn = AVIERR_BADPARAM: .CheckAVIError : EXIT FUNCTION
'get file info struct
.Retrn = AVIFileInfo(.pAVIFile, .FileInfo, SizeOf(QAVI.FileInfo))
IF .CheckAVIError THEN EXIT FUNCTION
'get stream info struct
.Retrn = AVIStreamInfo(.pAVIStream, .StreamInfo, SizeOf(QAVI.streamInfo))
IF .CheckAVIError THEN EXIT FUNCTION
.Width = .FileInfo.dwWidth
.Height = .FileInfo.dwHeight
.FileType = .FileInfo.szFileType
.FPS = .StreamInfo.dwRate\.StreamInfo.dwScale
.Quality = .StreamInfo.dwQuality
.Left = .StreamInfo.Left
.Top = .StreamInfo.Top
.Right = .StreamInfo.Right
.Bottom = .StreamInfo.Bottom
.SampleSize = .StreamInfo.dwSampleSize
END WITH
RESULT = 1
' With FileInfo .dwMaxBytesPerSecond, .dwFlags, .dwCaps, .dwStreams, .dwSuggestedBufferSize, .dwWidth
' dwHeight, .dwScale , .dwRate , .dwLength, .dwEditCount
' With StreamInfo .fccType, .fccHandler, .dwFlags, .dwCaps, .wPriority, .wLanguage, .dwScale, .dwRate, .dwStart
' .dwLength, .dwInitialFrames, .dwSuggestedBufferSize, .dwQuality, .dwSampleSize )
END SUB
'======================================================
' Get BMP from AVI File, work in progress
' Code adapted from Ray Mercers Tutorial
'======================================================
FUNCTION AVItoBMP(szFile AS STRING, TheBMP AS QBITMAP, FrameNum AS INTEGER) AS LONG
Dim pGetFrameObj As Long 'pointer to GetFrame interface
Dim pDIB As Long 'pointer to packed DIB in memory
Dim bih As BITMAPINFOHEADER 'infoheader to pass to GetFrame functions
DIM BMPPointer AS LONG
Dim i As Long
RESULT = 0 'failed = 0
WITH QAVI
IF .pAVIFile = 0 THEN
.GetAVIFileInfo(szFile) 'opens AVIFile library, gets all the info
ELSE
.Retrn = AVIFileOpen(.pAVIFile, szFile, OF_SHARE_DENY_WRITE, 0&)
IF .CheckAVIError THEN EXIT FUNCTION
'Get the first available video stream (PAVISTREAM)
.Retrn = AVIFileGetStream(.pAVIFile, .pAVIStream, streamtypeVIDEO, 0&)
IF .CheckAVIError THEN EXIT FUNCTION
'get the starting position of the stream (some streams may not start simultaneously)
.firstFrame = AVIStreamStart(.pAVIStream) 'this function returns -1 on error
IF .firstFrame = -1 Then .Retrn = AVIERR_BADPARAM: .CheckAVIError : EXIT FUNCTION
'get the length of video stream in frames
.NumFrames = AVIStreamLength(.pAVIStream) ' this function returns -1 on error
If .NumFrames = -1 Then .Retrn = AVIERR_BADPARAM: .CheckAVIError : EXIT FUNCTION
'get file info struct
.Retrn = AVIFileInfo(.pAVIFile, .FileInfo, SizeOf(QAVI.FileInfo))
IF .CheckAVIError THEN EXIT FUNCTION
'get stream info struct
.Retrn = AVIStreamInfo(.pAVIStream, .StreamInfo, SizeOf(QAVI.streamInfo))
IF .CheckAVIError THEN EXIT FUNCTION
IF .CheckAVIError THEN EXIT FUNCTION
.Width = .FileInfo.dwWidth
.Height = .FileInfo.dwHeight
.FileType = .FileInfo.szFileType
.FPS = .StreamInfo.dwRate\.StreamInfo.dwScale
.Quality = .StreamInfo.dwQuality
.Left = .StreamInfo.Left
.Top = .StreamInfo.Top
.Right = .StreamInfo.Right
.Bottom = .StreamInfo.Bottom
.SampleSize = .StreamInfo.dwSampleSize
END IF
IF (QAVI.StreamInfo.fccHandler = mmioStringToFOURCC("DIB ", 0&)) THEN 'set attributes to 24 bit
bih.biBitCount = 24
QAVI.Bpp = 24
bih.biClrImportant = 0
bih.biClrUsed = 0
bih.biCompression = BI_RGB
bih.biHeight = QAVI.StreamInfo.Bottom - QAVI.StreamInfo.Top
bih.biPlanes = 1
bih.biSize = SIZEOF(bih)'40
bih.biWidth = QAVI.StreamInfo.Right - QAVI.StreamInfo.Left
bih.biXPelsPerMeter = 0
bih.biYPelsPerMeter = 0
' bih.biSizeImage = (QAVI.Width * QAVI.Height * 3) 'calculate total size of RGBQUAD scanlines (DWORD aligned)
bih.biSizeImage = (((bih.biWidth * 3) + 3) And &HFFFC) * bih.biHeight 'calculate total size of RGBQUAD scanlines (DWORD aligned)
TheBMP.PixelFormat = pf24bit
'init AVISTreamGetFrame* functions and create GETFRAME object, tell AVIStream API what format we expect and input stream
pGetFrameObj = AVIStreamGetFrameOpen(.pAVIStream, 0&)'UDTPTR(bih)) 'force function to return 24bit DIBS
ELSE
QAVI.Bpp = 8
TheBMP.PixelFormat = pf8bit
pGetFrameObj = AVIStreamGetFrameOpen(.pAVIStream, AVIGETFRAMEF_BESTDISPLAYFMT) 'Let API pick the best format
END IF
If pGetFrameObj = 0 Then .Retrn = AVIERR_NoDecompressor: .CheckAVIError: EXIT FUNCTION
IF (FrameNum <= .NumFrames) AND (FrameNum >= 0) THEN
' FOR i = .FirstFrame TO (.NumFrames - 1) + .FirstFrame :next i
pDIB = AVIStreamGetFrame(pGetFrameObj, FrameNum)
BMPPointer = QAVI.BMPpointer(TheBMP) 'in case of dynamic memory allocations
IF .Bpp = 24 THEN
pDIB = pDIB + SIZEOF(bih) 'returns pointer to BITMAPINFOHEADER and packed DIB
ELSE
pDIB = pDIB + 1024 + SIZEOF(bih) 'returns pointer to BITMAPINFOHEADER and packed DIB
END IF
MEMCPY(BMPPointer, pDIB, (.Height * .Width * .Bpp/8))
ELSE
.Retrn = AVIERR_BADPARAM
.CheckAVIError
END IF
END WITH
RESULT = 1
END SUB
'======================================================
' Sequential store of Bitmap to AVI file 8 and 24 bit/pixel only
'======================================================
FUNCTION BMPtoAVIFile(TheBmp As QBITMAP) AS LONG 'may need to pass QForm.Handle
DIM BMPPointer AS LONG
DEFLNG cbBuffer = QAVI.Width * QAVI.Height * (QAVI.Bpp\8)
RESULT = 0
WITH QAVI
BMPPointer = .BMPpointer(TheBMP)
' Now write out each video frame
IF .pAVICompress THEN
.Retrn = AVIStreamWrite(.pAVICompress, _
.FramesWritten, 1, _
BMPPointer, cbBuffer, _
AVIIF_KEYFRAME, @QAVI.SampleWritten, @QAVI.BytesWritten)
IF .CheckAVIError THEN EXIT FUNCTION
ELSE
.Retrn = AVIStreamWrite(.pAVIStream, _
.FramesWritten, 1, _
BMPPointer, cbBuffer, _
AVIIF_KEYFRAME, @QAVI.SampleWritten, @QAVI.BytesWritten)
IF .CheckAVIError THEN EXIT FUNCTION
END IF
.FramesWritten += .SampleWritten '1
END WITH
RESULT = 1
END FUNCTION
'======================================================
' clear memory for new instance of QAVI
'======================================================
SUB New()
WITH QAVI
.Retrn = 0&
.pAVIFile = 0&
.pAVIStream = 0&
.pAVICompress = 0&
MEMSET(QAVI.FileInfo, 0, SizeOf(QAVI.FileInfo)) 'need full reference
MEMSET(QAVI.StreamInfo, 0, SizeOf(QAVI.StreamInfo))
.numFrames = 0&
.firstFrame = 0&
.NumFrames = 0&
.Error = ""
.ShowError = 0
.Width = 0&
.Height = 0&
.ShowDialog = 0
.UseCompression =0
.Quality = 10000
.bpp = 24
.FramesWritten = 0&
.SampleWritten =0&
.BytesWritten =0&
END WITH
END SUB
CONSTRUCTOR
New
END CONSTRUCTOR
END TYPE 'QAVI
|
|