Esempio n. 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;
    }
Esempio n. 2
0
  public static VideoCodecMeta createCodecMeta(
      VirtualTrack src, H264Encoder encoder, int thumbWidth, int thumbHeight) {
    VideoCodecMeta codecMeta = (VideoCodecMeta) src.getCodecMeta();

    AvcCBox createAvcC =
        H264Utils.createAvcC(
            encoder.initSPS(new Size(thumbWidth, thumbHeight)), encoder.initPPS(), 4);
    return VideoCodecMeta.createVideoCodecMeta(
        "avc1",
        H264Utils.getAvcCData(createAvcC),
        new Size(thumbWidth, thumbHeight),
        codecMeta.getPasp());
  }