public void copy(SeekableByteChannel input, WritableByteChannel out) throws IOException { input.setPosition(offset); NIOUtils.copy(input, out, header.getSize()); } }
public void copy(SeekableByteChannel input, WritableByteChannel out) throws IOException { input.position(offset); NIOUtils.copy(input, out, header.getSize()); } }
public void copy(SeekableByteChannel input, WritableByteChannel out) throws IOException { input.position(offset); NIOUtils.copy(input, out, header.getSize()); } }
public static List<Atom> getRootAtoms(SeekableByteChannel input) throws IOException { input.position(0); List<Atom> result = new ArrayList<Atom>(); long off = 0; Header atom; while (off < input.size()) { input.position(off); atom = Header.read(NIOUtils.fetchFrom(input, 16)); if (atom == null) break; result.add(new Atom(atom, off)); off += atom.getSize(); } return result; }
private ByteBuffer fetchBox(SeekableByteChannel fi, Atom moov) throws IOException { fi.setPosition(moov.getOffset()); ByteBuffer oldMov = NIOUtils.fetchFromChannel(fi, (int) moov.getHeader().getSize()); return oldMov; }
private ByteBuffer fetchBox(SeekableByteChannel fi, Atom moov) throws IOException { fi.setPosition(moov.getOffset()); ByteBuffer oldMov = NIOUtils.fetchFromChannel(fi, (int) moov.getHeader().getSize()); return oldMov; }
public static List<Atom> getRootAtoms(SeekableByteChannel input) throws IOException { input.setPosition(0); List<Atom> result = new ArrayList<Atom>(); long off = 0; Header atom; while (off < input.size()) { input.setPosition(off); atom = Header.read(NIOUtils.fetchFromChannel(input, 16)); if (atom == null) break; result.add(new Atom(atom, off)); off += atom.getSize(); } return result; }
public static List<Atom> getRootAtoms(SeekableByteChannel input) throws IOException { input.position(0); List<Atom> result = new ArrayList<Atom>(); long off = 0; Header atom; while (off < input.size()) { input.position(off); atom = Header.read(NIOUtils.fetchFrom(input, 16)); if (atom == null) break; result.add(new Atom(atom, off)); off += atom.getSize(); } return result; }
public Box parseBox(SeekableByteChannel input) throws IOException { input.position(offset + header.headerSize()); return NodeBox.parseBox(NIOUtils.fetchFrom(input, (int) header.getSize()), header, BoxFactory.getDefault()); }
public Box parseBox(SeekableByteChannel input) throws IOException { input.position(offset + header.headerSize()); return NodeBox.parseBox(NIOUtils.fetchFrom(input, (int) header.getSize()), header, BoxFactory.getDefault()); }
private boolean isMoov(SeekableByteChannel is, Atom atom) throws IOException { is.setPosition(atom.getOffset() + atom.getHeader().headerSize()); try { Box mov = BoxUtil.parseBox(NIOUtils.fetchFromChannel(is, (int) atom.getHeader().getSize()), Header.createHeader("moov", atom .getHeader().getSize()), BoxFactory.getDefault()); return (mov instanceof MovieBox) && BoxUtil.containsBox((NodeBox) mov, "mvhd"); } catch (Throwable t) { return false; } } }
public static WebOptimizedMP4Muxer withOldHeader(SeekableByteChannel output, Brand brand, MovieBox oldHeader) throws IOException { int size = (int) oldHeader.getHeader().getSize(); TrakBox vt = oldHeader.getVideoTrack(); SampleToChunkBox stsc = Box.findFirst(vt, SampleToChunkBox.class, "mdia", "minf", "stbl", "stsc"); size -= stsc.getSampleToChunk().length * 12; size += 12; ChunkOffsetsBox stco = Box.findFirst(vt, ChunkOffsetsBox.class, "mdia", "minf", "stbl", "stco"); if (stco != null) { size -= stco.getChunkOffsets().length << 2; size += vt.getFrameCount() << 3; } else { ChunkOffsets64Box co64 = Box.findFirst(vt, ChunkOffsets64Box.class, "mdia", "minf", "stbl", "co64"); size -= co64.getChunkOffsets().length << 3; size += vt.getFrameCount() << 3; } return new WebOptimizedMP4Muxer(output, brand, size + (size >> 1)); }
public static WebOptimizedMP4Muxer withOldHeader(SeekableByteChannel output, Brand brand, MovieBox oldHeader) throws IOException { int size = (int) oldHeader.getHeader().getSize(); TrakBox vt = oldHeader.getVideoTrack(); SampleToChunkBox stsc = vt.getStsc(); size -= stsc.getSampleToChunk().length * 12; size += 12; ChunkOffsetsBox stco = vt.getStco(); if (stco != null) { size -= stco.getChunkOffsets().length << 2; size += vt.getFrameCount() << 3; } else { ChunkOffsets64Box co64 = vt.getCo64(); size -= co64.getChunkOffsets().length << 3; size += vt.getFrameCount() << 3; } return new WebOptimizedMP4Muxer(output, brand, size + (size >> 1)); }
public static WebOptimizedMP4Muxer withOldHeader(SeekableByteChannel output, Brand brand, MovieBox oldHeader) throws IOException { int size = (int) oldHeader.getHeader().getSize(); TrakBox vt = oldHeader.getVideoTrack(); SampleToChunkBox stsc = Box.findFirst(vt, SampleToChunkBox.class, "mdia", "minf", "stbl", "stsc"); size -= stsc.getSampleToChunk().length * 12; size += 12; ChunkOffsetsBox stco = Box.findFirst(vt, ChunkOffsetsBox.class, "mdia", "minf", "stbl", "stco"); if (stco != null) { size -= stco.getChunkOffsets().length << 2; size += vt.getFrameCount() << 3; } else { ChunkOffsets64Box co64 = Box.findFirst(vt, ChunkOffsets64Box.class, "mdia", "minf", "stbl", "co64"); size -= co64.getChunkOffsets().length << 3; size += vt.getFrameCount() << 3; } return new WebOptimizedMP4Muxer(output, brand, size + (size >> 1)); }
public void relocate(File src, MP4Edit edit) throws IOException { SeekableByteChannel f = null; try { f = NIOUtils.rwChannel(src); Atom moovAtom = getMoov(f); ByteBuffer moovBuffer = fetchBox(f, moovAtom); MovieBox moovBox = (MovieBox) parseBox(moovBuffer); edit.apply(moovBox); if (moovAtom.getOffset() + moovAtom.getHeader().getSize() < f.size()) { Logger.info("Relocating movie header to the end of the file."); f.setPosition(moovAtom.getOffset() + 4); f.write(ByteBuffer.wrap(Header.FOURCC_FREE)); f.setPosition(f.size()); } else { f.setPosition(moovAtom.getOffset()); } MP4Util.writeMovie(f, moovBox); } finally { NIOUtils.closeQuietly(f); } }