本文整理汇总了Java中org.jcodec.containers.mp4.MP4Packet.getDuration方法的典型用法代码示例。如果您正苦于以下问题:Java MP4Packet.getDuration方法的具体用法?Java MP4Packet.getDuration怎么用?Java MP4Packet.getDuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jcodec.containers.mp4.MP4Packet
的用法示例。
在下文中一共展示了MP4Packet.getDuration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFrame
import org.jcodec.containers.mp4.MP4Packet; //导入方法依赖的package包/类
public void addFrame(MP4Packet pkt) throws IOException {
if (finished)
throw new IllegalStateException("The muxer track has finished muxing");
int entryNo = pkt.getEntryNo() + 1;
int compositionOffset = (int) (pkt.getPts() - ptsEstimate);
if (compositionOffset != lastCompositionOffset) {
if (lastCompositionSamples > 0)
compositionOffsets.add(new Entry(lastCompositionSamples, lastCompositionOffset));
lastCompositionOffset = compositionOffset;
lastCompositionSamples = 0;
}
lastCompositionSamples++;
ptsEstimate += pkt.getDuration();
if (lastEntry != -1 && lastEntry != entryNo) {
outChunk(lastEntry);
samplesInLastChunk = -1;
}
curChunk.add(pkt.getData());
if (pkt.isKeyFrame())
iframes.add(curFrame + 1);
else
allIframes = false;
curFrame++;
chunkDuration += pkt.getDuration();
if (curDuration != -1 && pkt.getDuration() != curDuration) {
sampleDurations.add(new TimeToSampleEntry((int) sameDurCount, (int) curDuration));
sameDurCount = 0;
}
curDuration = pkt.getDuration();
sameDurCount++;
trackTotalDuration += pkt.getDuration();
outChunkIfNeeded(entryNo);
processTimecode(pkt);
lastEntry = entryNo;
}
示例2: remux
import org.jcodec.containers.mp4.MP4Packet; //导入方法依赖的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);
}
}