public int parseTimecode(String tc) { String[] split = tc.split(":"); TimecodeSampleEntry tmcd = NodeBox.findFirstPath(box, TimecodeSampleEntry.class, Box.path("mdia.minf.stbl.stsd.tmcd")); byte nf = tmcd.getNumFrames(); return Integer.parseInt(split[3]) + Integer.parseInt(split[2]) * nf + Integer.parseInt(split[1]) * 60 * nf + Integer.parseInt(split[0]) * 3600 * nf; }
public static void _setLabels(TrakBox trakBox, Label[] labels) { ChannelBox channel = NodeBox.findFirstPath(trakBox, ChannelBox.class, new String[] { "mdia", "minf", "stbl", "stsd", null, "chan" }); if (channel == null) { channel = ChannelBox.createChannelBox(); NodeBox.findFirstPath(trakBox, SampleEntry.class, new String[] { "mdia", "minf", "stbl", "stsd", null }).add(channel); } setLabels(labels, channel); }
private static void appendDrefs(TrakBox trakBox1, TrakBox trakBox2) { DataRefBox dref1 = NodeBox.findFirstPath(trakBox1, DataRefBox.class, Box.path("mdia.minf.dinf.dref")); DataRefBox dref2 = NodeBox.findFirstPath(trakBox2, DataRefBox.class, Box.path("mdia.minf.dinf.dref")); dref1.getBoxes().addAll(dref2.getBoxes()); }
public List<Edit> getEdits() { EditListBox editListBox = NodeBox.findFirstPath(box, EditListBox.class, Box.path("edts.elst")); if (editListBox != null) return editListBox.getEdits(); return null; }
/** * Sets the 'media timescale' of this track. This is the time timescale used * to represent sample durations. * * @param timescale * A new 'media timescale' of this track. */ public void setTimescale(int timescale) { NodeBox.findFirstPath(this, MediaHeaderBox.class, Box.path("mdia.mdhd")).setTimescale(timescale); }
public List<Edit> getEdits() { EditListBox elst = NodeBox.findFirstPath(this, EditListBox.class, Box.path("edts.elst")); if (elst == null) return null; return elst.getEdits(); }
/** * Gets 'media timescale' of this track. This is the timescale used to * represent the durations of samples inside mdia/minf/stbl/stts box. * * @return 'media timescale' of the track. */ public int getTimescale() { return NodeBox.findFirstPath(this, MediaHeaderBox.class, Box.path("mdia.mdhd")).getTimescale(); }
private boolean matchSampleSizes(TrakBox trakBox1, TrakBox trakBox2) { SampleSizesBox stsz1 = NodeBox.findFirstPath(trakBox1, SampleSizesBox.class, Box.path("mdia.minf.stbl.stsz")); SampleSizesBox stsz2 = NodeBox.findFirstPath(trakBox1, SampleSizesBox.class, Box.path("mdia.minf.stbl.stsz")); return stsz1.getDefaultSize() == stsz2.getDefaultSize(); }
public String getHandlerType() { HandlerBox handlerBox = NodeBox.findFirstPath(this, HandlerBox.class, Box.path("mdia.hdlr")); if (handlerBox == null) return null; String type = handlerBox.getComponentSubType(); return type; }
private static void updateDuration(TrakBox dest, TrakBox src) { MediaHeaderBox mdhd1 = NodeBox.findFirstPath(dest, MediaHeaderBox.class, Box.path("mdia.mdhd")); MediaHeaderBox mdhd2 = NodeBox.findFirstPath(src, MediaHeaderBox.class, Box.path("mdia.mdhd")); mdhd1.setDuration(mdhd1.getDuration() + mdhd2.getDuration()); }
public static MetadataEditor createFrom(File f) throws IOException { Format format = JCodecUtil.detectFormat(f); if (format != Format.MOV) { throw new IllegalArgumentException("Unsupported format: " + format); } Movie movie = MP4Util.parseFullMovie(f); MetaBox keyedMeta = NodeBox.findFirst(movie.getMoov(), MetaBox.class, MetaBox.fourcc()); MetaBox itunesMeta = NodeBox.findFirstPath(movie.getMoov(), MetaBox.class, new String[] { "udta", MetaBox.fourcc() }); return new MetadataEditor(f, keyedMeta == null ? new HashMap<String, MetaValue>() : keyedMeta.getKeyedMeta(), itunesMeta == null ? new HashMap<Integer, MetaValue>() : itunesMeta.getItunesMeta()); }
public void apply(MovieBox mov) { TrakBox vt = mov.getVideoTrack(); MediaHeaderBox mdhd = NodeBox.findFirstPath(vt, MediaHeaderBox.class, Box.path("mdia.mdhd")); int oldTs = mdhd.getTimescale(); if (oldTs > ts) { throw new RuntimeException("Old timescale (" + oldTs + ") is greater then new timescale (" + ts + "), not touching."); } vt.fixMediaTimescale(ts); mov.fixTimescale(ts); }
public static ByteBuffer getSampleData(int sample, File file) throws IOException { MovieBox moov = MP4Util.parseMovie(file); MediaInfoBox minf = moov.getAudioTracks().get(0).getMdia().getMinf(); ChunkOffsetsBox stco = NodeBox.findFirstPath(minf, ChunkOffsetsBox.class, Box.path("stbl.stco")); SampleToChunkBox stsc = NodeBox.findFirstPath(minf, SampleToChunkBox.class, Box.path("stbl.stsc")); SampleSizesBox stsz = NodeBox.findFirstPath(minf, SampleSizesBox.class, Box.path("stbl.stsz")); long sampleOffset = getSampleOffset(sample, stsc, stco, stsz); MappedByteBuffer map = NIOUtils.mapFile(file); map.position((int) sampleOffset); map.limit(map.position() + stsz.getSizes()[sample]); return map; }
private AbstractMP4DemuxerTrack fromTrakBox(TrakBox trak) { SampleSizesBox stsz = NodeBox.findFirstPath(trak, SampleSizesBox.class, Box.path("mdia.minf.stbl.stsz")); if (stsz.getDefaultSize() == 0) return newTrack(trak); return new PCMMP4DemuxerTrack(movie, trak, input); }
public static ByteBuffer getCodecPrivate(SampleEntry mp4a) { LeafBox b = NodeBox.findFirst(mp4a, LeafBox.class, "esds"); if (b == null) { b = NodeBox.findFirstPath(mp4a, LeafBox.class, new String[] { null, "esds" }); } if (b == null) return null; EsdsBox esds = EsdsBox.newEsdsBox(); esds.parse(b.getData()); return esds.getStreamInfo(); }
public void apply() { NodeBox stbl = NodeBox.findFirstPath(trak, NodeBox.class, Box.path("mdia.minf.stbl")); stbl.removeChildren("stco", "co64"); stbl.add(ChunkOffsets64Box.createChunkOffsets64Box(offsets)); cleanDrefs(trak); }
private boolean matchClip(TrakBox trakBox1, TrakBox trakBox2) { ClipRegionBox crgn1 = NodeBox.findFirstPath(trakBox1, ClipRegionBox.class, Box.path("clip.crgn")); ClipRegionBox crgn2 = NodeBox.findFirstPath(trakBox2, ClipRegionBox.class, Box.path("clip.crgn")); if (crgn1 != null && crgn2 != null) { return crgn1.getRgnSize() == crgn2.getRgnSize() && crgn1.getX() == crgn2.getX() && crgn1.getY() == crgn2.getY() && crgn1.getWidth() == crgn2.getWidth() && crgn1.getHeight() == crgn2.getHeight(); } if (crgn1 == null && crgn2 == null) return true; return false; } }
private static void appendTimeToSamples(TrakBox trakBox1, TrakBox trakBox2) { TimeToSampleBox stts1 = trakBox1.getStts(); TimeToSampleBox stts2 = trakBox2.getStts(); TimeToSampleBox sttsNew = TimeToSampleBox.createTimeToSampleBox((TimeToSampleEntry[]) addAllObj(stts1.getEntries(), stts2.getEntries())); NodeBox.findFirstPath(trakBox1, NodeBox.class, Box.path("mdia.minf.stbl")).replace("stts", sttsNew); }
private static void appendSampleToChunk(TrakBox trakBox1, TrakBox trakBox2, int off) { SampleToChunkBox stsc1 = trakBox1.getStsc(); SampleToChunkBox stsc2 = trakBox2.getStsc(); SampleToChunkEntry[] orig = stsc2.getSampleToChunk(); SampleToChunkEntry[] shifted = new SampleToChunkEntry[orig.length]; for (int i = 0; i < orig.length; i++) { shifted[i] = new SampleToChunkEntry(orig[i].getFirst() + stsc1.getSampleToChunk().length, orig[i].getCount(), orig[i].getEntry() + off); } NodeBox.findFirstPath(trakBox1, NodeBox.class, Box.path("mdia.minf.stbl")).replace("stsc", SampleToChunkBox.createSampleToChunkBox((SampleToChunkEntry[]) ArrayUtil.addAllObj(stsc1.getSampleToChunk(), shifted))); }
private static void appendChunkOffsets(TrakBox trakBox1, TrakBox trakBox2) { ChunkOffsetsBox stco1 = trakBox1.getStco(); ChunkOffsets64Box co641 = trakBox1.getCo64(); ChunkOffsetsBox stco2 = trakBox2.getStco(); ChunkOffsets64Box co642 = trakBox2.getCo64(); long[] off1 = stco1 == null ? co641.getChunkOffsets() : stco1.getChunkOffsets(); long[] off2 = stco2 == null ? co642.getChunkOffsets() : stco2.getChunkOffsets(); NodeBox stbl1 = NodeBox.findFirstPath(trakBox1, NodeBox.class, Box.path("mdia.minf.stbl")); stbl1.removeChildren("stco", "co64"); stbl1.add(co641 == null && co642 == null ? ChunkOffsetsBox.createChunkOffsetsBox(ArrayUtil.addAllLong(off1, off2)) : ChunkOffsets64Box.createChunkOffsets64Box(ArrayUtil.addAllLong(off1, off2))); }