本文整理汇总了Java中org.jcodec.common.NIOUtils.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java NIOUtils.closeQuietly方法的具体用法?Java NIOUtils.closeQuietly怎么用?Java NIOUtils.closeQuietly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jcodec.common.NIOUtils
的用法示例。
在下文中一共展示了NIOUtils.closeQuietly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: finish
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public void finish() throws IOException {
// Push saved SPS/PPS to a special storage in MP4
outTrack.addSampleEntry(H264Utils.createMOVSampleEntry(spsList, ppsList, 4));
// Write MP4 header and finalize recording
muxer.writeHeader();
NIOUtils.closeQuietly(ch);
}
示例3: close
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
@Override
public void close(){
this.fg = null;
NIOUtils.closeQuietly(this.channel);
this.channel = null;
LOGGER.info("closed JCodecVideoDecoder");
}
示例4: finish
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public void finish() throws IOException {
// Push saved SPS/PPS to a special storage in MP4
outTrack.addSampleEntry(H264Utils.createMOVSampleEntry(spsList, ppsList));
// Write MP4 header and finalize recording
muxer.writeHeader();
NIOUtils.closeQuietly(ch);
}
示例5: getFrame
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
/**
* Get frame at a specified second as AWT image
*
* @param file
* @param second
* @return
* @throws IOException
* @throws JCodecException
*/
public static BufferedImage getFrame(File file, double second) throws IOException, JCodecException {
FileChannelWrapper ch = null;
try {
ch = NIOUtils.readableFileChannel(file);
return ((FrameGrab) new FrameGrab(ch).seekToSecondPrecise(second)).getFrame();
} finally {
NIOUtils.closeQuietly(ch);
}
}
示例6: finish
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public void finish() throws IOException {
// Push saved SPS/PPS to a special storage in MP4
outTrack.addSampleEntry(MP4Muxer.videoSampleEntry("png ", size, "JCodec"));
// Write MP4 header and finalize recording
muxer.writeHeader();
NIOUtils.closeQuietly(ch);
}
示例7: getNativeFrame
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
/**
* Get frame at a specified second as JCodec image
*
* @param file
* @param second
* @return
* @throws IOException
* @throws JCodecException
*/
public static Picture getNativeFrame(File file, double second) throws IOException, JCodecException {
FileChannelWrapper ch = null;
try {
ch = NIOUtils.readableFileChannel(file);
return new FrameGrab(ch).seekToSecondPrecise(second).getNativeFrame();
} finally {
NIOUtils.closeQuietly(ch);
}
}
示例8: saveSlices
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
private static void saveSlices(List<MovieBox> slices, List<String> names, File parentFile) throws IOException {
for (int i = 0; i < slices.size(); i++) {
if (names.get(i) == null)
continue;
SeekableByteChannel out = null;
try {
out = writableFileChannel(new File(parentFile, names.get(i)));
MP4Util.writeMovie(out, slices.get(i));
} finally {
NIOUtils.closeQuietly(out);
}
}
}
示例9: getData
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
@Override
public ByteBuffer getData() throws IOException {
ByteBuffer result = ByteBuffer.allocate(siLen + fsizes[curFrame]);
result.put(si.duplicate());
SeekableByteChannel ch = null;
try {
ch = fp.getChannel();
long curOff = fileOff;
ByteBuffer pesBuf = readPes(ch, curOff, pesLen(pesTokens[pesIdx]), payloadLen(pesTokens[pesIdx]),
pesIdx);
curOff += pesLen(pesTokens[pesIdx]);
NIOUtils.skip(pesBuf, pesOff);
result.put(NIOUtils.read(pesBuf, Math.min(pesBuf.remaining(), result.remaining())));
for (int idx = pesIdx; result.hasRemaining();) {
long posShift = 0;
idx++;
for (; streams[idx] != streamId && idx < pesTokens.length; idx++)
posShift += pesLen(pesTokens[idx]) + leadingSize(pesTokens[idx]);
pesBuf = readPes(ch, curOff + posShift + leadingSize(pesTokens[idx]), pesLen(pesTokens[idx]),
payloadLen(pesTokens[idx]), idx);
curOff += posShift + leadingSize(pesTokens[idx]) + pesLen(pesTokens[idx]);
result.put(NIOUtils.read(pesBuf, Math.min(pesBuf.remaining(), result.remaining())));
}
result.flip();
return result;
} finally {
NIOUtils.closeQuietly(ch);
}
}
示例10: main
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
FileChannelWrapper ch = null;
FileChannelWrapper out = null;
try {
ch = NIOUtils.readableFileChannel(new File(args[0]));
out = NIOUtils.writableFileChannel(new File(args[1]));
new MKVShiftTimecodes(Integer.parseInt(args[2])).run(ch, out);
} finally {
NIOUtils.closeQuietly(ch);
NIOUtils.closeQuietly(out);
}
}
示例11: getPrograms
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public static List<PMTStream> getPrograms(File src) throws IOException {
SeekableByteChannel ch = null;
try {
ch = NIOUtils.readableFileChannel(src);
return getProgramGuids(ch);
} finally {
NIOUtils.closeQuietly(ch);
}
}
示例12: getPrograms
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public static Set<Integer> getPrograms(File file) throws IOException {
FileChannelWrapper fc = null;
try {
fc = NIOUtils.readableFileChannel(file);
return getPrograms(fc);
} finally {
NIOUtils.closeQuietly(fc);
}
}
示例13: getMediaInfo
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public List<MPEGTrackMetadata> getMediaInfo(File f) throws IOException {
FileChannelWrapper ch = null;
final List<MTSUtils.PMT> pmtSections = new ArrayList<MTSUtils.PMT>();
final Map<Integer, MPSMediaInfo> pids = new HashMap<Integer, MPSMediaInfo>();
final List<MPEGTrackMetadata> result = new ArrayList<MPEGTrackMetadata>();
try {
ch = NIOUtils.readableFileChannel(f);
new MTSUtils.TSReader() {
private ByteBuffer pmtBuffer;
private int pmtPid = -1;
private boolean pmtDone;
protected boolean onPkt(int guid, boolean payloadStart, ByteBuffer tsBuf, long filePos) {
if (guid == 0) {
pmtPid = MTSUtils.parsePAT(tsBuf);
} else if (guid == pmtPid && !pmtDone) {
if (pmtBuffer == null) {
pmtBuffer = ByteBuffer.allocate(((tsBuf.duplicate().getInt() >> 8) & 0x3ff) + 3);
} else if (pmtBuffer.hasRemaining()) {
NIOUtils.write(pmtBuffer, tsBuf, Math.min(pmtBuffer.remaining(), tsBuf.remaining()));
}
if (!pmtBuffer.hasRemaining()) {
pmtBuffer.flip();
PMT pmt = MTSUtils.parsePMT(pmtBuffer);
pmtSections.add(pmt);
for (PMTStream stream : pmt.getStreams()) {
if (!pids.containsKey(stream.getPid()))
pids.put(stream.getPid(), new MPSMediaInfo());
}
pmtDone = pmt.getSectionNumber() == pmt.getLastSectionNumber();
pmtBuffer = null;
}
} else if (pids.containsKey(guid)) {
try {
pids.get(guid).analyseBuffer(tsBuf, filePos);
} catch (MediaInfoDone e) {
result.addAll(pids.get(guid).getInfos());
pids.remove(guid);
if (pids.size() == 0)
return false;
}
}
return true;
}
}.readTsFile(ch);
} finally {
NIOUtils.closeQuietly(ch);
}
return result;
}
示例14: remux
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public void remux(File tgt, File src, File timecode, Handler handler) throws IOException {
SeekableByteChannel input = null;
SeekableByteChannel output = null;
SeekableByteChannel tci = null;
try {
input = readableFileChannel(src);
output = writableFileChannel(tgt);
MP4Demuxer demuxer = new MP4Demuxer(input);
TimecodeMP4DemuxerTrack tt = null;
if (timecode != null) {
tci = readableFileChannel(src);
MP4Demuxer tcd = new MP4Demuxer(tci);
tt = tcd.getTimecodeTrack();
}
MP4Muxer muxer = WebOptimizedMP4Muxer.withOldHeader(output, Brand.MOV, demuxer.getMovie());
List<AbstractMP4DemuxerTrack> at = demuxer.getAudioTracks();
List<PCMMP4MuxerTrack> audioTracks = new ArrayList<PCMMP4MuxerTrack>();
for (AbstractMP4DemuxerTrack demuxerTrack : at) {
PCMMP4MuxerTrack att = muxer.addPCMAudioTrack(((AudioSampleEntry) demuxerTrack
.getSampleEntries()[0]).getFormat());
audioTracks.add(att);
att.setEdits(demuxerTrack.getEdits());
att.setName(demuxerTrack.getName());
}
AbstractMP4DemuxerTrack vt = demuxer.getVideoTrack();
FramesMP4MuxerTrack video = muxer.addTrack(VIDEO, (int) vt.getTimescale());
// vt.open(input);
video.setTimecode(muxer.addTimecodeTrack((int) vt.getTimescale()));
copyEdits(vt, video, new Rational((int)vt.getTimescale(), demuxer.getMovie().getTimescale()));
video.addSampleEntries(vt.getSampleEntries());
MP4Packet pkt = null;
while ((pkt = (MP4Packet)vt.nextFrame()) != null) {
if (tt != null)
pkt = tt.getTimecode(pkt);
pkt = processFrame(pkt);
video.addFrame(pkt);
for (int i = 0; i < at.size(); i++) {
AudioSampleEntry ase = (AudioSampleEntry) at.get(i).getSampleEntries()[0];
int frames = (int) (ase.getSampleRate() * pkt.getDuration() / vt.getTimescale());
MP4Packet apkt = (MP4Packet)at.get(i).nextFrame();
audioTracks.get(i).addSamples(apkt.getData());
}
}
MovieBox movie = muxer.finalizeHeader();
if (handler != null)
handler.handle(movie);
muxer.storeHeader(movie);
} finally {
NIOUtils.closeQuietly(input);
NIOUtils.closeQuietly(output);
NIOUtils.closeQuietly(tci);
}
}
示例15: parseIndex
import org.jcodec.common.NIOUtils; //导入方法依赖的package包/类
public void parseIndex(ByteBuffer index) throws IOException {
siLen = index.getInt();
int fCnt = index.getInt();
fsizes = new int[fCnt];
fpts = new long[fCnt];
for (int i = 0; i < fCnt; i++) {
int size = index.getInt();
fsizes[i] = size;
}
int syncCount = index.getInt();
sync = new int[syncCount];
for (int i = 0; i < syncCount; i++)
sync[i] = index.getInt();
for (int i = 0; i < fCnt; i++) {
fpts[i] = index.getInt() & 0xffffffffL;
}
long[] seg0 = Arrays.copyOf(fpts, 10);
Arrays.sort(seg0);
long[] seg1 = new long[10];
System.arraycopy(fpts, fpts.length - 10, seg1, 0, 10);
Arrays.sort(seg1);
duration = (seg1[9] - seg0[0] + (fpts.length >> 1)) / fpts.length;
offInPayload = siLen;
for (fileOff = 0; streams[pesIdx] != streamId; fileOff += pesLen(pesTokens[pesIdx])
+ leadingSize(pesTokens[pesIdx]), pesIdx++)
;
fileOff += leadingSize(pesTokens[pesIdx]);
SeekableByteChannel ch = null;
try {
ch = fp.getChannel();
ByteBuffer firstPes = readPes(ch, fileOff, pesLen(pesTokens[pesIdx]), payloadLen(pesTokens[pesIdx]),
pesIdx);
si = NIOUtils.read(firstPes, siLen);
} finally {
NIOUtils.closeQuietly(ch);
}
}