Success at rendering AVI to PictureBox, now need optimization

Success at rendering AVI to PictureBox, now need optimization

Post by Roger Hyd » Sun, 25 Jan 2004 17:32:42


Okay, here's the goal. I want to be able to load and playback AVI
files in a simple OCX of my own design, without any dependency on
other non-standard controls or dll servers. So far, this has meant
wrapping my poor brain around various unfamiliar API's. I've achieved
success at drawing AVI frames into a PictureBox using Ray Mercer's
AVIFile and cDIB, with StretchDIBits cobbled into cDIB to provide
scaling/drawing functionality. Now I have a problem of speed - well,
two problems, really:

1. How do I achieve high-resolution timing so that I'm not stuck with
the slow Timer control, but without relying on another OCX or dll?

2. How do I then speed up drawing the frames so that it can handle
the higher timer resolution and play back at the proper speed?

For speeding up drawing, I've seen a solution that I think might work
which uses a memory DC to buffer the video into, but the example I saw
used a dll and was beyond my ability to pick apart for my own use.
That was at
http://www.yqcomputer.com/

As to the timer issue, the only solutions I've seen so far require the
use of an OCX or dll. I really need this to be in a class or module
that will compile right into my "standalone" OCX.

If anyone is willing to spend some time bringing a graphics
programming newbie up to speed (no pun intended) on these issues, I
would really appreciate the effort!

Thanks,
RH
 
 
 

Success at rendering AVI to PictureBox, now need optimization

Post by Johan St » Tue, 27 Jan 2004 23:36:17


http://www.yqcomputer.com/

Re 1, I can tell you what I do myself:
I have developed a low-level AVI-player myself
When playing an AVI it works like this:
For each frame, I calculate the number of milliseconds that should have
passed since the play started. (mills-per-frame*frame_number)
I compare this with the actual number of
milliseconds that has passed (using TimeGetTime).
If I have arrived early, I calculate how many mills early I am, and issue a
sleep() command to wait until
"the time is right".
This scheme works very well.

/Johan S

 
 
 

Success at rendering AVI to PictureBox, now need optimization

Post by Roger Hyd » Wed, 28 Jan 2004 17:46:00

On Mon, 26 Jan 2004 15:36:17 +0100, "Johan Stk"



Thanks for the tip. And how are you implementing this method? Are
you using a do while loop? If you could share some code (or at least
pseudo-code) outlining your process I would be grateful. I sometimes
learn best by example:)

Of course, that still leaves me with the problem of getting frames
drawn more quickly. I think that is the real bottleneck in my process
right now, since I don't believe I'm getting the fidelity of even the
standard timer in my playback! Johan, if you've written a player then
perhaps you could give some advice on this?

Thanks,
RH
 
 
 

Success at rendering AVI to PictureBox, now need optimization

Post by Mike D Sut » Wed, 28 Jan 2004 17:54:06

> Thanks for the tip. And how are you implementing this method? Are

Sleep() is an API call that 'sleeps' the thread for a number of milliseconds:

'***
Private Declare Sub Sleep Lib "Kernel32.dll" (ByVal dwMilliseconds As Long)

...

' Sleep for a second)
Call Sleep(1000)
'***

Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: XXXX@XXXXX.COM
WWW: http://www.yqcomputer.com/
 
 
 

Success at rendering AVI to PictureBox, now need optimization

Post by Roger Hyd » Wed, 28 Jan 2004 19:08:26

On Tue, 27 Jan 2004 08:54:06 -0000, "Mike D Sutton" < XXXX@XXXXX.COM >




I was actually referring to how he implements the whole play routine
and not just the sleep() function. But thanks all the same:D

I'm beginning to think I'd be better off just figuring out how to use
MCISendString. Passing strings around doesn't sound like an ideal way
of playing video, but does seem a bit less of a hurdle! (I'd still
like to know how to do without it, though)

RH
 
 
 

Success at rendering AVI to PictureBox, now need optimization

Post by Johan St » Thu, 29 Jan 2004 15:36:27

To play an AVI file, you program a loop.

for i = start_frame to end frame
calculate_eventual_sleep_time
display_the_frame
next i

To display the frames, I use DrawDibDraw, which has the advantage for
AVI:s that it first will call the relevant VfW codec, and then draw the
decompressed frame. It will draw to a picture box, or to an off-screen
buffer for further treatment, depending on you needs....
Performance is certainly not as good as Direct/X, but good enough.
My new 2,4 Ghz PC will display about 60 DV frames/second using this
method (given that I "losen all the brakes").

My own resaon for doing this (and more) at low level, is that I want to
do things with my AVI files that no higher-level routines (that I know
of) allow.
I perform various updates of non_video chunks in my AVI files.
If all you want is to play an AVI file as-is, there might be easier ways.
Also, I don't use any sound (at least not emanating from audio streams
in the AVI:s)

/Johan
 
 
 

Success at rendering AVI to PictureBox, now need optimization

Post by Roger Hyd » Thu, 29 Jan 2004 21:04:18

On Wed, 28 Jan 2004 07:36:27 +0100, Johan Stk < XXXX@XXXXX.COM >



Thank you, that was very instructive. Custom processing was the
original motivation for wanting to write my own player, so I will
definitely look into DrawDibDraw. I just wrapped up making a player
control using mciSendString, but since it offers no access to the AVI
frames, it is not ultimately what I had hoped for...until I can finish
my low-level player, it will suffice. Fortunately audio is not really
a requirement for me at this time, so that will probably save me some
headaches!

Thanks again for all the advice

RH