Here you can find the source of putNAL(ByteBuffer codecPrivate, ByteBuffer byteBuffer, int nalType)
private static void putNAL(ByteBuffer codecPrivate, ByteBuffer byteBuffer, int nalType)
//package com.java2s; /**// w ww . j a va 2 s . com * This class is part of JCodec ( www.jcodec.org ) This software is distributed * under FreeBSD License * * @author The JCodec project * */ import java.nio.ByteBuffer; public class Main { private static void putNAL(ByteBuffer codecPrivate, ByteBuffer byteBuffer, int nalType) { ByteBuffer dst = ByteBuffer.allocate(byteBuffer.remaining() * 2); escapeNAL(byteBuffer, dst); dst.flip(); codecPrivate.putInt(1); codecPrivate.put((byte) nalType); codecPrivate.put(dst); } public static final void escapeNAL(ByteBuffer src, ByteBuffer dst) { byte p1 = src.get(), p2 = src.get(); dst.put(p1); dst.put(p2); while (src.hasRemaining()) { byte b = src.get(); if (p1 == 0 && p2 == 0 && (b & 0xff) <= 3) { dst.put((byte) 3); p1 = p2; p2 = 3; } dst.put(b); p1 = p2; p2 = b; } } }