News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using AVIStream for creating a video

Started by Farabi, March 26, 2010, 11:07:28 PM

Previous topic - Next topic

Farabi

Is this right?





AVISTREAMINFO struct
fccType dword 0
fccHandler dword 0
dwFlags dword 0
dwCaps dword 0
wPriority word 0
wLanguage word  0
dwScale dword 0
dwRate DWORD 0
dwStart DWORD 0
dwLength DWORD 0
dwInitialFrames DWORD 0
dwSuggestedBufferSize DWORD 0
dwQuality dword 0
dwSampleSize dword 0
rcFrame RECT <0>
dwEditCount dword 0
dwFormatChangeCount dword 0
szName dword [64]
AVISTREAMINFO ends

iAVIFILE struct
CreateStream dword 0
EndRecord dword 0
GetStream dword 0
Info dword 0
Open dword 0
ReadData dword 0
WriteData dword 0
iAVIFILE ends

TAviUtil struct
pfile dword 0
wfx WAVEFORMATEX <0>
period dword 0
as dword 0
ps dword 0
psCompressed dword 0
nframe dword 0
nsamp dword 0
iserr dword 0
TAviUtil ends



AVICOMPRESSOPTIONS struct
fccType dword 0
fccHandler dword 0
dwKeyFrameEvery dword 0
dwQuality dword 0
dwBytesPerSecond dword 0
dwFlags dword 0
lpFormat dword 0
cbFormat dword 0
lpParms dword 0
cbParms dword 0
dwInterleaveEvery dword 0
AVICOMPRESSOPTIONS ends

.code


fCreateAVI proc uses esi edi lpFileName:dword,nFramePeriode:dword,wfx:dword
LOCAL au:dword

invoke fvAVIFileInit
  invoke mAlloc,sizeof TAviUtil
mov esi,eax

invoke fvAVIFileOpen,addr [esi].TAviUtil.pfile,lpFileName,OF_WRITE or OF_CREATE,0
.if eax!=0
invoke fvAVIFileExit
ret
.endif

lea edx,[esi].TAviUtil.wfx
invoke memfill,edx,sizeof WAVEFORMATEX,0

push nFramePeriode
pop [esi].TAviUtil.period

push 0
pop [esi].TAviUtil.as
push 0
pop [esi].TAviUtil.ps
push FALSE
pop [esi].TAviUtil.iserr

mov eax,esi

ret
fCreateAVI endp

fAddFrame proc uses esi edi  avi:dword,hbmp:dword,hWnd:dword
LOCAL stdhdr:AVISTREAMINFO
LOCAL b:DIBSECTION
LOCAL op:AVICOMPRESSOPTIONS
LOCAL r:RECT
LOCAL buff[256] :dword


invoke GetObject,hbmp,sizeof DIBSECTION ,addr b
invoke memfill,addr stdhdr,sizeof stdhdr,0
mov esi,avi

.if [esi].TAviUtil.ps==0
push "SDIV"
pop stdhdr.fccType
push 0
pop stdhdr.fccHandler
push [esi].TAviUtil.period
pop stdhdr.dwScale
push 1000
pop stdhdr.dwRate
push b.dsBmih.biSizeImage
pop stdhdr.dwSuggestedBufferSize

invoke SetRect,addr stdhdr.rcFrame,0,0,b.dsBmih.biWidth,b.dsBmih.biHeight
invoke fvAVIFileCreateStream,[esi].TAviUtil.pfile,addr [esi].TAviUtil.ps,addr stdhdr
.if eax!=0
invoke PERR
.endif
.endif


.if [esi].TAviUtil.psCompressed==0
invoke memfill,addr op,sizeof AVICOMPRESSOPTIONS,0
mov eax,"XVID"
;bswap eax
mov op.fccHandler,eax
;----------------------------------------------------------------------------------------------------------------------------------
;              SOMETHING WAS WRONG HERE
invoke fvAVIMakeCompressedStream,addr [esi].TAviUtil.psCompressed,[esi].TAviUtil.ps,addr op,0
; .if eax!=0
; mov ecx,eax
; invoke dw2hex,ecx,addr buff
; invoke SetWindowText,hWnd,addr buff
; .endif
invoke dw2hex,[esi].TAviUtil.psCompressed,addr buff
invoke SetWindowText,hWnd,addr buff
ret
;-------------------------------------------------------------------------------------------------------------------
mov ecx,b.dsBmih.biClrUsed
shl ecx,2
add ecx,b.dsBmih.biSize
invoke fvAVIStreamSetFormat,[esi].TAviUtil.psCompressed,0,addr b.dsBmih,ecx
.if eax!=0
invoke PERR
.endif

