public void start() { try { // if QT was not successfully initialized the QTComponent will be null if (qtc != null) { add((Component) qtc, "Center"); mov.setRate(1); } } catch (QTException e) { e.printStackTrace(); } }
/** * Creates an empty movie to which frames can be added. * * @throws IOException */ private void createMovie() throws IOException { try { // create the scratch movie movie = Movie.createMovieFile( new QTFile(scratchFile), kMoviePlayer, createMovieFileDeleteCurFile | createMovieFileDontCreateResFile); // create the video track and media int timeScale = 600; int noVolume = 0; videoTrack = movie.newTrack(dim.width, dim.height, noVolume); videoMedia = new VideoMedia(videoTrack, timeScale); editing = false; } catch (QTException ex) { throw new IOException("caught in createMovie: " + ex.toString()); // $NON-NLS-1$ } }
/** Close out and finish the movie file. */ public void finish() { try { if (readyForFrames) { // System.out.println("Finishing movie file."); readyForFrames = false; videoMedia.endEdits(); videoTrack.insertMedia(0, 0, videoMedia.getDuration(), 1); OpenMovieFile omf = OpenMovieFile.asWrite(movFile); movie.addResource(omf, StdQTConstants.movieInDataForkResID, movFile.getName()); } } catch (StdQTException se) { se.printStackTrace(); } catch (QTException qe) { qe.printStackTrace(); } }
public void init() { try { if (QTSession.isInitialized() == false) QTSession.open(); // set up a QTComponent which will disply its content // at its original size of smaller and centered in the space given // to the QTComponent when the applet is layed out setLayout(new BorderLayout()); QTFile qtf = new QTFile(getCodeBase().getFile() + getParameter("file")); OpenMovieFile fis = OpenMovieFile.asRead(qtf); mov = Movie.fromFile(fis); qtc = QTFactory.makeQTComponent(mov); } catch (QTException qtE) { throw new RuntimeException(qtE.getMessage()); } }
/** * Saves the video to the current scratchFile. * * @throws IOException */ protected void saveScratch() throws IOException { if (movie != null && editing) try { // end edits and save the scratch videoMedia.endEdits(); int trackStart = 0; int mediaTime = 0; int mediaRate = 1; videoTrack.insertMedia(trackStart, mediaTime, videoMedia.getDuration(), mediaRate); editing = false; OpenMovieFile outStream = OpenMovieFile.asWrite(new QTFile(scratchFile)); movie.addResource(outStream, movieInDataForkResID, scratchFile.getName()); outStream.close(); movie = null; OSPLog.finest( "saved " + frameCount + " frames in " + scratchFile); // $NON-NLS-1$ //$NON-NLS-2$ } catch (QTException ex) { throw new IOException("caught in saveScratch: " + ex.toString()); // $NON-NLS-1$ } }
private void initMovie(String filename) { try { String path = parent.savePath(filename); movFile = new QTFile(new File(path)); movie = Movie.createMovieFile( movFile, StdQTConstants.kMoviePlayer, StdQTConstants.createMovieFileDeleteCurFile); int timeScale = TIME_SCALE; // 100 units per second videoTrack = movie.addTrack(width, height, 0); videoMedia = new VideoMedia(videoTrack, timeScale); videoMedia.beginEdits(); bounds = new QDRect(0, 0, width, height); int rawImageSize = QTImage.getMaxCompressionSize( gw, bounds, gw.getPixMap().getPixelSize(), codecQuality, codecType, CodecComponent.anyCodec); imageHandle = new QTHandle(rawImageSize, true); imageHandle.lock(); compressedImage = RawEncodedImage.fromQTHandle(imageHandle); seq = new CSequence( gw, bounds, gw.getPixMap().getPixelSize(), codecType, CodecComponent.bestFidelityCodec, codecQuality, codecQuality, keyFrameRate, null, 0); imgDesc = seq.getDescription(); readyForFrames = true; } catch (QTException e) { if (e.errorCode() == Errors.noCodecErr) { if (imageHandle == null) { // This means QTImage.getMaxCompressionSize() failed System.err.println( "The specified codec is not supported, " + "please ensure that the parameters are valid, " + "and in the correct order."); } else { // If it's a -8961 error, quietly do it the other way // (this happens when RAW is specified) temporalSupported = false; readyForFrames = true; } } else if (e.errorCode() == Errors.fBsyErr) { System.err.println("The movie file already exists. " + "Please delete it first."); } else { e.printStackTrace(); } } }
// use a file input stream to make dragging faster as the movie is comletetly loaded into memory // this is not required for any other reason private static QTPlayer makePlayer(QTFile f) throws IOException, QTException { QTDrawable d = QTFactory.makeDrawable(new FileInputStream(f), kDataRefFileExtensionTag, "mov"); Movie m = ((QTPlayer) d).getMovieController().getMovie(); m.getTimeBase().setFlags(loopTimeBase); return (QTPlayer) d; }