当前位置: 首页>>代码示例>>Java>>正文


Java MP4Packet.getDuration方法代码示例

本文整理汇总了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;
}
 
开发者ID:ihmcrobotics,项目名称:ihmc-video-codecs,代码行数:45,代码来源:FramesMP4MuxerTrack.java

示例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);
    }
}
 
开发者ID:PenoaksDev,项目名称:OpenSpaceDVR,代码行数:62,代码来源:Remux.java


注:本文中的org.jcodec.containers.mp4.MP4Packet.getDuration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。