예제 #1
0
  @Override
  public int probe(ByteBuffer data) {
    boolean validSps = false, validPps = false, validSh = false;
    for (ByteBuffer nalUnit : H264Utils.splitFrame(data.duplicate())) {
      NALUnit marker = NALUnit.read(nalUnit);
      if (marker.type == NALUnitType.IDR_SLICE || marker.type == NALUnitType.NON_IDR_SLICE) {
        BitReader reader = new BitReader(nalUnit);
        validSh = validSh(new SliceHeaderReader().readPart1(reader));
        break;
      } else if (marker.type == NALUnitType.SPS) {
        validSps = validSps(SeqParameterSet.read(nalUnit));
      } else if (marker.type == NALUnitType.PPS) {
        validPps = validPps(PictureParameterSet.read(nalUnit));
      }
    }

    return (validSh ? 60 : 0) + (validSps ? 20 : 0) + (validPps ? 20 : 0);
  }
예제 #2
0
  private void writeH264WithStartCode(AVPacket frame) throws IOException {
    ByteBuffer data = frame.getByteBuffer();
    if (data.remaining() > 4 && 1 != data.getInt(data.position())) {
      logger.warn("H264 Not Start With 0x00 00 00 01");
      return;
    }
    List<ByteBuffer> segs = H264Utils.splitFrame(data);

    int dataSize = 5 + 4 * segs.size();
    for (ByteBuffer seg : segs) {
      dataSize += seg.remaining();
    }

    ChannelBuffer avc = ChannelBuffers.buffer(11 + dataSize + 4 + 4 + 5);
    avc.writeByte(0x09); // video type
    avc.writeMedium(dataSize); // tag data size

    // timestamp
    long timestamp = frame.getTimestamp(AVTimeUnit.MILLISECONDS);
    avc.writeMedium((int) (0xFFFFFF & timestamp));
    avc.writeByte((int) (0xFF & (timestamp >> 24)));

    avc.writeMedium(0x0); // stream id

    avc.writeByte(frame.isKeyFrame() ? 0x17 : 0x27); // key frame + avc
    avc.writeByte(0x01); // avc NAL
    avc.writeMedium(
        (int) frame.getCompositionTime(AVTimeUnit.MILLISECONDS)); // Composition time offset

    // data
    for (ByteBuffer seg : segs) {
      avc.writeInt(seg.remaining());
      avc.writeBytes(seg);
    }

    avc.writeInt(avc.readableBytes()); // pre tag size

    avc.readBytes(out, avc.readableBytes());
  }
예제 #3
0
 public ByteBuffer transcode(ByteBuffer data, ByteBuffer _out) {
   return transcode(H264Utils.splitFrame(data), _out);
 }
예제 #4
0
 @Override
 public Frame decodeFrame8Bit(ByteBuffer data, byte[][] buffer) {
   return new FrameDecoder().decodeFrame(H264Utils.splitFrame(data), buffer);
 }
예제 #5
0
 @Override
 public Picture decodeFrame(ByteBuffer data, int[][] buffer) {
   Frame frame =
       new FrameDecoder().decodeFrame(H264Utils.splitFrame(data), getSameSizeBuffer(buffer));
   return frame == null ? null : frame.toPicture(8, buffer);
 }