FileDocCategorySizeDatePackage
TransitionTrackBuilder.javaAPI DocExample11823Wed Nov 10 12:59:32 GMT 2004com.oreilly.qtjnotebook.ch09

TransitionTrackBuilder

public class TransitionTrackBuilder extends Object

Fields Summary
public static final int
EFFECT_TRACK_WIDTH
public static final int
EFFECT_TRACK_HEIGHT
public static final int
TIMESCALE
public static final int
TRANSITION_DURATION_SECONDS
public static final int
TRANSITION_DURATION
Constructors Summary
public TransitionTrackBuilder()

        QTSessionCheck.check();

        QTFile movFile = new QTFile (new java.io.File("transition.mov"));
        // query user for source movies
        Movie sourceAMovie = queryUserForMovie();
        Movie sourceBMovie = queryUserForMovie();

        /* create *5* video tracks:
           1. all of sourceAMovie up to effect
           2. portion of sourceAMovie used for effect
           3. portion of sourceBMovie used for effect
           4. all of sourceBMovie after effect
           5. effects track
        */
        Movie movie =
            Movie.createMovieFile(movFile,
                                  StdQTConstants.kMoviePlayer,
                                  StdQTConstants.createMovieFileDeleteCurFile |
                                  StdQTConstants.createMovieFileDontCreateResFile);

        Track preEffectTrack = addVideoTrack (sourceAMovie,
                                              movie,
                                              0, 
                                              sourceAMovie.getDuration() - TRANSITION_DURATION,
                                              0);
        Track sourceATrack = addVideoTrack (sourceAMovie,
                                            movie,
                                            sourceAMovie.getDuration() - TRANSITION_DURATION,
                                            TRANSITION_DURATION,
                                            sourceAMovie.getDuration() - TRANSITION_DURATION);

        Track sourceBTrack = addVideoTrack (sourceBMovie,
                                            movie,
                                            0,
                                            TRANSITION_DURATION,
                                            movie.getDuration() - TRANSITION_DURATION);
        Track postEffectTrack = addVideoTrack (sourceBMovie,
                                               movie,
                                               TRANSITION_DURATION,
                                               sourceBMovie.getDuration() - TRANSITION_DURATION,
                                               movie.getDuration());

        Track effectsTrack = movie.addTrack (EFFECT_TRACK_WIDTH,
                                             EFFECT_TRACK_HEIGHT,
                                             0);
        int TIMESCALE = 600;
		VideoMedia effectsMedia = new VideoMedia(effectsTrack,
                                                 TIMESCALE);

        // get list of effects
        // StdQTConstants.elOptionsIncludeNoneInList)
        EffectsList effectsList = new EffectsList (2, 2, 0);

        // probably need to set up input map here
        AtomContainer inputMap = new AtomContainer();

        int trackARef =
            effectsTrack.addReference (sourceATrack,
                                       StdQTConstants.kTrackModifierReference);
        int trackBRef =
            effectsTrack.addReference (sourceBTrack,
                                       StdQTConstants.kTrackModifierReference);

        // add input reference atoms
        Atom aInputAtom = 
            inputMap.insertChild (null,
                                  StdQTConstants.kTrackModifierInput, 
                                  trackARef,
                                  0);
        inputMap.insertChild (aInputAtom,
                              StdQTConstants.kTrackModifierType,
                              1,
                              0,
                              EndianOrder.flipNativeToBigEndian32(StdQTConstants.videoMediaType));
        inputMap.insertChild (aInputAtom,
                              StdQTConstants.kEffectDataSourceType,
                              1,
                              0,
                              EndianOrder.flipNativeToBigEndian32(QTUtils.toOSType ("srcA")));

        Atom bInputAtom = 
            inputMap.insertChild (null,
                                  StdQTConstants.kTrackModifierInput, 
                                  trackBRef,
                                  0);
        inputMap.insertChild (bInputAtom,
                              StdQTConstants.kTrackModifierType,
                              1,
                              0,
                              EndianOrder.flipNativeToBigEndian32(StdQTConstants.videoMediaType));

        inputMap.insertChild (bInputAtom,
                              StdQTConstants.kEffectDataSourceType,
                              1,
                              0,
                              EndianOrder.flipNativeToBigEndian32(QTUtils.toOSType ("srcB")));

        System.out.println ("set up input map atoms");

        // show list of effects
        // flags are in StdQTConstants.pdOptions...
        // (http://developer.apple.com/documentation/QuickTime/REF/refEffects.61.htm)
        Pict[] previewPicts = new Pict[2];
        previewPicts[0] = sourceAMovie.getPosterPict();
        previewPicts[1] = sourceBMovie.getPosterPict();
        AtomContainer effect =
            ParameterDialog.showParameterDialog (effectsList,
                                                 0, // dialogOptions
                                                 null, // parameters
                                                 "Pick an effect", // title
                                                 previewPicts //pictArray
                                                 );
        // find out the effect type by getting the "what" atom,
        // whose data is a FOUR_CHAR_CODE
        Atom what = effect.findChildByIndex_Atom (null, 
                                                   StdQTConstants.kParameterWhatName,
                                                   1);
        int effectType = effect.getAtomData(what).getInt(0);
	effectType = EndianOrder.flipNativeToBigEndian32 (effectType);
        System.out.println ("User chose " + 
                            QTUtils.fromOSType(effectType) +
                            " effect type");

        // make a sample description for the effect description
        ImageDescription imgDesc = ImageDescription.forEffect (effectType);
        imgDesc.setWidth (EFFECT_TRACK_WIDTH);
        imgDesc.setHeight (EFFECT_TRACK_HEIGHT);

        // give the effect description refs to the sources
        effect.insertChild (null,
                            StdQTConstants.kEffectSourceName,
                            1,
                            0,
                            EndianOrder.flipNativeToBigEndian32(QTUtils.toOSType ("srcA")));
        effect.insertChild (null,
                            StdQTConstants.kEffectSourceName,
                            2,
                            0,
                            EndianOrder.flipNativeToBigEndian32(QTUtils.toOSType ("srcB")));


        // add effect to the video media
        effectsMedia.beginEdits();

        effectsMedia.addSample (effect, // QTHandleRef data,
                                0, // int dataOffset,
                                effect.getSize(), // int dataSize,
                                TRANSITION_DURATION, //int durationPerSample,
                                imgDesc, // SampleDescription sampleDesc,
                                1, // int numberOfSamples,
                                0 // int sampleFlags
                                );
        effectsMedia.setInputMap (inputMap);

        effectsMedia.endEdits();

        // now insert this media into track
        effectsTrack.insertMedia (sourceATrack.getDuration() -
                                    TRANSITION_DURATION, // trackStart
                                  0, // mediaTime
                                  TRANSITION_DURATION, // mediaDuration
                                  1); // mediaRate
        System.out.println ("inserted media into effects track");

        effectsTrack.setLayer (-1);

        // save up 
        System.out.println ("Saving...");
        OpenMovieFile omf = OpenMovieFile.asWrite (movFile);
        movie.addResource (omf,
                           StdQTConstants.movieInDataForkResID,
                           movFile.getName());
        System.out.println ("Done");

    
Methods Summary
public static TrackaddVideoTrack(Movie sourceMovie, Movie targetMovie, int srcIn, int srcDuration, int targetTime)

 
        // 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,
                                  srcIn, // 0
                                  srcDuration, // videoTrack.getDuration()
                                  targetTime);
        return newTrack;
    
public static voidmain(java.lang.String[] args)

 

          
        try {
            new TransitionTrackBuilder();
        } catch (QTException qte) {
            qte.printStackTrace();
        }
        System.exit(0);
    
public static MoviequeryUserForMovie()

        QTFile file =
            QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
        OpenMovieFile omf = OpenMovieFile.asRead (file);
        return Movie.fromFile (omf);