private void createCodec(VideoTrack vt) {
    Format fmt = vt.videoFormat;
    String enc = fmt.get(EncodingKey);
    if (enc.equals(ENCODING_AVI_MJPG) //
        || enc.equals(ENCODING_QUICKTIME_JPEG) //
    ) {
      vt.codec = new JPEGCodec();
    } else if (enc.equals(ENCODING_AVI_PNG) //
        || enc.equals(ENCODING_QUICKTIME_PNG) //
    ) {
      vt.codec = new PNGCodec();
    }

    vt.codec.setInputFormat(
        fmt.prepend(
            MediaTypeKey,
            MediaType.VIDEO,
            MimeTypeKey,
            MIME_JAVA,
            EncodingKey,
            ENCODING_BUFFERED_IMAGE,
            DataClassKey,
            BufferedImage.class));
    vt.codec.setOutputFormat(
        fmt.prepend(MediaTypeKey, MediaType.VIDEO, EncodingKey, enc, DataClassKey, byte[].class));
    //    vt.codec.setQuality(vt.videoQuality);
  }
예제 #2
0
파일: Main.java 프로젝트: sebkur/montemedia
  private static void testWriting(File file, Format format) throws IOException {
    System.out.println("Writing " + file);

    // Make the format more specific
    format =
        format.prepend(
            MediaTypeKey,
            MediaType.VIDEO, //
            FrameRateKey,
            new Rational(30, 1), //
            WidthKey,
            320, //
            HeightKey,
            160);

    // Create a buffered image for this format
    BufferedImage img = createImage(format);
    Graphics2D g = img.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    QuickTimeWriter out = null;
    try {
      // Create the writer
      out = new QuickTimeWriter(file);

      // Add a track to the writer
      out.addTrack(format);
      out.setVideoColorTable(0, img.getColorModel());

      // initialize the animation
      Random rnd = new Random(0); // use seed 0 to get reproducable output
      g.setBackground(Color.WHITE);
      g.clearRect(0, 0, img.getWidth(), img.getHeight());

      for (int i = 0; i < 100; i++) {
        // Create an animation frame
        g.setColor(new Color(rnd.nextInt()));
        g.fillOval(rnd.nextInt(img.getWidth() - 30), rnd.nextInt(img.getHeight() - 30), 30, 30);

        // write it to the writer
        out.write(0, img, 1);
      }

    } finally {
      // Close the writer
      if (out != null) {
        out.close();
      }

      // Dispose the graphics object
      g.dispose();
    }
  }
  public int addTrack(Format format) throws IOException {
    if (tracks.size() > 0) throw new UnsupportedOperationException("only 1 track supported");
    Format derivedFormat =
        format.prepend(
            MediaTypeKey,
            MediaType.VIDEO,
            MimeTypeKey,
            MIME_ANIM,
            EncodingKey,
            ENCODING_ANIM_OP5,
            DataClassKey,
            byte[].class, //
            FixedFrameRateKey,
            false);

    setCAMG(toCAMG(derivedFormat));
    Track tr = new Track();
    tr.format = derivedFormat;

    tracks.add(tr);
    return tracks.size() - 1;
  }