我这段代码AVIFileCreateStream参数哪里错了?(在线等)

[复制链接]
查看11 | 回复3 | 2021-1-27 05:16:41 | 显示全部楼层 |阅读模式
PrivateTypeAVI_COMPRESS_OPTIONS
fccTypeAsLong
fccHandlerAsLong
dwKeyFrameEveryAsLong
dwQualityAsLong
dwBytesPerSecondAsLong
dwFlagsAsLong
lpFormatAsLong
cbFormatAsLong
lpParmsAsLong
cbParmsAsLong
dwInterleaveEveryAsLong
EndType
PrivateTypeWAVEHDR
lpDataAsLong
dwBufferLenAsLong
dwBytesRecAsLong
dwUserAsLong
dwFlagsAsLong
dwLoopsAsLong
lpNextAsLong
ReservedAsLong
EndType
PrivateTypeWAVEFORMATEX
wFormatTagAsInteger'波形声音的格式,本人此处设置为WAVE_FORMAT_PCM
nChannelsAsInteger'通道数量,单声道为1,立体声为2
nSamplesPerSecAsLong'样本采样率,对于WAVE_FORMAT_PCM通常为8.0kHz,11.025kHz,22.05kHz和44.1kHz
nAvgBytesPerSecAsLong'forbufferestimation*/
nBlockAlignAsInteger'blocksizeofdata
wBitsPerSampleAsInteger'//每个样本的BIT数目,一般为16
biSizeAsInteger'//额外信息的大小,以字节为单位,添加在
EndType
ConstWAVE_FORMAT_PCM=1'这一块的const都是我写的
ConstWHDR_BEGINLOOP=4
ConstWHDR_DONE=1
ConstWHDR_ENDLOOP=8
ConstWHDR_INQUEUE=&H10
ConstWHDR_PREPARED=2
GlobalConstAVIERR_OKAsLong=0&
GlobalConstOF_WRITEAsLong=&H1
GlobalConstOF_CREATEAsLong=&H1000
GlobalConstAVIIF_KEYFRAMEAsLong=&H10
GlobalConstDATARATEAsLong=&H280
GlobalConstICMF_CHOOSE_KEYFRAMEAsLong=&H1
GlobalConstICMF_CHOOSE_DATARATEAsLong=&H2
DimresAsLong,pfileAsLong,psAsLong,psCompressedAsLong,pOptsAsLong
Dimps2AsLong,psCompressed2AsLong,pOpts2AsLong'这一行是自己写的
DimbmpAscDIB,strhdrAsAVI_STREAM_INFO,BIAsBITMAPINFOHEADER,optsAsAVI_COMPRESS_OPTIONS,avifileAsString
DimwavAscWAV,WHAsWAVEHDR,opts2AsAVI_COMPRESS_OPTIONS'这一行是自己写的
Dimstrhdr2AsWAVEFORMATEX'AVI_STREAM_INFO'
'转Integer数组到byte数组用的
PrivateDeclareSubCopyMemoryLib"kernel32"Alias"RtlMoveMemory"(DestinationAsAny,SourceAsAny,ByValLengthAsLong)
'转Integer数组到byte数组用的
PublicFunctionStartDecode(hwndAsLong,baseAsString,pathAsString,fps%)AsBoolean
avifile=path:AVIFileInit:res=AVIFileOpen(pfile,path,OF_WRITEOrOF_CREATE,0&)
If(resAVIERR_OK)Then
EndDecode
ExitFunction
EndIf
Setbmp=NewcDIB
Ifbmp.CreateFromFile(base)TrueThen
MsgBox"Couldnotloadfirstbitmapfileinlist!",vbExclamation,App.title
EndDecode
ExitFunction
EndIf
Withstrhdr
.fccType=mmioStringToFOURCC("vids",0&)
.fccHandler=0&
.dwScale=1
.dwRate=Val(fps)
.dwSuggestedBufferSize=bmp.SizeImage
SetRect.rcFrame,0,0,bmp.Width,bmp.Height
EndWith
Ifstrhdr.dwRate30Thenstrhdr.dwRate=30
res=AVIFileCreateStream(pfile,ps,strhdr)
If(resAVIERR_OK)Then
EndDecode
ExitFunction
EndIf
Withstrhdr2
.wFormatTag=1
.nChannels=Val(2)
.wBitsPerSample=Val(16)
.nSamplesPerSec=Val(44100)'采样率
.nAvgBytesPerSec=Val(176400)'WAVE声音中每秒的数据量(CLng(cboSamplerate.Text)*(2*(chkStereo.value+1)))=44100*(2*(1+1))
.nBlockAlign=(10240)'数据块的对齐标志
.biSize=14'此结构的大小
EndWith'SetFormatVarPtr(wfx),Len(wfx),"44.1kHz16BitStereo","PCM"
Dimstrhdr3AsAVI_STREAM_INFO
Withstrhdr3
.fccType=mmioStringToFOURCC("auds",0&)
.fccHandler=1&
.dwScale=Val(10240)
.dwRate=Val(176400)
.dwSuggestedBufferSize=bmp.SizeImage
'SetRect.rcFrame,0,0,bmp.Width,bmp.Height
EndWith
'updaterecordedtime
'lngMSEncoded=lngMSEncoded+((lngLen/lngBytesPerSec)*1000)
res=AVIFileCreateStream(pfile,ps2,strhdr3)
If(resAVIERR_OK)Then
EndDecode
ExitFunction
EndIf
Dimb()AsByte,iAsLong
'ReDimb(Len(strhdr2)*2-1)
'Fori=0ToUBound(intSamples)
'CopyMemoryb(i*2),intSamples(i),ByVal2'LenB(intSamples(i))
'Next
res=AVIStreamSetFormat(ps2,0,ByValVarPtr(strhdr2),Len(strhdr2))
If(resAVIERR_OK)Then
EndDecode
ExitFunction
EndIf
pOpts=VarPtr(opts)
res=AVISaveOptions(hwnd,ICMF_CHOOSE_KEYFRAMEOrICMF_CHOOSE_DATARATE,1,ps,pOpts)
Ifres1Then
AVISaveOptionsFree1,pOpts
EndDecode
ExitFunction
EndIf
res=AVIMakeCompressedStream(psCompressed,ps,opts,0&)
IfresAVIERR_OKThen
EndDecode
ExitFunction
EndIf
WithBI
.biBitCount=bmp.BitCount
.biClrImportant=bmp.ClrImportant
.biClrUsed=bmp.ClrUsed
.biCompression=bmp.Compression
.biHeight=bmp.Height
.biWidth=bmp.Width
.biPlanes=bmp.Planes
.biSize=bmp.SizeInfoHeader
.biSizeImage=bmp.SizeImage
.biXPelsPerMeter=bmp.XPPM
.biYPelsPerMeter=bmp.YPPM
EndWith
res=AVIStreamSetFormat(psCompressed,0,ByValbmp.PointerToBitmapInfo,bmp.SizeBitmapInfo)
If(resAVIERR_OK)Then
EndDecode
ExitFunction
EndIf
'Setwav=NewcWAV
'Ifwav.CreateFromFile(App.path&"\t.wav")=TrueThen
'EndDecode
'ExitFunction
'EndIf
'DimmWFeXAsWAVEFORMATEX
'.nBlockAlign=.nSamplesPerSec*.wBitsPerSample'blocksizeofdata(_wfx.wBitsPerSample*_wfx.nChannels)>>3;
'.nAvgBytesPerSec=.nBlockAlign*.nSamplesPerSec'/*forbufferestimation*/_wfx.nBlockAlign*_wfx.nSamplesPerSec;
'.cbSize=0'额外信息的大小,如果没有额外信息可为0'

