Log in

View Full Version : AviSynth framecount issue


Cyberia
2nd June 2003, 00:27
I am writing an application that uses a mediaplayer ocx control, and from the control I determine the timelength and framecount of the playing video.

If I open an avi directly through the mediaplayer ocx, it reports the correct file attributes... the same than VirtualDub reports, that is.

But if I open the avi through an avs script, the player reports the the timecount for BOTH timecount AND framecount. The timecount value is correctly reported, but I don't want it twice.

Virtual dub reports the correct values for the file opened through Avisynth.

The avs script is very simple:

AVISource(myfile.avi)


Although this could be a mediaplayer bug, it sounds like maybe AviSynth isn't reporting the framecount in the manner mediaplayer (ocx) wants it. Shouldn't AviSynth scripts work transparently in ANY application?

Cyberia
2nd June 2003, 18:30
Ok, massive response so far.

Lets try tackling this from another angle: Does any have (or know of)an example on how to query the AVIFile or AVIStream API's from VB6?

I have code trying to do this, but it returns inconsistent values between clips. I'd just like to see someone do it properly. Actually, even if you can't do that, can you tell me what calls I *should* be making in the correct order? (AVIFileOpen, then AVIFileInit, ... read the struct ... AVIFileClose)

I don't want to play the avi in this way, just to determine it's basic properties (height, width, framecount, timelength etc)

Sorry if I am being retarded.

Cyberia
3rd June 2003, 04:01
Nevermind, I got it. Actually I had it, but had a typo.

Thanks to everyone who responded! Out of gratitude for all you help I have decided to give everyone who has posted so far ALL THE MONEY I HAVE. Couldn't have done it without you.

You know who you are.

EDIT: If anyone is interested, I decided to release an example. So here it is: AviStreamInfo using VB6 (http://home.insightbb.com/~cyberia-1/ASI/AviStreamInfo.rar)

fisix
8th June 2003, 07:01
yay!

show me the money?

-fiz

sh0dan
8th June 2003, 17:13
@Cyberia: I don't know anyone here who works with VB, so that may be the reason for the lack of responses. Glad you got it resolved in the end!

@fisix: Remember rule 11, please.

Cyberia
8th June 2003, 19:30
@fisix: Sorry the offer was only good until I posted the code. Too Bad.

@Shodan: Yea, I understand most people are not coding in VB, but all I needed was the name and order of the API calls (in any language) and I could transcode it to VB. I think most people would be surprised at how fast and powerful VB is now (obviously NOT for intensive apps, but for small simple apps its GREAT)

FYI: There are FIVE API calls necessary for this operation - (EDITED)
AviFileInit
AviStreamOpenFromFile
AviStreamInfo
AviStreamRelease <--- Dont forget this one!!
AviFileExit

Cyberia
10th June 2003, 18:37
Crap. There is a BAD BAD BAD memory leak in the posted code. This is such a stupid mistake, sigh.

I completely forgot to release the stream when finished. The problem gets worse as you try to test more and more videos because the previous stream was not freed, but a new stream is created every time you scan a file. Fortunately, it seems that all memory is returned to the system when you close the program.

I have the fix ready and will put it up when I get home tonight. So in the off chance anyone has looked at the code, don't use it. Get the update.

EDIT: The update is now available at the above link.

sh0dan
10th June 2003, 18:42
Heh - A very easy thing to forget. ;)

Anyway - thanks for sharing your code - I'm sure it'll be appreciated!

vion11
16th March 2004, 10:32
The example exits with err=28 "Out of stack space" at line:

Call AVIStreamRelease(ByVal pavi)

in function LoadAviStreamInfo() and no framecount is reported.

Whats wrong?

Cyberia
5th April 2004, 18:33
Well, I'm not sure. What file are you trying to scan? Can Vdub open it and get a File Information from it?

Reboot and try again. It should work.

vion11
7th April 2004, 15:21
Using "version()" as script still same error.
Type AviStreamInfoStruct has good values, next
lines relases bad to reported error.

More Infos???

vion11
16th April 2004, 13:28
Example works with AviSynth version 2.08.
First not working version I've found is beta 2.5 (jan2003)

