.. _Intermediate/CreateALeftEyeRightEyeSideBySideMovie:

Create a Left-Eye, Right-Eye, Side-By-Side Movie
================================================

Problem
-------

You have a set of frames pairs (left eye, right eye) for creating a 3D movie of Patches playing with his ball, and you want to use them to create a left-eye, right-eye, side-by-side movie, where each side is 640x480.  The left eye images are saved using the filenames Patches_ball_left_###.jpg, with ### replaced by the three digit frame number, and the right eye images are similarly stored using the filenames Patches_ball_right_###.jpg.

Solution
--------


::

    import Draft
    from DraftParamParser import ReplaceFilenameHashesWithNumber

    width = 640
    doubleWidth = width * 2  # twice the width to fit both left and right eye frames.
    height = 480
    encoder = Draft.VideoEncoder( 'Patches.mov', width=doubleWidth )  # Create encoder.

    for currFrame in range( 1, 201 ): # Note: second parameter of range is one past end
        nameL = ReplaceFilenameHashesWithNumber( 'Patches_ball_left_###.jpg', currFrame )
        nameR = ReplaceFilenameHashesWithNumber( 'Patches_ball_right_###.jpg', currFrame )
        
        frameL = Draft.Image.ReadFromFile( nameL )
        frameR = Draft.Image.ReadFromFile( nameR )

        frameL.Resize( width, height )	# Make sure frames are correct size.
        frameR.Resize( width, height )

        frame = Draft.Image.CreateImage( doubleWidth, height )	# Frame to hold both eyes.
        compOp = Draft.CompositeOperator.OverCompositeOp
        frame.CompositeWithAnchor( frameL, Draft.Anchor.West, compOp )
        frame.CompositeWithAnchor( frameR, Draft.Anchor.East, compOp )
        
        encoder.EncodeNextFrame( frame )	# Add the frame to the video.

    encoder.FinalizeEncoding()	# Finalize and save the resulting video.

Discussion
----------

The main difference between this recipe and the basic :ref:`Basic/CreateAQuickTimeMovie` recipe is that here we have two images per frame of the movie, and we must load both and composite them into a single image before we can add them to the video encoder.

Using :const:`Draft.Anchor.West` and :const:`Draft.Anchor.East` we can easily place the images without having to worry about finding the exact location in the final image to use for the :meth:`~Draft.Image.Composite` call. The left frame is placed at the leftmost edge with the :const:`~Draft.Anchor.West` anchor and the right frame is place at the rightmost edge using the :const:`~Draft.Anchor.East` anchor.

See Also
--------

:ref:`Basic/CreateAQuickTimeMovie`, :ref:`Basic/ResizeAnImage`, and :ref:`Basic/CompositeTwoImages` in the Basic Cookbook
