本文整理汇总了Java中org.jcodec.common.NIOUtils类的典型用法代码示例。如果您正苦于以下问题:Java NIOUtils类的具体用法?Java NIOUtils怎么用?Java NIOUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NIOUtils类属于org.jcodec.common包,在下文中一共展示了NIOUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SequenceEncoderMp4
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public SequenceEncoderMp4(File out)
throws IOException
{
super(out);
this.ch = NIOUtils.writableFileChannel(out);
// Muxer that will store the encoded frames
muxer = new MP4Muxer(ch, Brand.MP4);
// Add video track to muxer
outTrack = muxer.addTrack(TrackType.VIDEO, 5);
// Allocate a buffer big enough to hold output frames
_out = ByteBuffer.allocate(1920 * 1080 * 6);
// Create an instance of encoder
encoder = new H264Encoder();
// Transform to convert between RGB and YUV
transform = ColorUtil.getTransform(ColorSpace.RGB, encoder.getSupportedColorSpaces()[0]);
// Encoder extra data ( SPS, PPS ) to be stored in a special place of
// MP4
spsList = new ArrayList<ByteBuffer>();
ppsList = new ArrayList<ByteBuffer>();
}
示例2: SequenceEncoderMp4
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public SequenceEncoderMp4(File out)
throws IOException
{
super(out);
this.ch = NIOUtils.writableFileChannel(out);
// Muxer that will store the encoded frames
muxer = new MP4Muxer(ch, Brand.MP4);
// Add video track to muxer
outTrack = muxer.addTrack(TrackType.VIDEO, timeScale);
// Allocate a buffer big enough to hold output frames
_out = ByteBuffer.allocate(1920 * 1080 * 6);
// Create an instance of encoder
encoder = new H264Encoder();
// Transform to convert between RGB and YUV
transform = ColorUtil.getTransform(ColorSpace.RGB, encoder.getSupportedColorSpaces()[0]);
// Encoder extra data ( SPS, PPS ) to be stored in a special place of
// MP4
spsList = new ArrayList<ByteBuffer>();
ppsList = new ArrayList<ByteBuffer>();
}
示例3: SequenceImagesEncoder
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public SequenceImagesEncoder(File out, int screenWidth, int screenHeight) throws IOException {
this.ch = NIOUtils.writableFileChannel(out);
// Transform to convert between RGB and YUV
transform = new RgbToYuv420(0, 0);
// Muxer that will store the encoded frames
muxer = new MP4Muxer(ch, Brand.MP4);
// Add video track to muxer
outTrack = muxer.addTrackForCompressed(TrackType.VIDEO, timescale);
// Allocate a buffer big enough to hold output frames
_out = ByteBuffer.allocate(screenWidth * screenHeight * 6);
// Create an instance of encoder
encoder = new H264Encoder();
// Encoder extra data ( SPS, PPS ) to be stored in a special place of
// MP4
spsList = new ArrayList<ByteBuffer>();
ppsList = new ArrayList<ByteBuffer>();
}
示例4: parse
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
@Override
public void parse(ByteBuffer input) {
NIOUtils.skip(input, 1);
profile = input.get() & 0xff;
profileCompat = input.get() & 0xff;
level = input.get() & 0xff;
int flags = input.get() & 0xff;
nalLengthSize = (flags & 0x03) + 1;
int nSPS = input.get() & 0x1f; // 3 bits reserved + 5 bits number of
// sps
for (int i = 0; i < nSPS; i++) {
int spsSize = input.getShort();
Assert.assertEquals(0x27, input.get() & 0x3f);
spsList.add(NIOUtils.read(input, spsSize - 1));
}
int nPPS = input.get() & 0xff;
for (int i = 0; i < nPPS; i++) {
int ppsSize = input.getShort();
Assert.assertEquals(0x28, input.get() & 0x3f);
ppsList.add(NIOUtils.read(input, ppsSize - 1));
}
}
示例5: doWrite
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
@Override
protected void doWrite(ByteBuffer out) {
out.put((byte) 0x1); // version
out.put((byte) profile);
out.put((byte) profileCompat);
out.put((byte) level);
out.put((byte) 0xff);
out.put((byte) (spsList.size() | 0xe0));
for (ByteBuffer sps : spsList) {
out.putShort((short) (sps.remaining() + 1));
out.put((byte) 0x67);
NIOUtils.write(out, sps);
}
out.put((byte) ppsList.size());
for (ByteBuffer pps : ppsList) {
out.putShort((byte) (pps.remaining() + 1));
out.put((byte) 0x68);
NIOUtils.write(out, pps);
}
}
示例6: getRootAtoms
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public static List<Atom> getRootAtoms(SeekableByteChannel input) throws IOException {
input.position(0);
List<Atom> result = new ArrayList<Atom>();
long off = 0;
Header atom;
while (off < input.size()) {
input.position(off);
atom = Header.read(NIOUtils.fetchFrom(input, 16));
if (atom == null)
break;
result.add(new Atom(atom, off));
off += atom.getSize();
}
return result;
}
示例7: getTimecodeSample
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
private int getTimecodeSample(int sample) throws IOException {
if (sampleCache != null)
return sampleCache[sample];
else {
synchronized (input) {
int stscInd, stscSubInd;
for (stscInd = 0, stscSubInd = sample; stscInd < sampleToChunks.length
&& stscSubInd >= sampleToChunks[stscInd].getCount(); stscSubInd -= sampleToChunks[stscInd]
.getCount(), stscInd++)
;
long offset = chunkOffsets[stscInd]
+ (Math.min(stscSubInd, sampleToChunks[stscInd].getCount() - 1) << 2);
if (input.position() != offset)
input.position(offset);
ByteBuffer buf = NIOUtils.fetchFrom(input, 4);
return buf.getInt();
}
}
}
示例8: cacheSamples
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
private void cacheSamples(SampleToChunkEntry[] sampleToChunks, long[] chunkOffsets) throws IOException {
synchronized (input) {
int stscInd = 0;
IntArrayList ss = new IntArrayList();
for (int chunkNo = 0; chunkNo < chunkOffsets.length; chunkNo++) {
int nSamples = sampleToChunks[stscInd].getCount();
if (stscInd < sampleToChunks.length - 1 && chunkNo + 1 >= sampleToChunks[stscInd + 1].getFirst())
stscInd++;
long offset = chunkOffsets[chunkNo];
input.position(offset);
ByteBuffer buf = NIOUtils.fetchFrom(input, nSamples * 4);
for (int i = 0; i < nSamples; i++) {
ss.add(buf.getInt());
}
}
sampleCache = ss.toArray();
}
}
示例9: probe
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public static int probe(final ByteBuffer b) {
ByteBuffer fork = b.duplicate();
int success = 0;
int total = 0;
while (fork.remaining() >= 8) {
long len = fork.getInt() & 0xffffffffL;
int fcc = fork.getInt();
int hdrLen = 8;
if (len == 1) {
len = fork.getLong();
hdrLen = 16;
} else if (len < 8)
break;
if (fcc == ftyp && len < 64 || fcc == moov && len < 100 * 1024 * 1024 || fcc == free || fcc == mdat || fcc == wide)
success++;
total++;
if (len >= Integer.MAX_VALUE)
break;
NIOUtils.skip(fork, (int) (len - hdrLen));
}
return total == 0 ? 0 : success * 100 / total;
}
示例10: read
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public static Header read(ByteBuffer input) {
long size = 0;
while (input.remaining() >= 4 && (size = (((long) input.getInt()) & 0xffffffffL)) == 0)
;
if (input.remaining() < 4 || size < 8 && size != 1) {
Logger.error("Broken atom of size " + size);
return null;
}
String fourcc = NIOUtils.readString(input, 4);
boolean lng = false;
if (size == 1) {
if (input.remaining() >= 8) {
lng = true;
size = input.getLong();
} else {
Logger.error("Broken atom of size " + size);
return null;
}
}
return new Header(fourcc, size, lng);
}
示例11: parse
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public void parse(ByteBuffer input) {
super.parse(input);
if (version == 0) {
created = fromMovTime(input.getInt());
modified = fromMovTime(input.getInt());
timescale = input.getInt();
duration = input.getInt();
} else if (version == 1) {
created = fromMovTime((int) input.getLong());
modified = fromMovTime((int) input.getLong());
timescale = input.getInt();
duration = input.getLong();
} else {
throw new RuntimeException("Unsupported version");
}
rate = readRate(input);
volume = readVolume(input);
NIOUtils.skip(input, 10);
matrix = readMatrix(input);
NIOUtils.skip(input, 24);
nextTrackId = input.getInt();
}
示例12: storeHeader
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
@Override
public void storeHeader(MovieBox movie) throws IOException {
long mdatEnd = out.position();
long mdatSize = mdatEnd - mdatOffset + 8;
out.position(mdatOffset);
NIOUtils.writeLong(out, mdatSize);
out.position(headerPos);
try {
movie.write(header);
header.flip();
int rem = header.capacity() - header.limit();
if (rem < 8) {
header.duplicate().putInt(header.capacity());
}
out.write(header);
if (rem >= 8)
new Header("free", rem).write(out);
} catch (ArrayIndexOutOfBoundsException e) {
Logger.warn("Could not web-optimize, header is bigger then allocated space.");
new Header("free", header.remaining()).write(out);
out.position(mdatEnd);
MP4Util.writeMovie(out, movie);
}
}
示例13: SequenceEncoder
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
public SequenceEncoder(File out, int frameRate) throws IOException {
this.ch = NIOUtils.writableFileChannel(out);
// Transform to convert between RGB and YUV
transform = new RgbToYuv420(0, 0);
// Muxer that will store the encoded frames
muxer = new MP4Muxer(ch, Brand.MP4);
// Add video track to muxer
outTrack = muxer.addTrackForCompressed(TrackType.VIDEO, frameRate);// original frmae rate is 25
// Allocate a buffer big enough to hold output frames
_out = ByteBuffer.allocate(1920 * 1080 * 6);
// Create an instance of encoder
encoder = new H264Encoder();
// Encoder extra data ( SPS, PPS ) to be stored in a special place of
// MP4
spsList = new ArrayList<ByteBuffer>();
ppsList = new ArrayList<ByteBuffer>();
}
示例14: getData
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
@Override
public ByteBuffer getData() throws IOException {
SeekableByteChannel ch = null;
try {
ch = fp.getChannel();
ch.position(pkt.getOffset());
KLV kl = KLV.readKL(ch);
while (kl != null && !essenceUL.equals(kl.key)) {
ch.position(ch.position() + kl.len);
kl = KLV.readKL(ch);
}
return kl != null && essenceUL.equals(kl.key) ? NIOUtils.fetchFrom(ch, (int) kl.len) : null;
} finally {
NIOUtils.closeQuietly(ch);
}
}
示例15: decodePicture
import org.jcodec.common.NIOUtils; //导入依赖的package包/类
protected void decodePicture(ByteBuffer data, int[][] result, int width, int height, int mbWidth, int[] qMatLuma,
int[] qMatChroma, int[] scan, int pictureType, int chromaType) {
ProresConsts.PictureHeader ph = readPictureHeader(data);
// int mbWidth = (width + 15) >> 4;
// int mbHeight = (height + 15) >> 4;
int mbX = 0, mbY = 0;
int sliceMbCount = 1 << ph.log2SliceMbWidth;
for (int i = 0; i < ph.sliceSizes.length; i++) {
while (mbWidth - mbX < sliceMbCount)
sliceMbCount >>= 1;
decodeSlice(NIOUtils.read(data, ph.sliceSizes[i]), qMatLuma, qMatChroma, scan, sliceMbCount, mbX, mbY,
ph.sliceSizes[i], result, width, pictureType, chromaType);
mbX += sliceMbCount;
if (mbX == mbWidth) {
sliceMbCount = 1 << ph.log2SliceMbWidth;
mbX = 0;
mbY++;
}
}
}