public WebVTTConfigurationBox getConfig() { return Path.getPath(this, "vttC"); }
for (Box tkhd : tkhds) { if (((TrackHeaderBox) tkhd).getTrackId() == this.getParent().getBoxes(TrackFragmentHeaderBox.class).get(0).getTrackId()) { AbstractTrackEncryptionBox tenc = (AbstractTrackEncryptionBox) Path.getPath(tkhd, "../mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schi[0]/tenc[0]"); if (tenc == null) { tenc = (AbstractTrackEncryptionBox) Path.getPath(tkhd, "../mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schi[0]/uuid[0]");
for (Box tkhd : tkhds) { if (((TrackHeaderBox) tkhd).getTrackId() == this.getParent().getBoxes(TrackFragmentHeaderBox.class).get(0).getTrackId()) { AbstractTrackEncryptionBox tenc = (AbstractTrackEncryptionBox) Path.getPath(tkhd, "../mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schi[0]/tenc[0]"); if (tenc == null) { tenc = (AbstractTrackEncryptionBox) Path.getPath(tkhd, "../mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schi[0]/uuid[0]");
public WebVTTSourceLabelBox getSourceLabel() { return Path.getPath(this, "vlab"); } }
syncSamples = stbl.getSyncSampleBox().getSampleNumber(); subSampleInformationBox = Path.getPath(stbl, "subs"); sampleGroups, sampleNumber - 1); SubSampleInformationBox subs = Path.getPath(traf, "subs"); if (subs != null) { long difFromLastFragment = sampleNumber - lastSubsSample - 1; trackMetaData.setMatrix(tkhd.getMatrix()); trackMetaData.setVolume(tkhd.getVolume()); EditListBox elst = Path.getPath(trackBox, "edts/elst"); MovieHeaderBox mvhd = Path.getPath(trackBox, "../mvhd"); if (elst != null) { for (EditListBox.Entry e : elst.getEntries()) {
public static void main2(String[] args) throws IOException { ESDescriptorBox esds = Path.getPath(new IsoFile("C:\\content\\bbb.mp4"), "/moov[0]/trak[0]/mdia[0]/minf[0]/stbl[0]/stsd[0]/mp4v[0]/esds[0]"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); esds.getBox(Channels.newChannel(baos)); System.err.println(Hex.encodeHex(baos.toByteArray())); System.err.println(esds.getEsDescriptor()); baos = new ByteArrayOutputStream(); esds.getBox(Channels.newChannel(baos)); System.err.println(Hex.encodeHex(baos.toByteArray())); } }
public static void replace(Map<String, Box> replacements, File file) throws IOException { IsoFile isoFile = new IsoFile( new FileDataSourceImpl(new RandomAccessFile(file, "r").getChannel())); Map<String, Box> replacementSanitised = new HashMap<String, Box>(); Map<String, Long> positions = new HashMap<String, Long>(); for (Map.Entry<String, Box> e : replacements.entrySet()) { Box b = Path.getPath(isoFile, e.getKey()); replacementSanitised.put(Path.createPath( b ), e.getValue()); positions.put(Path.createPath( b ), b.getOffset()); assert b.getSize() == e.getValue().getSize(); } isoFile.close(); FileChannel fileChannel = new RandomAccessFile(file, "rw").getChannel(); for (String path : replacementSanitised.keySet()) { Box b = replacementSanitised.get(path); long pos = positions.get(path); fileChannel.position(pos); b.getBox(fileChannel); } fileChannel.close(); }
public Avc1ToAvc3TrackImpl(Track parent) throws IOException { super(parent); if (!"avc1".equals(parent.getSampleDescriptionBox().getSampleEntry().getType())) { throw new RuntimeException("Only avc1 tracks can be converted to avc3 tracks"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); parent.getSampleDescriptionBox().getBox(Channels.newChannel(baos)); IsoFile isoFile = new IsoFile(new MemoryDataSourceImpl(baos.toByteArray())); this.stsd = Path.getPath(isoFile, "stsd"); ((VisualSampleEntry) stsd.getSampleEntry()).setType("avc3"); avcC = Path.getPath(stsd, "avc./avcC"); samples = new ReplaceSyncSamplesList(parent.getSamples()); }
static String getFormat(Track track) { SampleDescriptionBox stsd = track.getSampleDescriptionBox(); OriginalFormatBox frma = Path.getPath(stsd, "enc./sinf/frma"); if (frma!=null) { return frma.getDataFormat(); } else { return stsd.getSampleEntry().getType(); } }
public CencDecryptingTrackImpl(CencEncryptedTrack original, Map<UUID, SecretKey> keys) { super("dec(" + original.getName() + ")"); this.original = original; SchemeTypeBox schm = Path.getPath(original.getSampleDescriptionBox(), "enc./sinf/schm"); if (!("cenc".equals(schm.getSchemeType()) || "cbc1".equals(schm.getSchemeType()))) { throw new RuntimeException("You can only use the CencDecryptingTrackImpl with CENC (cenc or cbc1) encrypted tracks");
public SampleDescriptionBox getSampleDescriptionBox() { OriginalFormatBox frma = Path.getPath(original.getSampleDescriptionBox(), "enc./sinf/frma"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); SampleDescriptionBox stsd; try { original.getSampleDescriptionBox().getBox(Channels.newChannel(baos)); stsd = (SampleDescriptionBox) new IsoFile(new MemoryDataSourceImpl(baos.toByteArray())).getBoxes().get(0); } catch (IOException e) { throw new RuntimeException("Dumping stsd to memory failed"); } if (stsd.getSampleEntry() instanceof AudioSampleEntry) { ((AudioSampleEntry) stsd.getSampleEntry()).setType(frma.getDataFormat()); } else if (stsd.getSampleEntry() instanceof VisualSampleEntry) { ((VisualSampleEntry) stsd.getSampleEntry()).setType(frma.getDataFormat()); } else { throw new RuntimeException("I don't know " + stsd.getSampleEntry().getType()); } List<Box> nuBoxes = new LinkedList<Box>(); for (Box box : stsd.getSampleEntry().getBoxes()) { if (!box.getType().equals("sinf")) { nuBoxes.add(box); } } stsd.getSampleEntry().setBoxes(nuBoxes); return stsd; }
protected void createSaiz(long startSample, long endSample, CencEncryptedTrack track, int sequenceNumber, TrackFragmentBox parent) { SampleDescriptionBox sampleDescriptionBox = track.getSampleDescriptionBox(); SchemeTypeBox schm = Path.getPath(sampleDescriptionBox, "enc.[0]/sinf[0]/schm[0]"); TrackEncryptionBox tenc = Path.getPath(sampleDescriptionBox, "enc.[0]/sinf[0]/schi[0]/tenc[0]"); SampleAuxiliaryInformationSizesBox saiz = new SampleAuxiliaryInformationSizesBox(); saiz.setAuxInfoType("cenc"); saiz.setFlags(1); if (track.hasSubSampleEncryption()) { short[] sizes = new short[l2i(endSample - startSample)]; List<CencSampleAuxiliaryDataFormat> auxs = track.getSampleEncryptionEntries().subList(l2i(startSample - 1), l2i(endSample - 1)); for (int i = 0; i < sizes.length; i++) { sizes[i] = (short) auxs.get(i).getSize(); } saiz.setSampleInfoSizes(sizes); } else { saiz.setDefaultSampleInfoSize(tenc.getDefaultIvSize()); saiz.setSampleCount(l2i(endSample - startSample)); } parent.addBox(saiz); }
/** * Creates <code>Movie</code> object from a <code>ReadableByteChannel</code>. * * @param channel input channel * @return a representation of the movie * @throws IOException in case of I/O error during IsoFile creation */ public static Movie build(DataSource channel) throws IOException { IsoFile isoFile = new IsoFile(channel); Movie m = new Movie(); List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class); for (TrackBox trackBox : trackBoxes) { SchemeTypeBox schm = Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schm[0]"); if (schm != null && (schm.getSchemeType().equals("cenc") || schm.getSchemeType().equals("cbc1"))) { m.addTrack(new CencMp4TrackImplImpl(channel.toString() + "[" + trackBox.getTrackHeaderBox().getTrackId() + "]", trackBox)); } else { m.addTrack(new Mp4TrackImpl(channel.toString() + "[" + trackBox.getTrackHeaderBox().getTrackId() + "]" , trackBox)); } } m.setMatrix(isoFile.getMovieBox().getMovieHeaderBox().getMatrix()); return m; } }
protected void createSaio(long startSample, long endSample, CencEncryptedTrack track, int sequenceNumber, TrackFragmentBox parent) { SchemeTypeBox schm = Path.getPath(track.getSampleDescriptionBox(), "enc.[0]/sinf[0]/schm[0]"); SampleAuxiliaryInformationOffsetsBox saio = new SampleAuxiliaryInformationOffsetsBox(); parent.addBox(saio); assert parent.getBoxes(TrackRunBox.class).size() == 1 : "Don't know how to deal with multiple Track Run Boxes when encrypting"; saio.setAuxInfoType("cenc"); saio.setFlags(1); long offset = 0; offset += 8; // traf header till 1st child box for (Box box : parent.getBoxes()) { if (box instanceof SampleEncryptionBox) { offset += ((SampleEncryptionBox) box).getOffsetToFirstIV(); break; } else { offset += box.getSize(); } } MovieFragmentBox moof = (MovieFragmentBox) parent.getParent(); offset += 16; // traf header till 1st child box for (Box box : moof.getBoxes()) { if (box == parent) { break; } else { offset += box.getSize(); } } saio.setOffsets(new long[]{offset}); }
super(name, trackBox, fragments); SchemeTypeBox schm = Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schm[0]"); assert schm != null && (schm.getSchemeType().equals("cenc") || schm.getSchemeType().equals("cbc1")) : "Track must be CENC (cenc or cbc1) encrypted"; for (TrackFragmentBox traf : trafs) { if (traf.getTrackFragmentHeaderBox().getTrackId() == trackId) { TrackEncryptionBox tenc = Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schi[0]/tenc[0]"); defaultKeyId = tenc.getDefault_KID(); Container base; TrackEncryptionBox tenc = Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]/stsd[0]/enc.[0]/sinf[0]/schi[0]/tenc[0]"); defaultKeyId = tenc.getDefault_KID(); ChunkOffsetBox chunkOffsetBox = Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]/stco[0]"); chunkOffsetBox = Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]/co64[0]"); FindSaioSaizPair saizSaioPair = new FindSaioSaizPair((Container) Path.getPath(trackBox, "mdia[0]/minf[0]/stbl[0]")).invoke(); SampleAuxiliaryInformationOffsetsBox saio = saizSaioPair.saio; SampleAuxiliaryInformationSizesBox saiz = saizSaioPair.saiz;