StartDecode=1
EndFunction
PublicSubDecode(ByValIndexAsInteger,ByValfileAsString)
bmp.CreateFromFile(file)
res=AVIStreamWrite(psCompressed,Index,1,bmp.PointerToBits,bmp.SizeImage,AVIIF_KEYFRAME,ByVal0&,ByVal0&)
IfresAVIERR_OKThenEndDecode
EndSub
PublicSubDecode2(ByValIndexAsInteger,ii()AsInteger)'我写的录入音频
'Dimb()AsByte,iAsLong
'DimBuffer(3)AsByte
'a=Val(Text1)CopyMemoryBuffer(0),a,4
'Fori=0ToUBound(ii)
'b(i)=CByte(ii)
'Next
Dimb()AsByte
DimiAsLong
ReDimb((UBound(intSamples)+1)*2-1)
Fori=0ToUBound(intSamples)
CopyMemoryb(i*2),intSamples(i),ByVal2'LenB(intSamples(i))
Next
res=AVIStreamWrite(ps2,Index,1,b,intSamplesSize,AVIIF_KEYFRAME,ByVal0&,ByVal0&)'AVIIF_KEYFRAMEAVIIF_DATARATE
IfresAVIERR_OKThenEndDecode
EndSub
分 -->
回复

使用道具 举报

千问 | 2021-1-27 05:16:41 | 显示全部楼层
把图片写入avi文件没有问题可以显示,就是把音频写入avi不会发声,只有图像没有声音。谁能指点一下写音频的关健地方吗
回复

使用道具 举报

千问 | 2021-1-27 05:16:41 | 显示全部楼层
帅哥.音频问题搞掂了没?我下载了你的VB6实现屏幕和音频都录入合成avi音影视听的源码实例,但没窗体.我想说的不是这个.我一直在找你的联系方式,但没有.音频问题我也被搞疯掉了.如果你搞掂了.麻烦跟我联系一下.有谢礼啊.如果能将语言聊天保存为avi文件(即电话录音),一个远程音频采集传输到本机+本机采集.能入保存为avi文件(时间线要统一).请与我联系.Q452781589重谢
回复

使用道具 举报

千问 | 2021-1-27 05:16:41 | 显示全部楼层
https://blog.csdn.net/jinboker/article/details/52128276?utm_source=distribute.wap_relevant.none-task
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行