Package quicktime.std.movies

Examples of quicktime.std.movies.Movie


  public static Movie addTextTrack(Movie mov, String text, String fontName,
    String fontOptions, int fontSize, int[] fgColor, int[] bgColor, int x,
    int y, float start, float duration)
  {
    // make a copy of the original movie
    Movie movie = MovieUtils.cloneMovie(mov);
    try
    {
      movie = new Movie();
      mov.insertSegment(movie, 0, mov.getDuration(), 0);
      movie.setDefaultDataRef(new DataRef(new QTHandle()));
    } // try
    catch (QTException qte)
    {
      qte.printStackTrace();
    } // catch (QTException)

    // determine opaque / transparent background color; transparency is
    // indicated by a -1 in the first cell of bgColor
    int dfFlag = 0;
    if (bgColor[0] == -1)
    {
      dfFlag = StdQTConstants.dfAntiAlias | StdQTConstants.dfKeyedText;
    } // if (bgColor[0] == -1)
    else
    {
      dfFlag = StdQTConstants.dfAntiAlias;
    } // else

    // set up the Java font to estimate dimensions of the actual text
    // track using QDFont
    Font font = null;
    int style = 0;
    if (fontOptions.equalsIgnoreCase("plain"))
    {
      style = QDConstants.normal;
      font = new Font(fontName, Font.PLAIN, fontSize);
    } // if (fontOptions.equalsIgnoreCase("plain"))
    else if (fontOptions.equalsIgnoreCase("bold"))
    {
      style = QDConstants.bold;
      font = new Font(fontName, Font.BOLD, fontSize);
    } // else if (fontOptions.equalsIgnoreCase("bold"))
    else if (fontOptions.equalsIgnoreCase("italic"))
    {
      style = QDConstants.italic;
      font = new Font(fontName, Font.ITALIC, fontSize + 2);
    } // else if (fontOptions.equalsIgnoreCase("italic"))
    else if (fontOptions.equalsIgnoreCase("bolditalic"))
    {
      style = QDConstants.bold | QDConstants.italic;
      font = new Font(fontName, Font.PLAIN + Font.ITALIC, fontSize + 5);
    } // else if (fontOptions.equalsIgnoreCase("bolditalic"))
    else if (fontOptions.equalsIgnoreCase("underline"))
    {
      style = QDConstants.underlined;
      font = new Font(fontName, Font.ITALIC + Font.BOLD, fontSize);
    } // else if (fontOptions.equalsIgnoreCase("underline"))
    else if (fontOptions.equalsIgnoreCase("boldunderline"))
    {
      style = QDConstants.underlined | QDConstants.bold;
      font = new Font(fontName, Font.ITALIC + Font.BOLD, fontSize + 1);
    } // else if (fontOptions.equalsIgnoreCase("boldunderline"))
    else if (fontOptions.equalsIgnoreCase("italicunderline"))
    {
      style = QDConstants.underlined | QDConstants.italic;
      font = new Font(fontName, Font.ITALIC + Font.BOLD, fontSize + 1);
    } // else if (fontOptions.equalsIgnoreCase("italicunderline"))
    else if (fontOptions.equalsIgnoreCase("bolditalicunderline"))
    {
      style = QDConstants.underlined| QDConstants.italic | QDConstants.bold;
      font = new Font(fontName, Font.ITALIC + Font.BOLD, fontSize + 1);
    } // else if (fontOptions.equalsIgnoreCase("bolditalicunderline"))
    JDialog tempF = new JDialog();
    JPanel temp = new JPanel();
    temp.setFont(font);
    tempF.add(temp);

    // must be visible, otherwise g2 is null
    tempF.setVisible(true);
    temp.setVisible(true);
    Graphics2D g2 = (Graphics2D)temp.getGraphics();
    g2.setFont(font);
    g2.drawString(text, 0, 0);
    tempF.setVisible(false);
    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D rect = font.getStringBounds(text, context);
    int TEXT_TRACK_WIDTH = (int)rect.getWidth();
    int TEXT_TRACK_HEIGHT = (int)rect.getHeight();
    temp = null;
    tempF = null;
    QDRect textBox = new QDRect(0, 0, TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT);

    // add text track
    Track textTrack;
    try
    {
      textTrack = movie.addTrack(TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT, 0);
      Media textMedia = new TextMedia(textTrack, movie.getTimeScale());
      TextMediaHandler handler = (TextMediaHandler)textMedia.getHandler();
      textMedia.beginEdits();
      byte[] msgBytes = text.getBytes();
      QTPointer msgPoint = new QTPointer(msgBytes);
      handler.addTextSample(msgPoint, QDFont.getFNum(fontName), fontSize, style,
        new QDColor(fgColor[0] / 255f, fgColor[1] / 255f, fgColor[2] / 255f),
        new QDColor(bgColor[0] / 255f, bgColor[1] / 255f, bgColor[2] / 255f),
        QDConstants.teJustLeft, textBox, dfFlag, QDFont.getFNum(fontName), 0, 0,
        QDColor.white, Math.round(duration * movie.getTimeScale()));
      textMedia.endEdits();
      textTrack.insertMedia(Math.round(start * movie.getTimeScale()), 0,
        textMedia.getDuration(), 1);

      // position the text track to (x, y)
      Matrix mat = new Matrix();
      mat.rect(new QDRect(0, 0, TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT),
View Full Code Here


    String fontOptions, int fontSize, int[] fgColor, int[] bgColor, int x,
    int y, int width, int height)
  throws QTException
  {
    // make a new copy of mov
    Movie movie = cloneMovie(mov);
    int timescale = movie.getTimeScale();

    TimeCodeDef tcDef = new TimeCodeDef();
    tcDef.setTimeScale(movie.getTimeScale());
    int fps = MovieUtils.countFrames(movie, 0, 1);

    tcDef.setFrameDuration(movie.getTimeScale() / fps);
    tcDef.setFramesPerSecond(fps);
    tcDef.setFlags(StdQTConstants.tcDropFrame);

    // first record at 0 hrs, 0 min, 0 sec, 0 frames
    TimeCodeTime tcTime = new TimeCodeTime (0, 0, 0, 0);

    // create time code track and media
    Track tcTrack = movie.addTrack (width, height, 0);
    TimeCodeMedia tcMedia = new TimeCodeMedia (tcTrack, timescale);
    TimeCoder timeCoder = tcMedia.getTimeCodeHandler();

    int style = 0;
    if (fontOptions.equalsIgnoreCase("plain"))
    {
      style = QDConstants.normal;
    } // if (fontOptions.equalsIgnoreCase("plain"))
    else if (fontOptions.equalsIgnoreCase("bold"))
    {
      style = QDConstants.bold;
    } // else if (fontOptions.equalsIgnoreCase("bold"))
    else if (fontOptions.equalsIgnoreCase("italic"))
    {
      style = QDConstants.italic;
    } // else if (fontOptions.equalsIgnoreCase("italic"))
    else if (fontOptions.equalsIgnoreCase("bolditalic"))
    {
      style = QDConstants.bold | QDConstants.italic;
    } // else if (fontOptions.equalsIgnoreCase("bolditalic"))
    else if (fontOptions.equalsIgnoreCase("underline"))
    {
      style = QDConstants.underlined;
    } // else if (fontOptions.equalsIgnoreCase("underline"))
    else if (fontOptions.equalsIgnoreCase("boldunderline"))
    {
      style = QDConstants.underlined | QDConstants.bold;
    } // else if (fontOptions.equalsIgnoreCase("boldunderline"))
    else if (fontOptions.equalsIgnoreCase("italicunderline"))
    {
      style = QDConstants.underlined | QDConstants.italic;
    } // else if (fontOptions.equalsIgnoreCase("italicunderline"))
    else if (fontOptions.equalsIgnoreCase("bolditalicunderline"))
    {
      style = QDConstants.underlined| QDConstants.italic | QDConstants.bold;
    } // else if (fontOptions.equalsIgnoreCase("bolditalicunderline"))

    // turn on time code display, set colors
    timeCoder.setFlags(timeCoder.getFlags() | StdQTConstants.tcdfShowTimeCode,
      StdQTConstants.tcdfShowTimeCode);
    TCTextOptions tcTextOptions = timeCoder.getDisplayOptions();
    tcTextOptions.setTXSize(fontSize);
    tcTextOptions.setTXFace(style);
    tcTextOptions.setTXFont(QDFont.getFNum(fontName));
    tcTextOptions.setForeColor(new QDColor(fgColor[0] / 255f, fgColor[1] / 255f,
      fgColor[2] / 255f));

    // if transparency is indicated, set background color to a special value
    if (bgColor[0] == -1)
    {
      tcTextOptions.setBackColor(new QDColor(0.1f, 0.7f, 0.43f));
    } // if (bgColor[0] == -1)
    else
    {
      tcTextOptions.setBackColor(new QDColor(bgColor[0] / 255f,
        bgColor[1] / 255f, bgColor[2] / 255f));
    } // else
    timeCoder.setDisplayOptions(tcTextOptions);

    // set up a sample as a 4-byte array in a QTHandle
    int frameNumber = timeCoder.toFrameNumber(tcTime, tcDef);
    int frameNums[] = new int[1];

    // BOOK ERRATA: this is buggy on Windows for time codes other
    // than 00:00:00;00.  You need to adjust for endianness, as
    // seen in the revised (uncommented) line.
    // frameNums[0] = frameNumber;
    frameNums[0] = EndianOrder.flipNativeToBigEndian32(frameNumber);
    QTHandle frameNumHandle = new QTHandle (4, false);
    frameNumHandle.copyFromArray(0, frameNums, 0, 1);

    // create a time code description (sample to be added)
    TimeCodeDescription tcDesc = new TimeCodeDescription();
    tcDesc.setTimeCodeDef (tcDef);

    // add the sample to the TimeCodeMedia
    tcMedia.beginEdits();
    tcMedia.addSample(frameNumHandle, 0, frameNumHandle.getSize(),
      movie.getDuration(), tcDesc, 1, 0);
    tcMedia.endEdits();

    // insert media into track
    tcTrack.insertMedia(0, 0, tcMedia.getDuration(), 1);
View Full Code Here

   * @param mov2     Movie to append
   * @return result  mov2 appended to end of mov1
   */
  public static Movie movieAppend(Movie mov1, Movie mov2)
  {
    Movie composite = null;
    Movie movie1 = null;
    Movie movie2 = null;
    try
    {
      QDRect box1 = mov1.getBox();
      QDRect box2 = mov2.getBox();
      int height1 = box1.getHeight();
      int height2 = box2.getHeight();
      int width1 = box1.getWidth();
      int width2 = box2.getWidth();

      // variables for the matrix translations
      float a = 0, b = 0, c = 0, d = 0;
      movie1 = new Movie();
      movie2 = new Movie();
      composite = new Movie();

      // insert the movies to new movie files, in order to resize without
      // affecting originals
      mov1.insertSegment(movie1, 0, mov1.getDuration(), 0);
      mov2.insertSegment(movie2, 0, mov2.getDuration(), 0);
      Track track1 = movie1.getIndTrackType(1,
        StdQTConstants.videoMediaType,
        StdQTConstants.movieTrackMediaType);
      Track track2 = movie2.getIndTrackType(1,
        StdQTConstants.videoMediaType,
        StdQTConstants.movieTrackMediaType);
      Matrix matrix1 = track1.getMatrix();
      Matrix matrix2 = track2.getMatrix();

      // translate tracks based on size
      if (box1.equals(box2))
      {
        // do nothing - no resizing needed
      } // if (box1.equals(box2))
      else if ((height1 >= height2) && (width1 >= width2))
      {
        c = (width1 - width2) / 2;
        d = (height1 - height2) / 2;
      } // else if ((height1 >= height2) && (width1 >= width2))
      else if ((height2 >= height1) && (width2 >= width1))
      {
        a = (width2 - width1) / 2;
        b = (height2 - height1) / 2;
      } // else if ((height2 >= height1) && (width2 >= width1))
      else if ((height1 >= height2) && (width2 >= width1))
      {
        a = (width2 - width1) / 2;
        d = (height1 - height2) / 2;
      } // else if ((height1 >= height2) && (width2 >= width1))
      else if ((height2 >= height1) && (width1 >= width2))
      {
        b = (height2 - height1) / 2;
        c = (width1 - width2) / 2;
      } // else if ((height2 >= height1) && (width1 >= width2))

      // modify matrices based on changes made in the if-clause above
      matrix1.translate(a, b);
      matrix2.translate(c, d);

      // set tracks to changed matrices
      track1.setMatrix(matrix1);
      track2.setMatrix(matrix2);

      // add the two movies with translated video tracks to the returned
      // composite
      movie2.insertSegment(composite, 0, movie2.getDuration(), 0);
      movie1.insertSegment(composite, 0, movie1.getDuration(), 0);
    } // try
    catch (QTException qte)
    {
      qte.printStackTrace();
View Full Code Here

   * @param end       Time in mov to stop extracting
   * @return segment  Segment of mov from start to end
   */
  public static Movie extractSegment(Movie mov, float start, float end)
  {
    Movie section = null;
    try
    {
      section = new Movie();
      int begin = Math.round(start * mov.getTimeScale());
      int finish = Math.round(end * mov.getTimeScale());
      mov.insertSegment(section, begin, finish - begin, 0);
      section.setTimeScale(mov.getTimeScale());
    } // try
    catch (QTException qte)
    {
      qte.printStackTrace();
    } // catch (QTException)
View Full Code Here

   * @param time     Time in dest to insert src
   * @return result  dest with src inserted at time
   */
  public static Movie insertSegment(Movie src, Movie dest, float time)
  {
    Movie union = null;
    try
    {
      // create a new movie
      union = new Movie();

      // convert time from seconds to a time in dest's time scale
      int there = Math.round(time * dest.getTimeScale());

      // copy dest into new movie up until the time of insertion
      dest.insertSegment(union, 0, there, 0);

      // copy src, in its entirety, into new movie
      src.insertSegment(union, 0, src.getDuration(), union.getDuration());

      // copy rest of dest into new movie
      dest.insertSegment(union, there, dest.getDuration(), union.getDuration());
    } // try
    catch (QTException qte)
    {
      qte.printStackTrace();
    } // catch (QTException)
View Full Code Here

/*     */
/*     */   public boolean doUserDialog(Movie paramMovie, Track paramTrack, int paramInt1, int paramInt2)
/*     */     throws StdQTException
/*     */   {
/* 199 */     byte[] arrayOfByte = new byte[1];
/* 200 */     Movie localMovie = paramMovie;
/* 201 */     Track localTrack = paramTrack;
/* 202 */     int i = paramInt1;
/* 203 */     int j = paramInt2;
/* 204 */     int k = _ID();
/*     */
View Full Code Here

/* 260 */       if (localMovie != null) return paramQTDrawableMaker.fromMovie(localMovie);
/*     */
/*     */     }
/*     */
/* 264 */     Object localObject = openAsImage(paramQTFile);
/* 265 */     Movie localMovie = null;
/* 266 */     if (localObject != null) {
/* 267 */       localMovie = checkIfMovie(paramQTFile);
/* 268 */       if (localMovie == null) {
/* 269 */         return paramQTDrawableMaker.fromGraphicsImporter((GraphicsImporter)localObject);
/*     */       }
View Full Code Here

/* 354 */       if (localObject != null) return paramQTDrawableMaker.fromMovie((Movie)localObject);
/*     */
/*     */     }
/*     */
/* 358 */     Object localObject = importImage(localDataRef);
/* 359 */     Movie localMovie = null;
/* 360 */     if (localObject != null) {
/* 361 */       localMovie = checkIfMovie(localDataRef);
/* 362 */       if (localMovie == null) {
/* 363 */         return paramQTDrawableMaker.fromGraphicsImporter((GraphicsImporter)localObject);
/*     */       }
View Full Code Here

/*     */     }
/*     */
/* 425 */     DataRef localDataRef = new DataRef(paramString);
/*     */
/* 427 */     GraphicsImporter localGraphicsImporter = importImage(localDataRef);
/* 428 */     Movie localMovie = null;
/* 429 */     if (localGraphicsImporter != null) {
/* 430 */       localMovie = checkIfMovie(localDataRef);
/* 431 */       if (localMovie == null) {
/* 432 */         return paramQTDrawableMaker.fromGraphicsImporter(localGraphicsImporter);
/*     */       }
View Full Code Here

/*     */
/*     */   private static Movie importMovie(QTHandle paramQTHandle, int paramInt) throws QTException {
/* 525 */     if (paramInt == 0) throw new QTException(-2003); try
/*     */     {
/* 527 */       MovieImporter localMovieImporter = new MovieImporter(paramInt);
/* 528 */       Movie localMovie = new Movie(1);
/* 529 */       localMovie.setDefaultDataRef(new DataRef(new QTHandle()));
/* 530 */       localMovieImporter.fromHandle(paramQTHandle, localMovie, null, 0, 1);
/* 531 */       return localMovie; } catch (QTException localQTException) {
/*     */     }
/* 533 */     return null;
/*     */   }
View Full Code Here

TOP

Related Classes of quicktime.std.movies.Movie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.