FileDocCategorySizeDatePackage
MatrixVideoTracks.javaAPI DocExample5178Wed Nov 10 12:50:56 GMT 2004com.oreilly.qtjnotebook.ch08

MatrixVideoTracks

public class MatrixVideoTracks extends Frame

Fields Summary
static Movie
foreMovie
static Movie
backMovie
Constructors Summary
public MatrixVideoTracks(Movie backMovie, Movie foreMovie)

        super ("Matrix Video Tracks");
        Movie matrixMovie = new Movie();
        // build tracks
        Track foreTrack = addVideoTrack (foreMovie, matrixMovie);
        Track backTrack = addVideoTrack (backMovie, matrixMovie);
        // set matrix transformation
        Matrix foreMatrix = new Matrix();

        /* uncomment these two lines to add add mirror-image
           effect to the foreground video
        foreMatrix.scale (-1, 1, 0, 0);
        foreMatrix.translate ((float) foreTrack.getSize().getWidth(), 0f );
        */

        // set matrix to move fore to bottom right 1/4 or back
        QDRect foreFrom =
            new QDRect (0, 0,
                        foreTrack.getSize().getWidth(),
                        foreTrack.getSize().getHeight());
        QDRect foreTo = 
            new QDRect (backTrack.getSize().getWidth() / 2,
                        backTrack.getSize().getHeight() / 2,
                        backTrack.getSize().getWidth() / 2,
                        backTrack.getSize().getHeight() / 2);
        System.out.println ("foreTo is = " + foreTo);
        foreMatrix.map (foreFrom, foreTo);
        foreTrack.setMatrix (foreMatrix);
        // set foreTrack's layer
        foreTrack.setLayer (-1);
        /*
        System.out.println ("foreTrack layer = " +
                            foreTrack.getLayer() +
                            ", backTrack layer = " +
                            backTrack.getLayer());
        */
        // now get component and add to frame
        MovieController controller = new MovieController(matrixMovie);
        Component c = QTFactory.makeQTComponent(controller).asComponent();
        add (c);
    
Methods Summary
public TrackaddVideoTrack(Movie sourceMovie, Movie targetMovie)

 
        // find first video track
        Track videoTrack = 
            sourceMovie.getIndTrackType (1,
                                         StdQTConstants.videoMediaType,
                                         StdQTConstants.movieTrackMediaType);
        if (videoTrack == null)
            throw new QTException ("can't find a video track");
        // add videoTrack to targetMovie
        Track newTrack =
            targetMovie.newTrack (videoTrack.getSize().getWidthF(),
                                  videoTrack.getSize().getHeightF(),
                                  1.0f);
        VideoMedia newMedia = 
            new VideoMedia (newTrack,
                            videoTrack.getMedia().getTimeScale(),
                            new DataRef(new QTHandle()));
        videoTrack.insertSegment (newTrack,
                                 0,
                                 videoTrack.getDuration(),
                                 0);
        return newTrack;
    
public static voidmain(java.lang.String[] args)

        try {
            QTSessionCheck.check();
            // get background movie
            QTFile file = QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
            OpenMovieFile omf = OpenMovieFile.asRead(file);
            backMovie = Movie.fromFile (omf);
            // get foreground movie
            file = QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
            omf = OpenMovieFile.asRead(file);
            foreMovie = Movie.fromFile (omf);
            // get frame
            Frame frame = new MatrixVideoTracks (backMovie, foreMovie);
            frame.pack();
            frame.setVisible (true);
        } catch (QTException qte) {
            qte.printStackTrace();
        }