@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); }
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()); }
public ByteBuffer transcode(ByteBuffer data, ByteBuffer _out) { return transcode(H264Utils.splitFrame(data), _out); }
@Override public Frame decodeFrame8Bit(ByteBuffer data, byte[][] buffer) { return new FrameDecoder().decodeFrame(H264Utils.splitFrame(data), buffer); }
@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); }