.endif

invoke AVIStreamWrite,[esi].TAviUtil.psCompressed,[esi].TAviUtil.nframe,1,b.dsBm.bmBits,b.dsBmih.biSizeImage,AVIIF_KEYFRAME,0,0
.if eax!=0
invoke PERR
.endif

inc [esi].TAviUtil.nframe


ret
fAddFrame endp

fCloseAVI proc uses esi edi hAvi:dword
LOCAL buff[256]:dword

mov esi,hAvi
.if [esi].TAviUtil.as!=0
invoke fvAVIStreamRelease,[esi].TAviUtil.as
.endif
mov [esi].TAviUtil.as,0
.if [esi].TAviUtil.psCompressed!=0
invoke fvAVIStreamRelease,[esi].TAviUtil.psCompressed
.endif
mov [esi].TAviUtil.psCompressed,0
.if [esi].TAviUtil.pfile !=0
invoke fvAVIFileRelease, [esi].TAviUtil.pfile
.endif
mov [esi].TAviUtil.pfile,0
invoke fvAVIFileExit
invoke GlobalFree,esi

ret
fCloseAVI endp

The original code is here http://www.wischik.com/lu/programmer/avi_utils.html


Not just doesnot write anything also, the close avi file is crashed.

[edit]Oke got it working[/edit]
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

It seems the avifil32.lib is broken, can somebody do something?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Anyone can point where is my mistake? When I used the XVID codec it access a wrong memory address, it point to 0 and I dont know why.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Oke I got it working, but there are problem here, the header is blank, the first 2kb part is filled with 0, dont know where is my mistake is.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

For those who want to experimenting, I uploaded the include file.

How to Use


.data
vw dword 0
.code
.elseif WM_CREATE
invoke fCreateAVI,CADD("test.avi"),1000/20,0
mov vw,eax

; How to Add Frame
invoke fAddFrame,vw,fb.bmp,hWnd

; How to Close and Save
invoke fCloseAVI,vw


If this code works on your system, it mean, I installed a bad codecs.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

#5
@ Everyone: THIS APP IS VERY UNSAFE.... I will delete this message after Farabi has tested app if I have access rights, it is just a test app to help with this topic, sorry no code either, this is just an Alpha test :P

Hey Farabi,

Follow instructions in pm carefully, as I said very dodgy build nothing is checked so will error all over the place if not setup exactly as pm

EDIT: lol only 8 downloads
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

hmm if you had folders/files etc setup in pm as I said I dont know why.... those folders / files must be in c drive and must exist.... If I get a chance today I'll add error checking for you
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

oex

OK again possibly rushed and dodgy code but some limited error checking now and additional checking files:

put the folder 'bmps' in the c:\ drive and run the app.... it should bring up a format dialog and then create c:\test.avi
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

it does work, but not with all the codecs

oex

ah yes I should have said that.... I have the same issue.... I dont know why yet but it does work with some (Microsoft 1) for example for me and uncompresed
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

i use the k-lite mega codec pack
it works with ffdshow   :bg
but not xVid or DivX   :(
for those, it creates the AVI, but only 1 of the 2 frames show up

oex

What is a good generic format? It's all very well creating with better codecs but like image formats you want something that's also universally accepted

PS. Yes my cartoon skills are for hire but you probably cant afford me :lol
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

i don't know about the word "generic" - lol
but DivX and xVid are the formats of choice
they create a good quality video with good compression (xVid probably the best)
i think those 2 formats are very similar, so if you get one working, the other will probably follow

don't feel bad - i can't draw, either
but, i can write a program to do it for me   :bg