示例#1
0
    public ByteBuffer transcodeFrame(ByteBuffer src, ByteBuffer dst) throws IOException {
      if (src == null) return null;
      Picture8Bit decoded = decoder.decodeFrame8Bit(src, pic0.getData());
      if (pic1 == null) {
        pic1 =
            Picture8Bit.create(
                decoded.getWidth(), decoded.getHeight(), encoder.getSupportedColorSpaces()[0]);
        transform =
            ColorUtil.getTransform8Bit(decoded.getColor(), encoder.getSupportedColorSpaces()[0]);
      }
      transform.transform(decoded, pic1);
      pic1.setCrop(new Rect(0, 0, track.thumbWidth, track.thumbHeight));
      int rate = TARGET_RATE;
      do {
        try {
          encoder.encodeFrame8Bit(pic1, dst);
          break;
        } catch (BufferOverflowException ex) {
          Logger.warn("Abandon frame, buffer too small: " + dst.capacity());
          rate -= 10;
          rc.setRate(rate);
        }
      } while (rate > 10);
      rc.setRate(TARGET_RATE);

      H264Utils.encodeMOVPacket(dst);

      return dst;
    }
示例#2
0
  public Transcode2AVCTrack(VirtualTrack src, Size frameDim) {
    this.transcoders = new ThreadLocal<Transcoder>();

    checkFourCC(src);
    this.src = src;
    H264FixedRateControl rc = new H264FixedRateControl(TARGET_RATE);
    H264Encoder encoder = new H264Encoder(rc);

    scaleFactor = selectScaleFactor(frameDim);
    thumbWidth = frameDim.getWidth() >> scaleFactor;
    thumbHeight = (frameDim.getHeight() >> scaleFactor) & ~1;

    mbW = (thumbWidth + 15) >> 4;
    mbH = (thumbHeight + 15) >> 4;

    se = createCodecMeta(src, encoder, thumbWidth, thumbHeight);

    frameSize = rc.calcFrameSize(mbW * mbH);
    frameSize += frameSize >> 4;
  }