
org.jcodec.movtool.streaming.VirtualWebmMovie Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcodec-streaming Show documentation
Show all versions of jcodec-streaming Show documentation
Pure Java implementation of video/audio codecs and formats
The newest version!
package org.jcodec.movtool.streaming;
import java.lang.IllegalStateException;
import java.lang.System;
import org.jcodec.containers.mkv.MKVStreamingMuxer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* This class is part of JCodec ( www.jcodec.org ) This software is distributed under FreeBSD License
*
* WebM specific muxing
*
* @author The JCodec project
*
*/
public class VirtualWebmMovie extends VirtualMovie {
private MKVStreamingMuxer muxer = null;
public VirtualWebmMovie(VirtualTrack... arguments) throws IOException {
super(arguments);
muxer = new MKVStreamingMuxer();
muxTracks();
}
@Override
protected void muxTracks() throws IOException {
List chch = new ArrayList();
VirtualPacket[] heads = new VirtualPacket[tracks.length], tails = new VirtualPacket[tracks.length];
long currentlyAddedContentSize = 0;
for (int curChunk = 1;; curChunk++) {
int min = -1;
for (int i = 0; i < heads.length; i++) {
if (heads[i] == null) {
heads[i] = tracks[i].nextPacket();
if (heads[i] == null)
continue;
}
min = min == -1 || heads[i].getPts() < heads[min].getPts() ? i : min;
}
if (min == -1)
break;
MovieSegment packetChunk = packetChunk(tracks[min], heads[min], curChunk, min, currentlyAddedContentSize);
chch.add(packetChunk);
currentlyAddedContentSize += packetChunk.getDataLen();
tails[min] = heads[min];
heads[min] = tracks[min].nextPacket();
}
_headerChunk = headerChunk(chch, tracks, _size);
_size += _headerChunk.getDataLen()+currentlyAddedContentSize;
chunks = chch.toArray(new MovieSegment[0]);
}
@Override
protected MovieSegment packetChunk(VirtualTrack track, VirtualPacket pkt, int chunkNo, int trackNo, long previousClustersSize) {
return muxer.preparePacket(track, pkt, chunkNo, trackNo, previousClustersSize);
}
@Override
protected MovieSegment headerChunk(List chunks, VirtualTrack[] tracks, long dataSize) throws IOException {
return muxer.prepareHeader(chunks, tracks);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy