private static String createPath(Box box, String path) { Container parent = box.getParent(); int index = 0; List<Box> siblings = parent.getBoxes(); for (Box sibling : siblings) { if (sibling.getType().equals(box.getType())) { if (sibling == box) { break; } index++; } } path = String.format("/%s[%d]", box.getType(), index) + path; if (parent instanceof Box) { return createPath((Box) parent, path); } else { return path; } }
private void initIsoFile(IsoFile isoFile) { this.isoFile = isoFile; // find all mdats first to be able to use them later with explicitly looking them up long currentOffset = 0; LinkedList<MediaDataBox> mdats = new LinkedList<MediaDataBox>(); for (Box b : this.isoFile.getBoxes()) { long currentSize = b.getSize(); if ("mdat".equals(b.getType())) { if (b instanceof MediaDataBox) { long contentOffset = currentOffset + ((MediaDataBox) b).getHeader().limit(); mdatStartCache.put((MediaDataBox) b, contentOffset); mdatEndCache.put((MediaDataBox) b, contentOffset + currentSize); mdats.add((MediaDataBox) b); } else { throw new RuntimeException("Sample need to be in mdats and mdats need to be instanceof MediaDataBox"); } } currentOffset += currentSize; } this.mdats = mdats.toArray(new MediaDataBox[mdats.size()]); }
private void initIsoFile(IsoFile isoFile) { this.isoFile = isoFile; // find all mdats first to be able to use them later with explicitly looking them up long currentOffset = 0; LinkedList<MediaDataBox> mdats = new LinkedList<MediaDataBox>(); for (Box b : this.isoFile.getBoxes()) { long currentSize = b.getSize(); if ("mdat".equals(b.getType())) { if (b instanceof MediaDataBox) { long contentOffset = currentOffset + ((MediaDataBox) b).getHeader().limit(); mdatStartCache.put((MediaDataBox) b, contentOffset); mdatEndCache.put((MediaDataBox) b, contentOffset + currentSize); mdats.add((MediaDataBox) b); } else { throw new RuntimeException("Sample need to be in mdats and mdats need to be instanceof MediaDataBox"); } } currentOffset += currentSize; } this.mdats = mdats.toArray(new MediaDataBox[mdats.size()]); }
private static String createPath(Box box, String path) { if (box instanceof IsoFile) { return path; } else { List<?> boxesOfBoxType = box.getParent().getBoxes(box.getClass()); int index = boxesOfBoxType.indexOf(box); path = String.format("/%s[%d]", box.getType(), index) + path; return createPath(box.getParent(), path); } }
private static String createPath(Box box, String path) { if (box instanceof IsoFile) { return path; } else { List<?> boxesOfBoxType = box.getParent().getBoxes(box.getClass()); int index = boxesOfBoxType.indexOf(box); path = String.format("/%s[%d]", box.getType(), index) + path; return createPath(box.getParent(), path); } }
isoFile = isoFile.getParent(); assert isoFile instanceof IsoFile : isoFile.getType() + " has no parent"; return getPaths(isoFile, path.substring(1)); } else if (path.isEmpty()) { int currentIndex = 0; for (Box box1 : ((ContainerBox) box).getBoxes()) { if (box1.getType().matches(type)) { if (index == -1 || index == currentIndex) { children.addAll(getPaths(box1, later));
isoFile = isoFile.getParent(); assert isoFile instanceof IsoFile : isoFile.getType() + " has no parent"; return getPaths(isoFile, path.substring(1)); } else if (path.isEmpty()) { int currentIndex = 0; for (Box box1 : ((ContainerBox) box).getBoxes()) { if (box1.getType().matches(type)) { if (index == -1 || index == currentIndex) { children.addAll(getPaths(box1, later));
while (iterator.hasNext()) { Box box1 = iterator.next(); if (box1.getType().matches(type)) { if (index == -1 || index == currentIndex) { children.addAll(Path.<T>getPaths(box1, later, singleResult));
Box box = createBox(type, usertype, (parent instanceof Box) ? ((Box) parent).getType() : ""); box.setParent(parent);
FileChannel fc = fos.getChannel(); Box mdat = boxIt.next(); assert mdat.getType().equals("mdat");
FileChannel fc = fos.getChannel(); Box mdat = boxIt.next(); assert mdat.getType().equals("mdat");
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; }
private void writeMetaData(Container out, String artist, String title) { MovieBox mBox = null; for (Box box : out.getBoxes()) { if (box.getType().contains("moov")) { mBox = (MovieBox) box; break;