private static <T extends Box> T getOrNull(Container box, Class<T> clazz) { if (box == null) return null; List<T> boxes = box.getBoxes(clazz); if (boxes.size() == 0) { return null; } return boxes.get(0); } }
String h264Path = "path to my h264 file, generated by Android MediaCodec"; DataSource videoFile = new FileDataSourceImpl(h264Path); H264TrackImpl h264Track = new H264TrackImpl(videoFile, "eng", 5, 1); // 5fps. you can play with timescale and timetick to get non integer fps, 23.967 is 24000/1001 Movie movie = new Movie(); movie.addTrack(h264Track); Container out = new DefaultMp4Builder().build(movie); FileOutputStream fos = new FileOutputStream(new File("path to my generated file.mp4")); out.writeContainer(fos.getChannel()); fos.close();
protected DataInformationBox createDinf() { DataInformationBox dinf = new DataInformationBox(); DataReferenceBox dref = new DataReferenceBox(); dinf.addBox(dref); DataEntryUrlBox url = new DataEntryUrlBox(); url.setFlags(1); dref.addBox(url); return dinf; }
if (e.getValue().contains(fileType.getMajorBrand())) { type = e.getKey(); break; metadata.set(XMPDM.AUDIO_COMPRESSOR, fileType.getMajorBrand().trim()); metadata.set(TikaCoreProperties.CREATED, mHeader.getCreationTime()); metadata.set(TikaCoreProperties.MODIFIED, mHeader.getModificationTime()); double durationSeconds = ((double) mHeader.getDuration()) / mHeader.getTimescale(); metadata.set(XMPDM.DURATION, DURATION_FORMAT.format(durationSeconds)); metadata.set(XMPDM.AUDIO_SAMPLE_RATE, (int) mHeader.getTimescale()); List<TrackBox> tb = moov.getBoxes(TrackBox.class); if (tb.size() > 0) { TrackBox track = tb.get(0); TrackHeaderBox header = track.getTrackHeaderBox(); metadata.set(TikaCoreProperties.CREATED, header.getCreationTime()); metadata.set(TikaCoreProperties.MODIFIED, header.getModificationTime()); metadata.set(Metadata.IMAGE_WIDTH, (int) header.getWidth()); metadata.set(Metadata.IMAGE_LENGTH, (int) header.getHeight()); SampleTableBox samples = track.getSampleTableBox(); SampleDescriptionBox sampleDesc = samples.getSampleDescriptionBox(); if (sampleDesc != null) {
protected Box createStbl() { SampleTableBox stbl = new SampleTableBox(); stbl.addBox(source.getSampleDescriptionBox()); stbl.addBox(new TimeToSampleBox()); stbl.addBox(new SampleToChunkBox()); stbl.addBox(new SampleSizeBox()); stbl.addBox(new StaticChunkOffsetBox()); return stbl; }
protected Box createStbl(Movie movie, Track track) { SampleTableBox stbl = new SampleTableBox(); stbl.addBox(track.getSampleDescriptionBox()); stbl.addBox(new TimeToSampleBox()); //stbl.addBox(new SampleToChunkBox()); stbl.addBox(new StaticChunkOffsetBox()); return stbl; }
@Override public int size() { return l2i(trackBox.getSampleTableBox().getSampleSizeBox().getSampleCount()); }
public int getSize() { int size = 2; if (getVersion() == 1) { size += 2; } size += 2; size += baseOffsetSize; size += 2; for (Extent extent : extents) { size += extent.getSize(); } return size; }
@Override protected long getContentSize() { long entries = 8 + ((4 + 2) * entryCount); int subsampleEntries = 0; for (SampleEntry sampleEntry : this.entries) { subsampleEntries += sampleEntry.getSubsampleCount() * (((getVersion() == 1) ? 4 : 2) + 1 + 1 + 4); } return entries + subsampleEntries; }
protected long getContentSize() { long contentSize = 4; if (getVersion() == 1) { contentSize += 8 + 8 + 4 + 8; } else { contentSize += 4 + 4 + 4 + 4; } contentSize += 2; contentSize += 2; return contentSize; }
protected DataInformationBox createDinf(Movie movie, Track track) { DataInformationBox dinf = new DataInformationBox(); DataReferenceBox dref = new DataReferenceBox(); dinf.addBox(dref); DataEntryUrlBox url = new DataEntryUrlBox(); url.setFlags(1); dref.addBox(url); return dinf; }
protected Box createStbl(StreamingTrack streamingTrack) { SampleTableBox stbl = new SampleTableBox(); stbl.addBox(streamingTrack.getSampleDescriptionBox()); stbl.addBox(new TimeToSampleBox()); stbl.addBox(new SampleToChunkBox()); stbl.addBox(new SampleSizeBox()); stbl.addBox(new StaticChunkOffsetBox()); return stbl; }
protected Box createStbl(Movie movie, Track track) { SampleTableBox stbl = new SampleTableBox(); stbl.addBox(track.getSampleDescriptionBox()); stbl.addBox(new TimeToSampleBox()); //stbl.addBox(new SampleToChunkBox()); stbl.addBox(new StaticChunkOffsetBox()); return stbl; }
public int getSize() { int size = 2; if (getVersion() == 1) { size += 2; } size += 2; size += baseOffsetSize; size += 2; for (Extent extent : extents) { size += extent.getSize(); } return size; }
@Override protected long getContentSize() { long entries = 8 + ((4 + 2) * entryCount); int subsampleEntries = 0; for (SampleEntry sampleEntry : this.entries) { subsampleEntries += sampleEntry.getSubsampleCount() * (((getVersion() == 1) ? 4 : 2) + 1 + 1 + 4); } return entries + subsampleEntries; }
protected DataInformationBox createDinf() { DataInformationBox dinf = new DataInformationBox(); DataReferenceBox dref = new DataReferenceBox(); dinf.addBox(dref); DataEntryUrlBox url = new DataEntryUrlBox(); url.setFlags(1); dref.addBox(url); return dinf; }
protected Box createStbl(Movie movie, Track track) { SampleTableBox stbl = new SampleTableBox(); createStsd(track, stbl); stbl.addBox(new TimeToSampleBox()); stbl.addBox(new SampleToChunkBox()); stbl.addBox(new SampleSizeBox()); stbl.addBox(new StaticChunkOffsetBox()); return stbl; }
public int getSize() { int size = 2; if (getVersion() == 1) { size += 2; } size += 2; size += baseOffsetSize; size += 2; for (Extent extent : extents) { size += extent.getSize(); } return size; }
protected DataInformationBox createDinf(Movie movie, Track track) { DataInformationBox dinf = new DataInformationBox(); DataReferenceBox dref = new DataReferenceBox(); dinf.addBox(dref); DataEntryUrlBox url = new DataEntryUrlBox(); url.setFlags(1); dref.addBox(url); return dinf; }
protected DataInformationBox createDinf(Movie movie, Track track) { DataInformationBox dinf = new DataInformationBox(); DataReferenceBox dref = new DataReferenceBox(); dinf.addBox(dref); DataEntryUrlBox url = new DataEntryUrlBox(); url.setFlags(1); dref.addBox(url); return dinf; }