本文整理汇总了Java中com.coremedia.iso.boxes.TrackBox类的典型用法代码示例。如果您正苦于以下问题:Java TrackBox类的具体用法?Java TrackBox怎么用?Java TrackBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TrackBox类属于com.coremedia.iso.boxes包,在下文中一共展示了TrackBox类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: muxerFileDebug
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public static void muxerFileDebug(){
try
{
File input = new File(SDCardUtils.getExternalSdCardPath() + "/a.h264");
File output = new File(SDCardUtils.getExternalSdCardPath() + "/b.mp4");
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(input), "eng", UriParser.videoQuality.framerate, 1);
Movie m = new Movie();
m.addTrack(h264Track);
m.setMatrix(Matrix.ROTATE_90);
Container out = new DefaultMp4Builder().build(m);
MovieHeaderBox mvhd = Path.getPath(out, "moov/mvhd");
mvhd.setMatrix(Matrix.ROTATE_90);
TrackBox trackBox = Path.getPath(out, "moov/trak");
TrackHeaderBox tkhd = trackBox.getTrackHeaderBox();
tkhd.setMatrix(Matrix.ROTATE_90);
FileChannel fc = new FileOutputStream(output.getAbsolutePath()).getChannel();
out.writeContainer(fc);
fc.close();
}
catch (IOException e) {
Log.e("test", "some exception", e);
}
}
示例2: build
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public static Movie build(ReadableByteChannel channel) throws IOException {
IsoFile isoFile = new IsoFile(channel);
Movie m = new Movie();
List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class);
for (TrackBox trackBox : trackBoxes) {
m.addTrack(new Mp4TrackImpl(trackBox));
}
return m;
}
示例3: createTrak
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
protected Box createTrak(Track track, Movie movie) {
LOG.fine("Creating Track " + track);
TrackBox trackBox = new TrackBox();
trackBox.addBox(createTkhd(movie, track));
trackBox.addBox(createMdia(track, movie));
return trackBox;
}
示例4: handleSegment
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
/**
* Handles a segment by merging it with the init segment into a temporary file.
*/
private void handleSegment(byte[] mediaSegment, CachedSegment cachedSegment) throws IOException {
File segmentFile = getTempFile(mContext, "seg" + cachedSegment.representation.id + "-" + cachedSegment.segment.range + "");
long segmentPTSOffsetUs = 0;
if(mMp4Mode) {
/* The MP4 iso format needs special treatment because the Android MediaExtractor/MediaCodec
* does not support the fragmented MP4 container format. Each segment therefore needs
* to be joined with the init fragment and converted to a "conventional" unfragmented MP4
* container file. */
IsoFile baseIsoFile = new IsoFile(new MemoryDataSourceImpl(mInitSegments.get(cachedSegment.representation).asByteBuffer()));
IsoFile fragment = new IsoFile(new MemoryDataSourceImpl(mediaSegment));
/* The PTS in a converted MP4 always start at 0, so we read the offset from the segment
* index box and work with it at the necessary places to adjust the local PTS to global
* PTS concerning the whole stream. */
List<SegmentIndexBox> segmentIndexBoxes = fragment.getBoxes(SegmentIndexBox.class);
if(segmentIndexBoxes.size() > 0) {
SegmentIndexBox sidx = segmentIndexBoxes.get(0);
segmentPTSOffsetUs = (long) ((double) sidx.getEarliestPresentationTime() / sidx.getTimeScale() * 1000000);
}
/* If there is no segment index box to read the PTS from, we calculate the PTS offset
* from the info given in the MPD. */
else {
segmentPTSOffsetUs = cachedSegment.number * cachedSegment.representation.segmentDurationUs;
}
Movie mp4Segment = new Movie();
for(TrackBox trackBox : baseIsoFile.getMovieBox().getBoxes(TrackBox.class)) {
mp4Segment.addTrack(new Mp4TrackImpl(null, trackBox, fragment));
}
Container mp4SegmentContainer = new DefaultMp4Builder().build(mp4Segment); // always create new instance to avoid memory leaks!
FileOutputStream fos = new FileOutputStream(segmentFile, false);
mp4SegmentContainer.writeContainer(fos.getChannel());
fos.close();
} else {
// merge init and media segments into file
BufferedSink segmentFileSink = Okio.buffer(Okio.sink(segmentFile));
segmentFileSink.write(mInitSegments.get(cachedSegment.representation));
segmentFileSink.write(mediaSegment);
segmentFileSink.close();
}
cachedSegment.file = segmentFile;
cachedSegment.ptsOffsetUs = segmentPTSOffsetUs;
}
示例5: createTrackBox
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
protected TrackBox createTrackBox(Track track, Mp4Movie movie) {
TrackBox trackBox = new TrackBox();
TrackHeaderBox tkhd = new TrackHeaderBox();
tkhd.setEnabled(true);
tkhd.setInMovie(true);
tkhd.setInPreview(true);
if (track.isAudio()) {
tkhd.setMatrix(Matrix.ROTATE_0);
} else {
tkhd.setMatrix(movie.getMatrix());
}
tkhd.setAlternateGroup(0);
tkhd.setCreationTime(track.getCreationTime());
tkhd.setDuration(track.getDuration() * getTimescale(movie) / track.getTimeScale());
tkhd.setHeight(track.getHeight());
tkhd.setWidth(track.getWidth());
tkhd.setLayer(0);
tkhd.setModificationTime(new Date());
tkhd.setTrackId(track.getTrackId() + 1);
tkhd.setVolume(track.getVolume());
trackBox.addBox(tkhd);
MediaBox mdia = new MediaBox();
trackBox.addBox(mdia);
MediaHeaderBox mdhd = new MediaHeaderBox();
mdhd.setCreationTime(track.getCreationTime());
mdhd.setDuration(track.getDuration());
mdhd.setTimescale(track.getTimeScale());
mdhd.setLanguage("eng");
mdia.addBox(mdhd);
HandlerBox hdlr = new HandlerBox();
hdlr.setName(track.isAudio() ? "SoundHandle" : "VideoHandle");
hdlr.setHandlerType(track.getHandler());
mdia.addBox(hdlr);
MediaInformationBox minf = new MediaInformationBox();
minf.addBox(track.getMediaHeaderBox());
DataInformationBox dinf = new DataInformationBox();
DataReferenceBox dref = new DataReferenceBox();
dinf.addBox(dref);
DataEntryUrlBox url = new DataEntryUrlBox();
url.setFlags(1);
dref.addBox(url);
minf.addBox(dinf);
Box stbl = createStbl(track);
minf.addBox(stbl);
mdia.addBox(minf);
return trackBox;
}
示例6: SampleList
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public SampleList(TrackBox trackBox) {
initIsoFile(trackBox.getIsoFile()); // where are we?
// first we get all sample from the 'normal' MP4 part.
// if there are none - no problem.
SampleSizeBox sampleSizeBox = trackBox.getSampleTableBox().getSampleSizeBox();
ChunkOffsetBox chunkOffsetBox = trackBox.getSampleTableBox().getChunkOffsetBox();
SampleToChunkBox sampleToChunkBox = trackBox.getSampleTableBox().getSampleToChunkBox();
final long[] chunkOffsets = chunkOffsetBox != null ? chunkOffsetBox.getChunkOffsets() : new long[0];
if (sampleToChunkBox != null && sampleToChunkBox.getEntries().size() > 0 &&
chunkOffsets.length > 0 && sampleSizeBox != null && sampleSizeBox.getSampleCount() > 0) {
long[] numberOfSamplesInChunk = sampleToChunkBox.blowup(chunkOffsets.length);
int sampleIndex = 0;
if (sampleSizeBox.getSampleSize() > 0) {
sizes = new long[l2i(sampleSizeBox.getSampleCount())];
Arrays.fill(sizes, sampleSizeBox.getSampleSize());
} else {
sizes = sampleSizeBox.getSampleSizes();
}
offsets = new long[sizes.length];
for (int i = 0; i < numberOfSamplesInChunk.length; i++) {
long thisChunksNumberOfSamples = numberOfSamplesInChunk[i];
long sampleOffset = chunkOffsets[i];
for (int j = 0; j < thisChunksNumberOfSamples; j++) {
long sampleSize = sizes[sampleIndex];
offsets[sampleIndex] = sampleOffset;
sampleOffset += sampleSize;
sampleIndex++;
}
}
}
// Next we add all samples from the fragments
// in most cases - I've never seen it different it's either normal or fragmented.
List<MovieExtendsBox> movieExtendsBoxes = trackBox.getParent().getBoxes(MovieExtendsBox.class);
if (movieExtendsBoxes.size() > 0) {
Map<Long, Long> offsets2Sizes = new HashMap<Long, Long>();
List<TrackExtendsBox> trackExtendsBoxes = movieExtendsBoxes.get(0).getBoxes(TrackExtendsBox.class);
for (TrackExtendsBox trackExtendsBox : trackExtendsBoxes) {
if (trackExtendsBox.getTrackId() == trackBox.getTrackHeaderBox().getTrackId()) {
for (MovieFragmentBox movieFragmentBox : trackBox.getIsoFile().getBoxes(MovieFragmentBox.class)) {
offsets2Sizes.putAll(getOffsets(movieFragmentBox, trackBox.getTrackHeaderBox().getTrackId(), trackExtendsBox));
}
}
}
if (sizes == null || offsets == null) {
sizes = new long[0];
offsets = new long[0];
}
splitToArrays(offsets2Sizes);
}
// We have now a map from all sample offsets to their sizes
}
示例7: createTrackBox
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
private TrackBox createTrackBox(Track track, Mp4Movie movie) {
TrackBox trackBox = new TrackBox();
TrackHeaderBox tkhd = new TrackHeaderBox();
tkhd.setEnabled(true);
tkhd.setInMovie(true);
tkhd.setInPreview(true);
if (track.isAudio()) {
tkhd.setMatrix(Matrix.ROTATE_0);
} else {
tkhd.setMatrix(movie.getMatrix());
}
tkhd.setAlternateGroup(0);
tkhd.setCreationTime(track.getCreationTime());
tkhd.setModificationTime(track.getCreationTime());
tkhd.setDuration(track.getDuration() * getTimescale(movie) / track.getTimeScale());
tkhd.setHeight(track.getHeight());
tkhd.setWidth(track.getWidth());
tkhd.setLayer(0);
tkhd.setModificationTime(new Date());
tkhd.setTrackId(track.getTrackId() + 1);
tkhd.setVolume(track.getVolume());
trackBox.addBox(tkhd);
MediaBox mdia = new MediaBox();
trackBox.addBox(mdia);
MediaHeaderBox mdhd = new MediaHeaderBox();
mdhd.setCreationTime(track.getCreationTime());
mdhd.setModificationTime(track.getCreationTime());
mdhd.setDuration(track.getDuration());
mdhd.setTimescale(track.getTimeScale());
mdhd.setLanguage("eng");
mdia.addBox(mdhd);
HandlerBox hdlr = new HandlerBox();
hdlr.setName(track.isAudio() ? "SoundHandle" : "VideoHandle");
hdlr.setHandlerType(track.getHandler());
mdia.addBox(hdlr);
MediaInformationBox minf = new MediaInformationBox();
minf.addBox(track.getMediaHeaderBox());
DataInformationBox dinf = new DataInformationBox();
DataReferenceBox dref = new DataReferenceBox();
dinf.addBox(dref);
DataEntryUrlBox url = new DataEntryUrlBox();
url.setFlags(1);
dref.addBox(url);
minf.addBox(dinf);
Box stbl = createStbl(track);
minf.addBox(stbl);
mdia.addBox(minf);
return trackBox;
}
示例8: handleSegment
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
/**
* Handles a segment by merging it with the init segment into a temporary file.
*/
private void handleSegment(byte[] mediaSegment, CachedSegment cachedSegment) throws IOException {
File segmentFile = getTempFile(mContext, "seg" + cachedSegment.representation.id + "-" + cachedSegment.segment.range + "");
long segmentPTSOffsetUs = 0;
if(mMp4Mode) {
/* The MP4 iso format needs special treatment because the Android MediaExtractor/MediaCodec
* does not support the fragmented MP4 container format. Each segment therefore needs
* to be joined with the init fragment and converted to a "conventional" unfragmented MP4
* container file. */
IsoFile baseIsoFile = new IsoFile(new MemoryDataSourceImpl(mInitSegments.get(cachedSegment.representation).toByteArray())); // TODO do not go ByteString -> byte[] -> ByteBuffer, find more efficient way (custom mp4parser DataSource maybe?)
IsoFile fragment = new IsoFile(new MemoryDataSourceImpl(mediaSegment));
/* The PTS in a converted MP4 always start at 0, so we read the offset from the segment
* index box and work with it at the necessary places to adjust the local PTS to global
* PTS concerning the whole stream. */
List<SegmentIndexBox> segmentIndexBoxes = fragment.getBoxes(SegmentIndexBox.class);
if(segmentIndexBoxes.size() > 0) {
SegmentIndexBox sidx = segmentIndexBoxes.get(0);
segmentPTSOffsetUs = (long) ((double) sidx.getEarliestPresentationTime() / sidx.getTimeScale() * 1000000);
}
/* If there is no segment index box to read the PTS from, we calculate the PTS offset
* from the info given in the MPD. */
else {
segmentPTSOffsetUs = cachedSegment.number * cachedSegment.representation.segmentDurationUs;
}
Movie mp4Segment = new Movie();
for(TrackBox trackBox : baseIsoFile.getMovieBox().getBoxes(TrackBox.class)) {
mp4Segment.addTrack(new Mp4TrackImpl(null, trackBox, fragment));
}
Container mp4SegmentContainer = mMp4Builder.build(mp4Segment);
FileOutputStream fos = new FileOutputStream(segmentFile, false);
mp4SegmentContainer.writeContainer(fos.getChannel());
fos.close();
} else {
// merge init and media segments into file
BufferedSink segmentFileSink = Okio.buffer(Okio.sink(segmentFile));
segmentFileSink.write(mInitSegments.get(cachedSegment.representation));
segmentFileSink.write(mediaSegment);
segmentFileSink.close();
}
cachedSegment.file = segmentFile;
cachedSegment.ptsOffsetUs = segmentPTSOffsetUs;
}
示例9: RotateVideo
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public static Uri RotateVideo( Uri uri, int rotation ) {
Uri rotatedVideoUri = null;
try {
IsoFile file = new IsoFile( uri.toString() );
List<Box> boxes = file.getMovieBox().getBoxes();
for ( Box box : boxes ) {
if ( box instanceof TrackBox ) {
TrackBox trackBox = (TrackBox) box;
HandlerBox handlerBox = trackBox.getMediaBox().getHandlerBox();
if ( handlerBox.getHandlerType().toLowerCase( Locale.US ).equals( "vide" ) ) {
TrackHeaderBox trackHeaderBox = trackBox.getTrackHeaderBox();
trackHeaderBox.setMatrix( GetMatrixFromRotation( rotation ) );
}
}
}
String pathWithoutExtension = uri.toString().replace( ".mp4", "" );
String rotatedFileName = String.format( Locale.US, "%s_rotated_to_%d.mp4", pathWithoutExtension, rotation );
FileOutputStream videoFileOutputStream = new FileOutputStream( rotatedFileName );
file.getBox( videoFileOutputStream.getChannel() );
file.close();
videoFileOutputStream.close();
rotatedVideoUri = Uri.parse( rotatedFileName );
} catch ( IOException e ) {
e.printStackTrace();
return null;
}
return rotatedVideoUri;
}
示例10: loadIsoFile
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
private Media loadIsoFile(IsoFile isoFile, FileBaseResourceInfo fileBaseResourceInfo) {
// Grab the file type box
FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class);
if (fileType == null) {
return null;
}
// Get the main MOOV box
MovieBox moov = getOrNull(isoFile, MovieBox.class);
if (moov == null) {
// Bail out
return null;
}
double duration = 0;
// Pull out some information from the header box
MovieHeaderBox mHeader = getOrNull(moov, MovieHeaderBox.class);
if (mHeader == null) {
return null;
}
// Get the duration. Seconds
duration = (double)mHeader.getDuration() / mHeader.getTimescale();
if (duration == 0){
duration = 1;
}
// Get some more information from the track header
List<TrackBox> tb = moov.getBoxes(TrackBox.class);
if (tb.isEmpty()) {
return null;
}
// Get the video with and height
int width = 0;
int height = 0;
for(int idx=0; idx<tb.size(); idx++){
TrackBox track = tb.get(idx);
TrackHeaderBox header = track.getTrackHeaderBox();
int w = (int)header.getWidth();
int h = (int)header.getHeight();
if (w==0 && h==0){
// skip the none-video track
continue;
}
// Get the video with and height
width = w;
height = h;
break;
}
if (width == 0 && height == 0) {
// no video track found.
return null;
}
Video.Format format = (
MIME_TYPE_VIDEO_MP4.equals(fileBaseResourceInfo.getMimeType())?
Video.Format.mp4:
Video.Format.mov);
return new DefaultVideo(
fileBaseResourceInfo, format,
width, height, duration);
}
示例11: LoadSpecificBox
import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
private void LoadSpecificBox( TrackBox box ) {
}