Save to Video
Save to Video
Hi Gang:
Quick question.
I made a real cool demo reel that I want to save as AVI....
Perhaps even use it as animation for a DVD.
Q: Is there a way to capture PureBasic output to video? How?
Thanks!
Quick question.
I made a real cool demo reel that I want to save as AVI....
Perhaps even use it as animation for a DVD.
Q: Is there a way to capture PureBasic output to video? How?
Thanks!
-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Save to Video
tkruk wrote:Hi Gang:
Quick question.
I made a real cool demo reel that I want to save as AVI....
Perhaps even use it as animation for a DVD.
Q: Is there a way to capture PureBasic output to video? How?
Thanks!

If the captureimages are small


bye,
Daniel
Daniel
This code is from Nico ( French Forum )
Convert bmp to Avi
Convert bmp to Avi
Code: Select all
;/ Nico le 02/06/05
;/ Création d'un avi avec de l'audio
#streamtypeAUDIO = $73647561
#streamtypeVIDEO = $73646976
#ICMF_CHOOSE_KEYFRAME=1
#ICMF_CHOOSE_DATARATE=2
#AVIERR_OK=0
#AVIIF_KEYFRAME=$10
#Lib = 0
Structure bitmap24
bmiHeader.BITMAPINFOHEADER
EndStructure
Structure msvc
a.b
b.b
c.b
d.b
EndStructure
Structure AVISTREAMINFO
fccType.l
fccHandler.msvc
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.RECT
dwEditCount.l
dwFormatChangeCount.l
szName.b[64]
EndStructure
Structure AVICOMPRESSOPTIONS
fccType.l
fccHandler.l
dwKeyFrameEvery.l
dwQuality.l
dwBytesPerSecond.l
dwFlags.l
*lpFormat.l
cbFormat.l
*lpParms.l
cbParms.l
dwInterleaveEvery.l
EndStructure
Structure WAVEFORMATEX
wFormatTag.w
nChannels.w
nSamplesPerSec.l
nAvgBytesPerSec.l
nBlockAlign.w
wBitsPerSample.w
cbSize.w
EndStructure
NewList bitmap.s()
NewList memoire.l()
;/ Procédure traduite en Pure Basic
;/ d'un code écrit en c++ par son auteur Chiew Heng Wah.
Procedure AddWAV(strFileWAV.s, pfile.l)
pfileWav.IAVIFILE
siWav.AVISTREAMINFO
psWav.IAVISTREAM
psAvi.l
fmtWav.WAVEFORMATEX
If CallFunction( #Lib, "AVIFileOpen",@pfileWav, @strFileWAV, #OF_READ, #Null)=0
If CallFunction( #Lib, "AVIFileGetStream",pfileWav, @psWav, #streamtypeAUDIO, 0)=0
If CallFunction( #Lib, "AVIStreamInfo",psWav, @siWav, SizeOf(AVISTREAMINFO))=0
If CallFunction( #Lib, "AVIStreamReadFormat",psWav, 0, #Null, @lFmtSize) =0
If lFmtSize
If CallFunction( #Lib, "AVIStreamReadFormat",psWav, 0, @fmtWav, @lFmtSize)=0
lStreamLength = CallFunction( #Lib, "AVIStreamLength",psWav)
If lStreamLength
lpbData = AllocateMemory(lStreamLength)
If CallFunction( #Lib, "AVIStreamRead",psWav, 0, lStreamLength, lpbData, lStreamLength, #Null, #Null)=0
If CallFunction( #Lib, "AVIFileCreateStream",pfile, @psAvi, @siWav)=0
If CallFunction( #Lib, "AVIStreamSetFormat",psAvi, 0, @fmtWav, lFmtSize)=0
If CallFunction( #Lib, "AVIStreamWrite",psAvi, 0, lStreamLength, lpbData, lStreamLength, #AVIIF_KEYFRAME, #Null, #Null)=0
val.b=1
EndIf
EndIf
CallFunction( #Lib, "AVIStreamRelease",psAvi)
EndIf
EndIf
FreeMemory(lpbData)
EndIf
EndIf
EndIf
EndIf
EndIf
CallFunction( #Lib, "AVIStreamRelease",psWav)
EndIf
CallFunction( #Lib, "AVIFileRelease",pfileWav)
EndIf
ProcedureReturn val
EndProcedure
Fichier.s = OpenFileRequester("Sélection multiple des Fichiers Bitmaps", "", "Fichiers BMP|*.bmp", 0, #PB_Requester_MultiSelection)
If Fichier
Debug Fichier
AddElement(bitmap())
bitmap()= Fichier
Repeat
Fichier = NextSelectedFileName()
If Fichier
AddElement(bitmap())
bitmap()= Fichier
Debug Fichier
EndIf
Until Fichier = ""
EndIf
ForEach bitmap()
If ReadFile(0, bitmap())
FileSeek(SizeOf(BITMAPFILEHEADER))
bmi.bitmap24
ReadData(@bmi, SizeOf(bitmap24))
If bmi\bmiHeader\biWidth
If bmi\bmiHeader\biHeight
If bmi\bmiHeader\biBitCount
If bmi\bmiHeader\bisizeimage=0
bmi\bmiHeader\bisizeimage=Lof()-54
EndIf
FileSeek(1078)
AddElement(memoire())
memoire() =GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, bmi\bmiHeader\bisizeimage)
ReadData(memoire(), bmi\bmiHeader\bisizeimage)
EndIf
EndIf
EndIf
CloseFile(0)
EndIf
Next
If OpenLibrary ( #Lib , "AVIFIL32.DLL")
CallFunction ( #Lib, "AVIFileInit" )
avifile.s = SaveFileRequester ( "Nom du fichier Avi à enregistrer", "", "Video|*.avi", 0 )
If GetExtensionPart(avifile)=""
avifile=avifile+".avi"
EndIf
Debug avifile
If CallFunction( #Lib, "AVIFileOpen", @pAVIFile.IAVIFILE, @avifile, (#OF_WRITE | #OF_CREATE), 0 )=0
strhdr.AVISTREAMINFO
strhdr\fccType = #streamtypeVIDEO
strhdr\fccHandler\a = $6D
strhdr\fccHandler\b = $73
strhdr\fccHandler\c = $76
strhdr\fccHandler\d = $63
strhdr\dwScale = 1 ;Nb de frames/secondes
strhdr\dwRate = 4 ;( 1 à 30)
strhdr\dwSuggestedBufferSize = bmi\bmiHeader\biSize
If SetRect_(@strhdr\rcFrame, 0, 0, bmi\bmiHeader\biWidth, bmi\bmiHeader\biHeight) <>0
If CallFunction( #Lib, "AVIFileCreateStream", pAVIFile, @pAVIStream, @strhdr) =0
opts.AVICOMPRESSOPTIONS
Dim aopts(0)
aopts(0)=@opts
If CallFunction( #Lib, "AVISaveOptions", 0, #ICMF_CHOOSE_KEYFRAME | #ICMF_CHOOSE_DATARATE, 1, @pAVIStream, @aopts(0)) =1
If CallFunction( #Lib, "AVIMakeCompressedStream", @pAVICompressed, pAVIStream, aopts(0), 0)=#AVIERR_OK
If CallFunction( #Lib, "AVIStreamSetFormat", pAVICompressed, 0, @bmi, SizeOf(bitmap24)) =0
ForEach memoire()
If memoire()
If CallFunction( #Lib, "AVIStreamWrite", pAVICompressed, index, 1, memoire() , bmi\bmiHeader\bisizeimage, #AVIIF_KEYFRAME, 0,0) =0
index=index+1
EndIf
EndIf
Next
EndIf
CallFunction( #Lib, "AVIStreamRelease", pAVICompressed)
EndIf
EndIf
CallFunction( #Lib, "AVIStreamRelease", pAVIStream )
EndIf
;------------------------ Inclure le son -----------------------------------------
strFileWAV2.s = OpenFileRequester("Sélection d'un Fichier Audio", "", "Fichiers Wav|*.wav", 0)
If AddWAV(strFileWAV2, pAVIFile)
a$="Le fichier avi créé contient un fichier audio."
Else
a$="Le fichier audio n'a pu être créé."
EndIf
;----------------------------------------
EndIf
CallFunction( #Lib, "AVIFileRelease", pAVIFile)
EndIf
CallFunction( #Lib, "AVIFileExit" )
CloseLibrary( #Lib )
ForEach memoire()
GlobalFree_(memoire())
Next
MessageRequester("Info","Nombre de Frames enregistrées: "+Str(index)+Chr(13)+a$)
EndIf
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Save to Video
This code does not work in PB4.40. I have updated all the simple things but clearly missed one or more items that are not obvious to me. It opens the Lib OK, adds the selected BMP files successfully to a linked list and the compiler does not complain about a thing, but the "AVIFileOpen" function fails:
It doesn't get as far as calling the AddWAV procedure and Audio is not important for my current project but I notice that the procedure returns a value, yet that val is not used anywhere.
Code: Select all
;/ Nico le 02/06/05
;/ Création d'un avi avec de l'audio
#streamtypeAUDIO = $73647561
#streamtypeVIDEO = $73646976
#ICMF_CHOOSE_KEYFRAME = 1
#ICMF_CHOOSE_DATARATE = 2
#AVIERR_OK = 0
#AVIIF_KEYFRAME = $10
#Lib = 10
#BmpFile = 20
#AviFile = 30
Global sgAvi32Lib.s = "C:\WINDOWS\system32\avifil32.dll"
Global sgPat.s = ""
Global igIndex.i = 0
Global bgVal.b = 0
Global sgAviFile.s = ""
Structure bitmap24
bmiHeader.BITMAPINFOHEADER
EndStructure
Structure msvc
a.b
b.b
c.b
d.b
EndStructure
Structure AVISTREAMINFO
fccType.l
fccHandler.msvc
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.RECT
dwEditCount.l
dwFormatChangeCount.l
szName.b[64]
EndStructure
Structure AVICOMPRESSOPTIONS
fccType.l
fccHandler.l
dwKeyFrameEvery.l
dwQuality.l
dwBytesPerSecond.l
dwFlags.l
*lpFormat.l
cbFormat.l
*lpParms.l
cbParms.l
dwInterleaveEvery.l
EndStructure
Structure WAVE_FORMAT
wFormatTag.w
nChannels.w
nSamplesPerSec.l
nAvgBytesPerSec.l
nBlockAlign.w
wBitsPerSample.w
cbSize.w
EndStructure
NewList bitmap.s()
NewList memoire.l()
;/ Procédure traduite en Pure Basic
;/ d'un code écrit en c++ par son auteur Chiew Heng Wah.
Procedure AddWAV(strFileWAV.s, pfile.l)
;--------------------------------------
pfileWav.IAVIFILE
siWav.AVISTREAMINFO
psWav.IAVISTREAM
psAvi.l
fmtWav.WAVE_FORMAT
If CallFunction(#Lib, "AVIFileOpen",@pfileWav, @strFileWAV, #OF_READ, #Null) = 0
If CallFunction(#Lib, "AVIFileGetStream",pfileWav, @psWav, #streamtypeAUDIO, 0) = 0
If CallFunction(#Lib, "AVIStreamInfo",psWav, @siWav, SizeOf(AVISTREAMINFO)) = 0
If CallFunction(#Lib, "AVIStreamReadFormat",psWav, 0, #Null, @lFmtSize) = 0
If lFmtSize
If CallFunction(#Lib, "AVIStreamReadFormat",psWav, 0, @fmtWav, @lFmtSize) = 0
lStreamLength = CallFunction(#Lib, "AVIStreamLength",psWav)
If lStreamLength
lpbData = AllocateMemory(lStreamLength)
If CallFunction(#Lib, "AVIStreamRead",psWav, 0, lStreamLength, lpbData, lStreamLength, #Null, #Null) = 0
If CallFunction(#Lib, "AVIFileCreateStream",pfile, @psAvi, @siWav) = 0
If CallFunction(#Lib, "AVIStreamSetFormat",psAvi, 0, @fmtWav, lFmtSize) = 0
If CallFunction(#Lib, "AVIStreamWrite",psAvi, 0, lStreamLength, lpbData, lStreamLength, #AVIIF_KEYFRAME, #Null, #Null) = 0
bgVal = 1
EndIf
EndIf
CallFunction(#Lib, "AVIStreamRelease",psAvi)
EndIf
EndIf
FreeMemory(lpbData)
EndIf
EndIf
EndIf
EndIf
EndIf
CallFunction(#Lib, "AVIStreamRelease",psWav)
EndIf
CallFunction(#Lib, "AVIFileRelease",pfileWav)
EndIf
ProcedureReturn bgVal
EndProcedure
sgPat = "Image Files (*.BMP *.bmp)|*.BMP;*.bmp"
Images.s = OpenFileRequester("Select multiple Bitmap Images", "", sgPat, 0, #PB_Requester_MultiSelection)
If Images
AddElement(bitmap())
bitmap() = Images
Repeat
Images = NextSelectedFileName()
If Images
AddElement(bitmap())
bitmap() = Images
EndIf
Until Images = ""
EndIf
ForEach bitmap()
If ReadFile(#BmpFile, bitmap())
FileSeek(#BmpFile, SizeOf(BITMAPFILEHEADER))
bmi.bitmap24
ReadData(#BmpFile, @bmi, SizeOf(bitmap24))
If bmi\bmiHeader\biWidth
If bmi\bmiHeader\biHeight
If bmi\bmiHeader\biBitCount
If bmi\bmiHeader\bisizeimage = 0
bmi\bmiHeader\bisizeimage = (Lof(#BmpFile) - 54)
EndIf
FileSeek(#BmpFile,1078)
AddElement(memoire())
memoire() = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, bmi\bmiHeader\bisizeimage)
ReadData(#BmpFile,memoire(), bmi\bmiHeader\bisizeimage)
EndIf
EndIf
EndIf
CloseFile(#BmpFile)
EndIf
Next
If OpenLibrary(#Lib, sgAvi32Lib)
CallFunction(#Lib, "AVIFileInit") ;## Initialise the AVI Lib (cannot test success, does not return a val)
sgPat = "AVI Movie File (*.AVI *.avi)|*.AVI;*.avi"
sgAviFile = SaveFileRequester("Enter AVI File Name", "", sgPat, 0)
If (GetExtensionPart(sgAviFile) = "")
sgAviFile = sgAviFile + ".avi"
EndIf
If CallFunction(#Lib, "AVIFileOpen", @pAVIFile.IAVIFILE, @sgAviFile, (#OF_WRITE | #OF_CREATE), 0) = 0
strhdr.AVISTREAMINFO
strhdr\fccType = #streamtypeVIDEO
strhdr\fccHandler\a = $6D
strhdr\fccHandler\b = $73
strhdr\fccHandler\c = $76
strhdr\fccHandler\d = $63
strhdr\dwScale = 1
strhdr\dwRate = 5 ;##Frames per second(1 to 30)
strhdr\dwSuggestedBufferSize = bmi\bmiHeader\biSize
If SetRect_(@strhdr\rcFrame, 0, 0, bmi\bmiHeader\biWidth, bmi\bmiHeader\biHeight) <> 0
If CallFunction(#Lib, "AVIFileCreateStream", pAVIFile, @pAVIStream, @strhdr) = 0
opts.AVICOMPRESSOPTIONS
Dim aopts(1)
aopts(0) = @opts
If CallFunction(#Lib, "AVISaveOptions", 0, #ICMF_CHOOSE_KEYFRAME | #ICMF_CHOOSE_DATARATE, 1, @pAVIStream, @aopts(0)) = 1
If CallFunction(#Lib, "AVIMakeCompressedStream", @pAVICompressed, pAVIStream, aopts(0), 0) = #AVIERR_OK
If CallFunction(#Lib, "AVIStreamSetFormat", pAVICompressed, 0, @bmi, SizeOf(bitmap24)) = 0
ForEach memoire()
If memoire()
If CallFunction(#Lib, "AVIStreamWrite", pAVICompressed, igIndex, 1, memoire(), bmi\bmiHeader\bisizeimage, #AVIIF_KEYFRAME, 0, 0) = 0
igIndex = igIndex + 1
Else
MessageRequester("Attention","AVI Stream Write call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
EndIf ;## memoire()
Next
Else
MessageRequester("Attention","AVI Stream Set Format call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf ;##CallFunction(#Lib, "AVIStreamSetFormat"
CallFunction(#Lib, "AVIStreamRelease", pAVICompressed)
Else
MessageRequester("Attention","AVI Make Compressed Stream call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf ;##CallFunction(#Lib, "AVIMakeCompressedStream"
Else
MessageRequester("Attention","AVI Save Options call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf ;##CallFunction(#Lib, "AVISaveOptions"
CallFunction(#Lib, "AVIStreamRelease", pAVIStream)
Else
MessageRequester("Attention","AVI create File Stream call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf ;##CallFunction(#Lib, "AVIFileCreateStream"
;### Include Sound Option ###
sgPat = "Audio Files (*.WAV *.wav)|*.WAV;*.wav"
strFileWAV2.s = OpenFileRequester("Select an Audio file", "", sgPat, 0)
If (Len(strFileWAV2) > 4)
If AddWAV(strFileWAV2, pAVIFile)
a$="Audio added to AVI file"
Else
a$="Could not add Audio to AVI file"
EndIf
EndIf
;### End Include Sound Option ###
Else
MessageRequester("Attention","Set header frame width and height values call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf ;##SetRect_
CallFunction(#Lib, "AVIFileRelease", pAVIFile)
Else
MessageRequester("Attention","AVI File Open call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf ;##CallFunction(#Lib, "AVIFileOpen"
CallFunction(#Lib, "AVIFileExit") ;## Release the AVI Lib
CloseLibrary(#Lib)
ForEach memoire()
GlobalFree_(memoire())
Next
MessageRequester("Info","Total number of Frames created: " + Str(igIndex) + Chr(13) + a$)
Else
MessageRequester("Attention","Could not Open AVI Lib", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf ;##OpenLibrary(#Lib, sgAvi32Lib)
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Save to Video
Never got this code to work. There are memory issues along the way with CallFunction, for example:
Fails with [ERROR] Invalid memory access. (read error at address 0)
Code: Select all
CallFunction(#Lib, "AVIFileCreateStream", pAVIFile, @pAVIStream, @strhdr)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Save to Video
Just caught this about coverting to PB4.40. Haven't tested your code yet, but my suggestion atm is to try using command prototyping or use Import/EndImport to wrap the Avifil32 library commands. This is actually a safer and more perferred method over using CallFunction nowadays.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Save to Video
Hi D Ogre
Well, I'm going to take your advice on board. I really need the code to work in a specific way for my app anyway, so it's better to learn about the avi lib first. I have found a nice tutorial http://www.shrinkwrapvb.com/avihelp/avihlp_1.htm for VB which explains the basics, I shouldn't have too much trouble in PB.
Well, I'm going to take your advice on board. I really need the code to work in a specific way for my app anyway, so it's better to learn about the avi lib first. I have found a nice tutorial http://www.shrinkwrapvb.com/avihelp/avihlp_1.htm for VB which explains the basics, I shouldn't have too much trouble in PB.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Save to Video
Code: Select all
;d'un code écrit en c++ par son auteur Chiew Heng Wah
#streamtypeAUDIO = $73647561
#streamtypeVIDEO = 1935960438
#ICMF_CHOOSE_KEYFRAME = 1
#ICMF_CHOOSE_DATARATE = 2
#AVIERR_OK = 0
#AVIIF_KEYFRAME = $10
#BmpFile = 20
#AviFile = 30
Global sgAvi32Lib.s = "C:\WINDOWS\system32\avifil32.dll"
Global sgPat.s = ""
Global igIndex.i = 0
Global bgVal.b = 0
Global sgAviFile.s = ""
Structure bitmap24
bmiHeader.BITMAPINFOHEADER
EndStructure
Structure msvc
a.b
b.b
c.b
d.b
EndStructure
Structure AVI_STREAM_INFO
fccType.l
fccHandler.msvc
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.RECT
dwEditCount.l
dwFormatChangeCount.l
szName.b[64]
EndStructure
Structure AVI_COMPRESS_OPTIONS
fccType.l
fccHandler.l
dwKeyFrameEvery.l
dwQuality.l
dwBytesPerSecond.l
dwFlags.l
*lpFormat.l
cbFormat.l
*lpParms.l
cbParms.l
dwInterleaveEvery.l
EndStructure
Global bi.BITMAPINFOHEADER
Global Opts.AVI_COMPRESS_OPTIONS
Global pFile.IAVIFILE
Global pStream
Global strhdr.AVI_STREAM_INFO
; ==== VB Syntax ====
; AVIFileInit()
; AVISaveOptions(ByVal hwnd As IntPtr, ByVal flags As UInt32, ByVal nStreams As Integer, ByRef ptr_ptr_avi As IntPtr, ByRef ao As Integer) As Integer 'AVI_COMPRESS_OPTIONS)
; 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
; AVIMakeCompressedStream(ByRef ppsCompressed As Long, ByRef psSource As Long, ByRef lpOptions As AVI_COMPRESS_OPTIONS, ByVal pclsidHandler As Long) As Long
; AVIFileOpen(ByRef ppfile As Int32, ByVal szFile As String, ByVal uMode As Int32, ByVal pclsidHandler As Int32) As Int32
; AVIFileGetStream(ByVal pfile As Int32, ByRef ppavi As IntPtr, ByVal fccType As Int32, ByVal lParam As Int32) As Int32
; AVIStreamStart(ByVal pavi As Int32) As Int32
; AVIStreamLength(ByVal pavi As Int32) As Int32
; AVIStreamInfo(ByVal pAVIStream As Int32, ByRef psi As AVISTREAM_INFO, ByVal lSize As Int32) As Int32
; AVIStreamGetFrameOpen(ByVal pAVIStream As IntPtr, ByRef bih As BITMAPINFOHEADER) As Int32
; AVIStreamGetFrame(ByVal pGetFrameObj As Int32, ByVal lPos As Int32) As Int32
; AVIFileCreateStream(ByVal pfile As Int32, ByRef ppavi As IntPtr, ByRef ptr_streaminfo As AVISTREAM_INFO) As Int32
; AVIStreamSetFormat(ByVal aviStream As IntPtr, ByVal lPos As Int32, ByRef lpFormat As BITMAPINFOHEADER, ByVal cbFormat As Int32) As Int32
; AVIStreamWrite(ByVal aviStream As IntPtr, ByVal lStart As Int32, ByVal lSamples As Int32, ByVal lpBuffer As IntPtr, ByVal cbBuffer As Int32, ByVal dwFlags As Int32, ByVal dummy1 As Int32, ByVal dummy2 As Int32) As Integer
; AVIStreamGetFrameClose(ByVal pGetFrameObj As Integer) As Integer
; AVIStreamRelease(ByVal aviStream As IntPtr) As Integer
; AVIFileRelease(ByVal pfile As Integer) As Integer
; AVIFileExit()
Prototype AVIFileInit()
Prototype AVISaveOptions(iHwnd.i,iFlags.i,iNstreams.i,ptrAvi,iOpts.i)
Prototype AVISaveVA(sFileSave.s,iPclsidhandler.i,iLpfncallback,iNstreams.i,iPpavistream.i,iPpcompoptions.i)
Prototype AVIMakeCompressedStream(iPpsCompressed.i,iPsSource.i,LpOptions.i,iPclsidHandler.i)
Prototype AVIFileOpen(iPfile.i,sFileOpen.s,iUmode.i,iPclsidHandler.i)
Prototype AVIFileGetStream(ipfileStream.i,ptr_avi,iFccType.i,iLParam.i)
Prototype AVIStreamStart(iPavi.i)
Prototype AVIStreamLength(iPavi.i)
Prototype AVIStreamInfo(iPaviStream.i,psi.i,iLsize.i)
Prototype AVIStreamGetFrameOpen(ptrAviStream,BitmapHeader)
Prototype AVIStreamGetFrame(iPGetFrameObj.i,iLpos.i)
Prototype AVIFileCreateStream(ptrAviFile,ptrAviStream,ptrStreamInfo)
Prototype AVIStreamSetFormat(ptrAviStream,iLpos.i,LpFormat,iCbFormat.i)
Prototype AVIStreamWrite(ptrAviStream,iLstart.i,iLsamples.i,ptrLpBuffer,iCbBuffer.i,iDwFlags.i,iDummy1.i,iDummy2.i)
Prototype AVIStreamGetFrameClose(iPGetFrameObj.i)
Prototype AVIStreamRelease(ptrAviStream)
Prototype AVIFileRelease(iPfile.i)
Prototype AVIFileExit()
Global AVIFileInit.AVIFileInit
Global AVISaveOptions.AVISaveOptions
Global AVISaveVA.AVISaveVA
Global AVIMakeCompressedStream.AVIMakeCompressedStream
Global AVIFileOpen.AVIFileOpen
Global AVIFileGetStream.AVIFileGetStream
Global AVIStreamStart.AVIStreamStart
Global AVIStreamLength.AVIStreamLength
Global AVIStreamInfo.AVIStreamInfo
Global AVIStreamGetFrameOpen.AVIStreamGetFrameOpen
Global AVIStreamGetFrame.AVIStreamGetFrame
Global AVIFileCreateStream.AVIFileCreateStream
Global AVIStreamSetFormat.AVIStreamSetFormat
Global AVIStreamWrite.AVIStreamWrite
Global AVIStreamGetFrameClose.AVIStreamGetFrameClose
Global AVIStreamRelease.AVIStreamRelease
Global AVIFileRelease.AVIFileRelease
Global AVIFileExit.AVIFileExit
AviLib = OpenLibrary(#PB_Any,sgAvi32Lib)
If AviLib
AVIFileInit = GetFunction(AviLib,"AVIFileInit")
AVISaveOptions = GetFunction(AviLib,"AVISaveOptions")
AVISaveVA = GetFunction(AviLib,"AVISaveVA")
AVIMakeCompressedStream = GetFunction(AviLib,"AVIMakeCompressedStream")
AVIFileOpen = GetFunction(AviLib,"AVIFileOpen")
AVIFileGetStream = GetFunction(AviLib,"AVIFileGetStream")
AVIStreamStart = GetFunction(AviLib,"AVIStreamStart")
AVIStreamLength = GetFunction(AviLib,"AVIStreamLength")
AVIStreamInfo = GetFunction(AviLib,"AVIStreamInfo")
AVIStreamGetFrameOpen = GetFunction(AviLib,"AVIStreamGetFrameOpen")
AVIStreamGetFrame = GetFunction(AviLib,"AVIStreamGetFrame")
AVIFileCreateStream = GetFunction(AviLib,"AVIFileCreateStream")
AVIStreamSetFormat = GetFunction(AviLib,"AVIStreamSetFormat")
AVIStreamWrite = GetFunction(AviLib,"AVIStreamWrite")
AVIStreamGetFrameClose = GetFunction(AviLib,"AVIStreamGetFrameClose")
AVIStreamRelease = GetFunction(AviLib,"AVIStreamRelease")
AVIFileRelease = GetFunction(AviLib,"AVIFileRelease")
AVIFileExit = GetFunction(AviLib,"AVIFileExit")
NewList bitmap.s()
NewList memoire.l()
sgPat = "Image Files (*.BMP *.bmp)|*.BMP;*.bmp"
Images.s = OpenFileRequester("Select multiple Bitmap Images", "", sgPat, 0, #PB_Requester_MultiSelection)
If Images
AddElement(bitmap())
bitmap() = Images
Repeat
Images = NextSelectedFileName()
If Images
AddElement(bitmap())
bitmap() = Images
EndIf
Until Images = ""
EndIf
ForEach bitmap()
If ReadFile(#BmpFile, bitmap())
FileSeek(#BmpFile, SizeOf(BITMAPFILEHEADER))
bmi.bitmap24
ReadData(#BmpFile, @bmi, SizeOf(bitmap24))
If bmi\bmiHeader\biWidth
If bmi\bmiHeader\biHeight
If bmi\bmiHeader\biBitCount
If bmi\bmiHeader\bisizeimage = 0
bmi\bmiHeader\bisizeimage = (Lof(#BmpFile) - 54)
EndIf
FileSeek(#BmpFile,1078)
AddElement(memoire())
memoire() = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, bmi\bmiHeader\bisizeimage)
ReadData(#BmpFile,memoire(), bmi\bmiHeader\bisizeimage)
EndIf
EndIf
EndIf
CloseFile(#BmpFile)
EndIf
Next
AVIFileInit()
; sgPat = "AVI Movie File (*.AVI *.avi)|*.AVI;*.avi"
;sgAviFile = SaveFileRequester("Enter AVI File Name", "", sgPat, 0)
sgAviFile = "C:\Temp\Test1.avi"
;If(GetExtensionPart(sgAviFile) = "") : sgAviFile = sgAviFile + ".avi" : EndIf
If AVIFileOpen(@pFile,sgAviFile,(#OF_WRITE|#OF_CREATE),0) = 0
strhdr\fccType = #streamtypeVIDEO
strhdr\fccHandler\a = $6D
strhdr\fccHandler\b = $73
strhdr\fccHandler\c = $76
strhdr\fccHandler\d = $63
strhdr\dwScale = 1
strhdr\dwRate = 4 ;##Frames per second(1 to 30)
strhdr\dwSuggestedBufferSize = (3 * (bmi\bmiHeader\biHeight * bmi\bmiHeader\biWidth))
strhdr\rcFrame\top = 0
strhdr\rcFrame\left = 0
If SetRect_(strhdr\rcFrame,0,0,bmi\bmiHeader\biWidth,bmi\bmiHeader\biHeight) <> 0
If AVIFileCreateStream(pFile,@pStream,@strhdr) = 0
Dim Opts(1)
Opts(0) = @Opts
If AVISaveOptions(0, #ICMF_CHOOSE_KEYFRAME | #ICMF_CHOOSE_DATARATE, 1, @pStream, opts(0)) = 1
If AVIMakeCompressedStream(@pAVICompressed, pStream, opts(0), 0) = #AVIERR_OK
If AVIStreamSetFormat(pCompressed, 0, @bmi, SizeOf(bitmap24)) = 0
ForEach memoire()
If memoire()
If AVIStreamWrite(pCompressed, igIndex, 1, memoire(), bmi\bmiHeader\bisizeimage, #AVIIF_KEYFRAME, 0, 0) = 0
igIndex = igIndex + 1
Else
MessageRequester("Attention","AVI Stream Write call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
EndIf ;memoire()
Next
Else
MessageRequester("Attention","AVI Stream Set Format call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
AVIStreamRelease(pAVICompressed)
Else
MessageRequester("Attention","AVI Make Compressed Stream call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
Else
MessageRequester("Attention","AVI Save Options call failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
AVIStreamRelease(pAVIStream)
Else
MessageRequester("Attention","AVI create File Stream failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
Else
MessageRequester("Attention","Set frame width/height values failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
AVIStreamRelease(pAVIFile)
Else
MessageRequester("Attention","AVI File Open failed", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
AVIFileExit() ;## Release the AVI Lib
CloseLibrary(AviLib)
ForEach memoire()
GlobalFree_(memoire())
Next
MessageRequester("Info","Total number of Frames created: " + Str(igIndex))
Else
MessageRequester("Attention","Could not Open AVI Lib", #PB_MessageRequester_Ok | #MB_ICONERROR)
EndIf
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Save to Video
fixed code here
http://www.purebasic.fr/english/viewtop ... 13&t=42170
http://www.purebasic.fr/english/viewtop ... 13&t=42170
Ziltch - http://www.youtube.com/user/OZiltch