MPEG from Director For Windows FAQ

Mauricio Piacentini
Tabuleiro da Baiana Multimedia, Brasil
Internet tbaiana@embratel.net.br
Compuserve 74741,367


Well, as promised, here's some information I have compiled and discovered about MPEG playback in Director. The following scripts work with both the Reel Magic Cards and the MP400 from Creative Labs, and should work with every card that follows the Microsoft guidelines for MPEG playback under Windows. PLEASE contact me if you discover that these scripts work (or not) with other decoders, so we can compile information about them. The part of this code that gets the handler to the stage is copied from the MPEG playback example provided by Macromedia with the DLLGlue XObject. Please notice that this code works for me and should work for you, but use it on your own risk. The DLLGLUE XObject is a very powerful one and calls directly to the Windows API, and MCI controls hang or crash or system if called wrongly, so YOU HAVE BENN WARNED!!!!

First, the basics:

  1. You need a MPEG decoder to play MPEG files. I have tested the MP400 card and the Reel Magic, and both work with this tips.

  2. MPEG decoders interfaces with Windows through MCI drivers. Each MCI driver has its own set of commands, and some (like the Reel Magic) doesn't follow Microsoft's guidelines for implementation of MCI control of MPEG files. This examples works without modifications for the cards listed above.

  3. In order to retain interactivity when playing an MPEG file, you'll need to make the MPEG clip window a child of the stage. This requires the window handle of the stage window. To get the window handle you'll need the DLLGLUE Xobject from Macromedia, available from their libraries on Compuserve (filename DLLGLU.ZIP). READ THE DOCS CAREFULLY! Macromedia doesn't provide support for XObjects, so only use this techniques if you're confortable using them. The DLLGLUE.DLL should be placed in the same directory of the projector.

  4. To get rid of the annoying 'magenta flash' that always preceeds the MPEG playback on Reel Magic systems you'll have to use chromakey. The video will only show through the parts of the stage that have the color you define as the chromakey color. This way you can have elliptical movies, animation OVER the video, holes that reveal only part of the image and some other nice effects. Note that the objects that you place OVER the video area including the video area that is not displayed doesn't respond to mouse events, so leave a border to place the movie controllers.

  5. You should limit the data rate of your MPEG files to 170 kbps, otherwise performance will be compromised in 486 systems. Higher data rates movies will push the hardware a little too much and could play poorly.

  6. Use the following revision for the drivers and software:
    1. Director for Windows 4.04
    2. Real Magic Drivers v. 2.21
    3. Updated MP400 Drivers (available at Compuserve, GO BLASTER)
    4. Quicktime for Windows 2.01
    THERE IS AN INCOMPATIBILITY BETWEEN VERSIONS 2.10 - 2.20 OF THE REAL MAGIC DRIVERS AND QUICKTIME FOR WINDOWS VERSION 2.0 - 2.01. IF YOU CAN'T GET V 2.21 PLEASE DELETE THE FILE REALMAGC.QTC FROM YOUR WINDOWS/SYSTEM DIRECTORY.
  7. The following movie script should be placed in your movie:
     
    on startMovie
      global gcursor
      global gWindowHandle
      openXLib the pathname&"DLLGLUE"
      put dllglue(mNew, "USER.EXE", "GetActiveWindow", "W", "V") into gWindowHandle
      if NOT objectP(gWindowHandle) then
        alert "Windows has returned an error. Cancelling execution"
        quit
      end if
    end 
    
    on openmpeg mpegfile mpeglocation
      global gWindowHandle
      
      put gWindowHandle(mWindowHandle) into hwnd
      if (gWindowHandle (mStatus))<>0 then
        alert "Error. Cancelling execution"
        quit
      end if
      
      mci("open"&&the pathname&mpegfile&&"alias clip style child parent"&&hwnd)
    -- "clip" is the alias I'm using to refer to the open mpeg file. You can
    -- use other word.
      mci("put clip window at"&&mpeglocation)
      mci("window clip state hide")
      mci("setvideo clip key index to 253")
      
    -- 253 is the index of the color that is to be used for chromakey.
    -- IMPORTANT! Color 0 is the LAST
    -- of the palette, and color 255 is the first, so count backwards....
    end 
    
    on closempeg
      mci("close clip")
    end 
    
    on pausempeg
      mci("pause clip")
    end 
    
    on plaympeg
      mci("play clip")
    end 
    
    on restartmpeg
      mci("play clip from 0")
    end 
    
    on stopMovie
      global gWindowHandle
      mci("close clip")
      if objectP(gWindowHandle) then gWindowHandle(mDispose)
      closeXLib the pathname & "DLLGLUE"
    end 
     
  8. This script defines the following handlers:
     
      OPENMPEG(mpegfile,mpeglocation)
    
    In this example, the mpeg file is supposed to be in the same directory as the projector. mpeglocation is a string of four number that defines the position of the MPEG Window. The first two numbers define the top left corner of the window, and the other two define the window size.

    Example:

      
      on mouseDown
        openmpeg("test.mpg","0 0 320 240")
      end
    This will open the file and prepare it to play. You should open the file in a frame and then go to another frame to begin playing it. In this 'playing' frame you should place a shape filled with the color you've defined as the key color, so the video will appear without flashes. You can even use a transition to reveal the shape!!! To begin playing the file, use
    on enterFrame
       PLAYMPEG
    end
    Don't forget to add a (on exitframe go to the frame end) script to keep the playback head from moving. or you can keep it moving and key animations over the video... cool!! If you want more control, you can assign the following handlers to buttons, to pause, resume, close and restart the movie. (Resuming a paused video is accomplished using the PLAYMPEG command).
     
    PAUSEMPEG
    CLOSEMPEG
    RESTARTMPEG
     
    Thanks to our chroma-key approach, all this operations will (hopefully!!) occur without flashes and cleanly. To close the movie, first move to another frame that doen't contains any keyable areas, and then issue the closempeg handler.