public void writeTo(WritableByteChannel channel) throws java.io.IOException { for (Box box : boxes) { box.getBox(channel); } }
public void _writeChildBoxes(ByteBuffer bb) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); WritableByteChannel wbc = Channels.newChannel(baos); try { for (Box box : boxes) { box.getBox(wbc); } wbc.close(); } catch (IOException e) { throw new RuntimeException("Cannot happen. Everything should be in memory and therefore no exceptions."); } bb.put(baos.toByteArray()); }
public void _writeChildBoxes(ByteBuffer bb) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); WritableByteChannel wbc = Channels.newChannel(baos); try { for (Box box : boxes) { box.getBox(wbc); } wbc.close(); } catch (IOException e) { throw new RuntimeException("Cannot happen. Everything should be in memory and therefore no exceptions."); } bb.put(baos.toByteArray()); }
protected final void writeChildBoxes(ByteBuffer bb) { WritableByteChannel wbc = new ByteBufferByteChannel(bb); for (Box box : boxes) { try { box.getBox(wbc); } catch (IOException e) { // cannot happen since my WritableByteChannel won't throw any excpetion throw new RuntimeException("Cannot happen.", e); } } }
public void getBox(WritableByteChannel os) throws IOException { for (Box replacer : replacers) { replacer.getBox(os); } ByteBuffer header = ByteBuffer.allocate(8); IsoTypeWriter.writeUInt32(header, 8 + data.limit()); header.put(TYPE.getBytes()); header.rewind(); os.write(header); data.rewind(); os.write(data); }
protected final void writeChildBoxes(ByteBuffer bb) { WritableByteChannel wbc = new ByteBufferByteChannel(bb); for (Box box : boxes) { try { box.getBox(wbc); } catch (IOException e) { // cannot happen since my WritableByteChannel won't throw any excpetion throw new RuntimeException("Cannot happen.", e); } } }
protected final void writeChildBoxes(ByteBuffer bb) { WritableByteChannel wbc = new ByteBufferByteChannel(bb); for (Box box : boxes) { try { box.getBox(wbc); } catch (IOException e) { // My WritableByteChannel won't throw any excpetion throw new RuntimeException("Cannot happen to me", e); } } }
public final void writeContainer(WritableByteChannel bb) throws IOException { for (Box box : getBoxes()) { box.getBox(bb); } }
public void getBox(WritableByteChannel os) throws IOException { for (Box replacer : replacers) { replacer.getBox(os); } ByteBuffer header = ByteBuffer.allocate(8); IsoTypeWriter.writeUInt32(header, 8 + data.limit()); header.put(TYPE.getBytes()); header.rewind(); os.write(header); data.rewind(); os.write(data); }
protected final void writeChildBoxes(ByteBuffer bb) { WritableByteChannel wbc = new ByteBufferByteChannel(bb); for (Box box : boxes) { try { box.getBox(wbc); } catch (IOException e) { // My WritableByteChannel won't throw any excpetion throw new RuntimeException("Cannot happen to me", e); } } }
public void getBox(WritableByteChannel os) throws IOException { for (Box replacer : replacers) { replacer.getBox(os); } ByteBuffer header = ByteBuffer.allocate(8); IsoTypeWriter.writeUInt32(header, 8 + data.limit()); header.put(TYPE.getBytes()); header.rewind(); os.write(header); header.rewind(); data.rewind(); os.write(data); data.rewind(); }
public void write() throws IOException { final WritableByteChannel out = Channels.newChannel(outputStream); createFtyp().getBox(out); createMoov().getBox(out); ExecutorService es = Executors.newFixedThreadPool(source.length); for (StreamingTrack streamingTrack : source) { es.submit(new ConsumeSamplesCallable(streamingTrack)); } }
public void write() throws IOException { WritableByteChannel out = Channels.newChannel(outputStream); createFtyp().getBox(out); createMoov().getBox(out); do { try { StreamingSample ss; while ((ss = source.getSamples().poll(100, TimeUnit.MILLISECONDS)) != null) { consumeSample(ss, out); } } catch (InterruptedException e) { e.printStackTrace(); } } while (source.hasMoreSamples()); }
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 void finishMovie(boolean error) throws Exception { if (mdat.getContentSize() != 0) { flushCurrentMdat(); } for (Track track : currentMp4Movie.getTracks()) { List<Sample> samples = track.getSamples(); long[] sizes = new long[samples.size()]; for (int i = 0; i < sizes.length; i++) { sizes[i] = samples.get(i).getSize(); } track2SampleSizes.put(track, sizes); } Box moov = createMovieBox(currentMp4Movie); moov.getBox(fc); fos.flush(); fc.close(); fos.close(); }
public void finishMovie(boolean error) throws Exception { if (mdat.getContentSize() != 0) { flushCurrentMdat(); } for (Track track : currentMp4Movie.getTracks()) { List<Sample> samples = track.getSamples(); long[] sizes = new long[samples.size()]; for (int i = 0; i < sizes.length; i++) { sizes[i] = samples.get(i).getSize(); } track2SampleSizes.put(track, sizes); } Box moov = createMovieBox(currentMp4Movie); moov.getBox(fc); fos.flush(); fc.close(); fos.close(); }
public void finishMovie(boolean error) throws Exception { if (mdat.getContentSize() != 0) { flushCurrentMdat(); } for (Track track : currentMp4Movie.getTracks()) { List<Sample> samples = track.getSamples(); long[] sizes = new long[samples.size()]; for (int i = 0; i < sizes.length; i++) { sizes[i] = samples.get(i).getSize(); } track2SampleSizes.put(track, sizes); } Box moov = createMovieBox(currentMp4Movie); moov.getBox(fc); fos.flush(); fc.close(); fos.close(); }
private void consumeSample(StreamingSample ss, WritableByteChannel out) throws IOException { SampleFlagsSampleExtension sampleDependencySampleExtension = null; CompositionTimeSampleExtension compositionTimeSampleExtension = null; for (SampleExtension sampleExtension : ss.getExtensions()) { if (sampleExtension instanceof SampleFlagsSampleExtension) { sampleDependencySampleExtension = (SampleFlagsSampleExtension) sampleExtension; } else if (sampleExtension instanceof CompositionTimeSampleExtension) { compositionTimeSampleExtension = (CompositionTimeSampleExtension) sampleExtension; } } currentTime += ss.getDuration(); // 3 seconds = 3 * source.getTimescale() fragment.add(ss); if (currentTime > currentFragmentStartTime + 3 * source.getTimescale() && fragment.size() > 0 && (sampleDependencyTrackExtension == null || sampleDependencySampleExtension == null || sampleDependencySampleExtension.isSyncSample())) { createMoof().getBox(out); createMdat().getBox(out); currentFragmentStartTime = currentTime; fragment.clear(); } }