Can somebody verify/falsify this fact please!

For handyness the test exe from cyberia: Link (http://innerphase.de/AVEditor/AviStreamInfo.exe)

Access to AVIFile library is necessary to extract and
display frames from avs files => per filter preview in editors.

sh0dan
16th April 2004, 14:43
:confused:

The example loads an avs nicely with 2.5 (i tried simply putting a version() in the avs).

vion11
16th April 2004, 19:27
:confused: :confused: Hmmh local error.
But why difference between versions?

How can I reinstall/check/test avi support (w2k)?
(want to avoid complete system new install)

Cyberia
16th April 2004, 22:19
Shodan, thanks for confirming what I was seeing. I simply CAN'T get it to break at all. I am running WinXP, but the call that is failing (AVIStreamRelease) was present in Win95 and up according to the MSDN.

vion11
19th April 2004, 16:17
Checking other ressources/samples I have no doubt code is correct
and in addition it runs perfect with old version.

Would like to see a verification from w2k machine...

It is simple: open *.avs and when
dialog shows numbers => ok
if dialog shows N/A => nok

sh0dan
19th April 2004, 16:25
FYI I tested on an XP machine. SP1+latest patches.

vion11
19th April 2004, 19:35
It runs now, haven't find out exactly what was wrong.
(de+installed sp4, all codecs, wmp 9, wmp 6.4)

Here are exe + sources to display frames extracted
from avs file with visual basic 6.0.
Many thanks to cyberia and shrinkwrapvb.com
Link (50kb) (http://innerphase.de/aveditor/avsviewer.zip) no runtime library

Dark-Cracker
20th April 2004, 00:45
hi,

instead of SetDIBitsToDevice24 api i suggest u the DrawDibDraw api.

++

Cyberia
20th April 2004, 02:27
There is some Good Stuff™ in this code! Thanks for sharing it!

vion11
20th April 2004, 10:57
@Dark-Cracker
Can you point at some running code, please?
There is a clumsy colordepth handling with SetDIBitsToDevice24,
I'd like to optimize.

Dark-Cracker
20th April 2004, 13:46
u can use it like this :


Public Declare Function DrawDibOpen Lib "msvfw32.dll" () As Long
Public Declare Function DrawDibClose Lib "msvfw32.dll" (ByVal hDD As Long) As Long

Public Declare Function DrawDibDraw Lib "msvfw32.dll" (ByVal hDD As Long, ByVal hdc As Long, _
ByVal xDst As Long, ByVal yDst As Long, ByVal dxDst As Long, ByVal dyDst As Long, _
lpbi As Any, lpBits As Any, _
ByVal xSrc As Long, ByVal ySrc As Long, ByVal dxSrc As Long, ByVal dySrc As Long, _
ByVal wFlags As Long) As Long

'------------

call the drawdibopen only once (when u init your class).
m_hDrawDib is a global long.

'initialise the DDraw fonction
m_hDrawDib = DrawDibOpen()


call the drawdibclose only once (when u destroy your class).

'Close DDraw library
DrawDibClose m_hDrawDib


and use drawdibdraw like this :

DrawDibDraw(m_hDrawDib, PicBox.hdc, 0, 0, 640, 480, ByVal pDIB, ByVal 0&, 0, 0, -1, -1, 0)


640 and 480 are width and height, if u want to strech the picture u can change the -1 and -1 with the new desired size.
pDIB is the pointer on the packet dib returned by the AVIStreamGetFrame API.

hope this can help u :)

Bye.

vion11
20th April 2004, 15:07
It does! Now Displayframe() has optional stretching. Nice stuff. :)

Public Function DisplayFrame()

Dim pDIB As Long 'pointer to packed DIB in memory

pDIB = AVIStreamGetFrame(pGetFrameObj, mvarCurFrame - 1) 'returns "packed DIB"
DrawDibDraw m_hDrawDib, mvarCtlView.hdc, 0, 0, mvarCtlView.Width, _
mvarCtlView.Height, ByVal pDIB, ByVal 0&, 0, 0, -1, -1, 0
mvarCtlView.Refresh

End Function