Non mais c'est vrai que si Erix14 ne l'avait pas demandé, je ne serais pas allé plus loin, je ne serais pas un peu influençable moi, du coup.
Créer vos videos AVI avec de l'audio.
Vous aurez remarqué que l'on fait appel à une boite de dialogue pour le choix du codec vidéo, maintenant on peut s'en passer avec ce programme qui permet de lister les codecs installés sur la machine.
Le code ci dessus vous sera utile pour déterminé quel codec vous souhaitez pour l'encodage.
#ICMODE_QUERY = 4
#Lib =0
Structure ICINFO
dwSize.l
fccType.l
fccHandler.l
dwFlags.l
dwVersion.l
dwVersionICM.l
szName.w[16]
szDescription.w[128]
szDriver.w[128]
EndStructure
Procedure.s Uni2Ansi(*Unicode.l)
size.l = WideCharToMultiByte_ ( #CP_ACP , 0, *Unicode, -1, #Null , #Null , #Null , #Null )
ansi.s= Space (size)
WideCharToMultiByte_ ( #CP_ACP , 0, *Unicode, -1, @ansi, size, #Null , #Null )
ProcedureReturn ansi
EndProcedure
Procedure.s MAKESTRING(a.l)
*pointeur.BYTE=@a
a$= Chr (*pointeur\b)
*pointeur=*pointeur+1
a$=a$+ Chr (*pointeur\b)
*pointeur=*pointeur+1
a$=a$+ Chr (*pointeur\b)
*pointeur=*pointeur+1
a$=a$+ Chr (*pointeur\b)
ProcedureReturn a$
EndProcedure
If OpenLibrary ( #Lib , "MSVFW32.dll" )
Repeat
iNext = CallFunction ( #Lib , "ICInfo" ,0, iLast, @tIC.ICINFO)
If iNext
hiC = CallFunction ( #Lib , "ICOpen" ,tIC\fccType, tIC\fccHandler, #ICMODE_QUERY )
If hiC
CallFunction ( #Lib , "ICGetInfo" , hiC, @tIC, SizeOf(ICINFO))
Debug Uni2Ansi(@tIC\szName[0])
Debug Uni2Ansi(@tIC\szDescription[0])
Debug MAKESTRING(tIC\fccHandler)
Debug "fccHandler: " + Str (tIC\fccHandler)
Debug "-------------------------"
CallFunction ( #Lib , "ICClose" , hiC)
EndIf
iLast = iLast + 1
EndIf
Until (iNext = 0)
FreeLibrary_ ( #Lib )
EndIf
Le code ci dessus vous sera utile pour déterminé quel codec vous souhaitez pour l'encodage.
#streamtypeVIDEO = $73646976
#Lib = 0
Structure bitmap24
bmiHeader.BITMAPINFOHEADER
EndStructure
Structure AVISTREAMINFO
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.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
Global bmi.bitmap24
NewList memoire.l()
Procedure MAKEFOURCC(ch0_.s, ch1_.s, ch2_.s, ch3_.s)
ch0.b= Asc ( ch0_ ):ch1.b= Asc ( ch1_ ):ch2.b= Asc ( ch2_ ):ch3.b= Asc ( ch3_ )
a=ch0 | (ch1 << 8 ) |(ch2 << 16) | (ch3 << 24 )
ProcedureReturn a
EndProcedure
Procedure Add_bmp_avi(bmp.s)
If ReadFile (0, bmp)
FileSeek (SizeOf(BITMAPFILEHEADER))
ReadData (@bmi, SizeOf(bitmap24))
If bmi\bmiHeader\biWidth
If bmi\bmiHeader\biHeight
If bmi\bmiHeader\biBitCount=24
If bmi\bmiHeader\bisizeimage=0
bmi\bmiHeader\bisizeimage= Lof ()-54
EndIf
FileSeek (54)
AddElement (memoire())
memoire() = GlobalAlloc_ ( #GMEM_FIXED|#GMEM_ZEROINIT , bmi\bmiHeader\bisizeimage)
ReadData (memoire(), bmi\bmiHeader\bisizeimage)
EndIf
EndIf
EndIf
CloseFile (0)
EndIf
EndProcedure
Procedure create_avi(chemin.s)
If CountList (memoire())
If OpenLibrary ( #Lib , "AVIFIL32.DLL" )
CallFunction ( #Lib , "AVIFileInit" )
If CallFunction ( #Lib , "AVIFileOpen" , @pAVIFile.IAVIFILE, @chemin, ( #OF_WRITE | #OF_CREATE ), 0 )=0
strhdr.AVISTREAMINFO
strhdr\fccType = #streamtypeVIDEO
strhdr\fccHandler = 0
strhdr\dwScale = 1
strhdr\dwRate = 10
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
#ICMF_CHOOSE_KEYFRAME =1
#ICMF_CHOOSE_DATARATE =2
#AVIERR_OK =0
#AVIIF_KEYFRAME =$10
opts\fccType=1667524982
;/ codec divx
opts\fccHandler=MAKEFOURCC( "d" , "i" , "v" , "x" )
;/ codec cinepak
;opts\fccHandler=MAKEFOURCC("c", "v", "i", "d")
;/ codec MICROSOFT VIDEO 1 16 bits
;opts\fccHandler=MAKEFOURCC("M", "S", "V", "C")
;/ codec MICROSOFT VIDEO MPEG4 V1
;opts\fccHandler=MAKEFOURCC("M", "P", "G", "4")
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()
Debug "popo"
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
CallFunction ( #Lib , "AVIStreamRelease" , pAVIStream )
EndIf
EndIf
CallFunction ( #Lib , "AVIFileRelease" , pAVIFile)
EndIf
CallFunction ( #Lib , "AVIFileExit" )
CloseLibrary ( #Lib )
ForEach memoire()
GlobalFree_ (memoire())
Next
EndIf
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Add_bmp_avi( "e:\nico2.bmp" )
Add_bmp_avi( "e:\nico.bmp" )
Add_bmp_avi( "e:\nico2.bmp" )
Add_bmp_avi( "e:\nico.bmp" )
Add_bmp_avi( "e:\nico2.bmp" )
Add_bmp_avi( "e:\nico.bmp" )
create_avi( "e:\test.avi" )
Re: Créer vos videos AVI avec de l'audio.
Bonjour Nico,
Très bon le second code, page 1. L'auteur Chiew Heng Wah est remerciable pour sa procédure assez conséquente. Et merci à toi, pour son intégration en PureBASIC et l'accompagnement du son.
Très bon le second code, page 1. L'auteur Chiew Heng Wah est remerciable pour sa procédure assez conséquente. Et merci à toi, pour son intégration en PureBASIC et l'accompagnement du son.