FileDocCategorySizeDatePackage
FilterTrackBuilder.javaAPI DocExample9018Wed Nov 10 12:52:40 GMT 2004com.oreilly.qtjnotebook.ch09

FilterTrackBuilder

public class FilterTrackBuilder extends Object

Fields Summary
public static final int
EFFECT_TRACK_WIDTH
public static final int
EFFECT_TRACK_HEIGHT
public static final int
TIMESCALE
Constructors Summary
public FilterTrackBuilder()

        QTSessionCheck.check();

        QTFile movFile = new QTFile (new java.io.File("filter.mov"));
        Movie movie =
            Movie.createMovieFile(movFile,
                                  StdQTConstants.kMoviePlayer,
                                  StdQTConstants.createMovieFileDeleteCurFile |
                                  StdQTConstants.createMovieFileDontCreateResFile);

        Movie sourceMovie = queryUserForMovie();
        Track sourceTrack = addVideoTrack (sourceMovie,
                                           movie,
                                           0,
                                           sourceMovie.getDuration(),
                                           0);

        Track effectsTrack = movie.addTrack (EFFECT_TRACK_WIDTH,
                                             EFFECT_TRACK_HEIGHT,
                                             0);
        effectsTrack.setLayer(-1);

        int TIMESCALE = 600;
		VideoMedia effectsMedia = new VideoMedia(effectsTrack,
                                                 TIMESCALE);
        // set up input map 
        AtomContainer inputMap = new AtomContainer();

        int trackRef =
            effectsTrack.addReference (sourceTrack,
                                       StdQTConstants.kTrackModifierReference);

        // add input reference atom
        Atom inputAtom = 
            inputMap.insertChild (null,
                                  StdQTConstants.kTrackModifierInput, 
                                  trackRef,
                                  0);

        // add name and type
        inputMap.insertChild (inputAtom,
                              StdQTConstants.kTrackModifierType,
                              1,
                              0,
                              EndianOrder.flipNativeToBigEndian32(StdQTConstants.videoMediaType));

        inputMap.insertChild (inputAtom,
                              StdQTConstants.kEffectDataSourceType,
                              1,
                              0,
                              // QTUtils.toOSType ("srcA"));
	                      EndianOrder.flipNativeToBigEndian32(QTUtils.toOSType ("srcA")));
        System.out.println ("set up input map atom");

        // show list of effects
        // flags are in StdQTConstants.pdOptions...
        // (http://developer.apple.com/documentation/QuickTime/REF/refEffects.61.htm)
        Pict[] previewPicts = new Pict[1];
        previewPicts[0] = sourceMovie.getPosterPict();

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

        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.flipBigEndianToNative32(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 a ref to the source
        effect.insertChild (null,
                            StdQTConstants.kEffectSourceName,
                            1,
                            0,
                            // QTUtils.toOSType ("srcA"));
                            EndianOrder.flipNativeToBigEndian32(QTUtils.toOSType ("srcA")));

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

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

        effectsMedia.endEdits();

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

        // 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 FilterTrackBuilder();
        } 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);