示例#1
0
 /**
  * Appends a frame to the current video.
  *
  * @param image the image to append
  * @return true if image successfully appended
  */
 protected boolean append(Image image) {
   BufferedImage bi;
   if (image instanceof BufferedImage) {
     bi = (BufferedImage) image;
   } else {
     bi = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB);
     Graphics2D g = bi.createGraphics();
     g.drawImage(image, 0, 0, null);
   }
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   try {
     if (!editing) {
       videoMedia.beginEdits();
       editing = true;
     }
     ImageIO.write(bi, "png", out); // $NON-NLS-1$
     QTHandle handle = new QTHandle(out.toByteArray());
     DataRef dataRef = new DataRef(handle, kDataRefFileExtensionTag, "png"); // $NON-NLS-1$
     GraphicsImporter importer = new GraphicsImporter(dataRef);
     ImageDescription description = importer.getImageDescription();
     int duration = (int) (frameDuration * 0.6);
     videoMedia.addSample(
         handle,
         0, // data offset
         handle.getSize(),
         duration,
         description,
         1, // number of samples
         0); // key frame??
   } catch (Exception ex) {
     ex.printStackTrace();
     return false;
   }
   return true;
 }
示例#2
0
 /** 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();
   }
 }
示例#3
0
 /**
  * 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$
     }
 }
示例#4
0
 private void compressAndAdd() {
   try {
     if (temporalSupported) {
       CompressedFrameInfo cfInfo =
           seq.compressFrame(gw, bounds, StdQTConstants.codecFlagUpdatePrevious, compressedImage);
       boolean syncSample =
           cfInfo.getSimilarity() == 0; // see developer.apple.com/qa/qtmcc/qtmcc20.html
       videoMedia.addSample(
           imageHandle,
           0,
           cfInfo.getDataSize(),
           TIME_SCALE / rate,
           imgDesc,
           1,
           syncSample ? 0 : StdQTConstants.mediaSampleNotSync);
     } else {
       imgDesc =
           QTImage.fCompress(
               gw,
               gw.getBounds(),
               32,
               codecQuality,
               codecType,
               CodecComponent.anyCodec,
               null,
               0,
               RawEncodedImage.fromQTHandle(imageHandle));
       boolean syncSample = true; // UM, what the hell should this be???
       videoMedia.addSample(
           imageHandle,
           0,
           imgDesc.getDataSize(),
           TIME_SCALE / rate,
           imgDesc,
           1,
           syncSample ? 0 : StdQTConstants.mediaSampleNotSync);
     }
   } catch (QTException e) {
     e.printStackTrace();
   }
 }
示例#5
0
  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();
      }
    }
  }