How To Grab Frames From A Flash Movie

Artem Razin
June 14, 2008

One customer wrote to me:

Why does the GetBitmap method consume so much processor time?
It's a 720×576, 25fps simple movie, but it uses 40–60% of the CPU.
I'm calling GetBitmap without any additional processing.

Actually, GetBitmap is not an efficient method when you need to grab frames quickly from a movie.

So, what's the better approach?

Use f_in_box__control, set TransparentMode = true, and handle the OnFlashPaint event, for example:

[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory")]
private static extern void CopyMemory(IntPtr Destination, IntPtr Source, int Length); 
 
private void flashControl1_OnFlashPaint(object sender, IntPtr pPixelPointer)
{
    if (videoOut != null)
    {
        BitmapData bmd = videoOut.VideoBitmap.LockBits(
            new Rectangle(0, 0, 720, 576),
            ImageLockMode.WriteOnly,
            PixelFormat.Format32bppArgb);
 
        int StrideSize = 720 * 4;
        for (int i = 0; i < 576; i++)
        {
            IntPtr s = new IntPtr(pPixelPointer.ToInt32() + StrideSize * i);
            IntPtr d = new IntPtr(bmd.Scan0.ToInt32() + (StrideSize * (575 - i)));
            CopyMemory(d, s, StrideSize);
        }
 
        videoOut.PixelPointer = bmd.Scan0;
        videoOut.VideoBitmap.UnlockBits(bmd);
    }
}