Example #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;
    }
Example #2
0
  private static void mux(FramesMP4MuxerTrack track, File f) throws IOException {
    MappedH264ES es = new MappedH264ES(NIOUtils.map(f));

    ArrayList<ByteBuffer> spsList = new ArrayList<ByteBuffer>();
    ArrayList<ByteBuffer> ppsList = new ArrayList<ByteBuffer>();
    Packet frame = null;
    while ((frame = es.nextFrame()) != null) {
      ByteBuffer data = frame.getData();
      H264Utils.wipePS(data, spsList, ppsList);
      H264Utils.encodeMOVPacket(data);
      MP4Packet pkt = new MP4Packet(new Packet(frame, data), frame.getPts(), 0);
      System.out.println(pkt.getFrameNo());
      track.addFrame(pkt);
    }
    addSampleEntry(track, es.getSps(), es.getPps());
  }