protected void createStsd(Track track, SampleTableBox stbl) { SampleDescriptionBox stsd = new SampleDescriptionBox(); stsd.setBoxes(track.getSampleEntries()); stbl.addBox(stsd); }
public AbstractSampleEntry getSampleEntry() { for (AbstractSampleEntry box : getBoxes(AbstractSampleEntry.class)) { return box; } return null; }
private SampleDescriptionBox mergeStsds(SampleDescriptionBox stsd1, SampleDescriptionBox stsd2) throws IOException { ByteArrayOutputStream curBaos = new ByteArrayOutputStream(); ByteArrayOutputStream refBaos = new ByteArrayOutputStream(); try { stsd1.getBox(Channels.newChannel(curBaos)); stsd2.getBox(Channels.newChannel(refBaos)); } catch (IOException e) { LOG.error(e.getMessage()); return null; } byte[] cur = curBaos.toByteArray(); byte[] ref = refBaos.toByteArray(); if (!Arrays.equals(ref, cur)) { SampleEntry se = mergeSampleEntry(stsd1.getBoxes(SampleEntry.class).get(0), stsd2.getBoxes(SampleEntry.class).get(0)); if (se != null) { stsd1.setBoxes(Collections.<ParsableBox>singletonList(se)); } else { throw new IOException("Cannot merge " + stsd1.getBoxes(SampleEntry.class).get(0) + " and " + stsd2.getBoxes(SampleEntry.class).get(0)); } } return stsd1; }
@Override public void getBox(WritableByteChannel writableByteChannel) throws IOException { writableByteChannel.write(getHeader()); ByteBuffer versionFlagNumOfChildBoxes = ByteBuffer.allocate(8); IsoTypeWriter.writeUInt8(versionFlagNumOfChildBoxes, version); IsoTypeWriter.writeUInt24(versionFlagNumOfChildBoxes, flags); IsoTypeWriter.writeUInt32(versionFlagNumOfChildBoxes, getBoxes().size()); writableByteChannel.write((ByteBuffer) versionFlagNumOfChildBoxes.rewind()); writeContainer(writableByteChannel); }
log.debug("stsd children: {}", stsd.getBoxes().size()); MP4Reader.dumpBox(stsd); SampleEntry entry = stsd.getSampleEntry(); log.debug("Sample entry type: {}", entry.getType());
stsd = new SampleDescriptionBox(); stsd.addBox(visualSampleEntry);
@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { ByteBuffer versionFlagNumOfChildBoxes = ByteBuffer.allocate(8); dataSource.read(versionFlagNumOfChildBoxes); versionFlagNumOfChildBoxes.rewind(); version = IsoTypeReader.readUInt8(versionFlagNumOfChildBoxes); flags = IsoTypeReader.readUInt24(versionFlagNumOfChildBoxes); // number of child boxes is not required initContainer(dataSource, contentSize - 8, boxParser); }
@Override public long getSize() { long s = getContainerSize(); long t = 8; return s + t + ((largeBox || (s + t + 8) >= (1L << 32)) ? 16 : 8); } }
log.debug("stsd children: {}", stsd.getBoxes().size()); MP4Reader.dumpBox(stsd); SampleEntry entry = stsd.getSampleEntry(); log.debug("Sample entry type: {}", entry.getType());
@Override public void getBox(WritableByteChannel writableByteChannel) throws IOException { writableByteChannel.write(getHeader()); ByteBuffer versionFlagNumOfChildBoxes = ByteBuffer.allocate(8); IsoTypeWriter.writeUInt8(versionFlagNumOfChildBoxes, version); IsoTypeWriter.writeUInt24(versionFlagNumOfChildBoxes, flags); IsoTypeWriter.writeUInt32(versionFlagNumOfChildBoxes, getBoxes().size()); writableByteChannel.write((ByteBuffer) versionFlagNumOfChildBoxes.rewind()); writeContainer(writableByteChannel); }
public synchronized SampleDescriptionBox getSampleDescriptionBox() { waitForFirstSample(); if (stsd == null) { stsd = new SampleDescriptionBox(); AudioSampleEntry audioSampleEntry = new AudioSampleEntry("mp4a"); if (firstHeader.channelconfig == 7) { stsd.addBox(audioSampleEntry);
@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { ByteBuffer versionFlagNumOfChildBoxes = ByteBuffer.allocate(8); dataSource.read(versionFlagNumOfChildBoxes); versionFlagNumOfChildBoxes.rewind(); version = IsoTypeReader.readUInt8(versionFlagNumOfChildBoxes); flags = IsoTypeReader.readUInt24(versionFlagNumOfChildBoxes); // number of child boxes is not required initContainer(dataSource, contentSize - 8, boxParser); }
@Override public long getSize() { long s = getContainerSize(); long t = 8; return s + t + ((largeBox || (s + t + 8) >= (1L << 32)) ? 16 : 8); } }
protected void createStsd(Track track, SampleTableBox stbl) { SampleDescriptionBox stsd = new SampleDescriptionBox(); stsd.setBoxes(track.getSampleEntries()); stbl.addBox(stsd); }
public List<SampleEntry> getSampleEntries() { return sampleDescriptionBox.getBoxes(SampleEntry.class); }
private SampleDescriptionBox mergeStsds(SampleDescriptionBox stsd1, SampleDescriptionBox stsd2) throws IOException { ByteArrayOutputStream curBaos = new ByteArrayOutputStream(); ByteArrayOutputStream refBaos = new ByteArrayOutputStream(); try { stsd1.getBox(Channels.newChannel(curBaos)); stsd2.getBox(Channels.newChannel(refBaos)); } catch (IOException e) { LOG.error(e.getMessage()); return null; } byte[] cur = curBaos.toByteArray(); byte[] ref = refBaos.toByteArray(); if (!Arrays.equals(ref, cur)) { SampleEntry se = mergeSampleEntry(stsd1.getBoxes(SampleEntry.class).get(0), stsd2.getBoxes(SampleEntry.class).get(0)); if (se != null) { stsd1.setBoxes(Collections.<ParsableBox>singletonList(se)); } else { throw new IOException("Cannot merge " + stsd1.getBoxes(SampleEntry.class).get(0) + " and " + stsd2.getBoxes(SampleEntry.class).get(0)); } } return stsd1; }
log.debug("stsd children: {}", stsd.getBoxes().size()); dumpBox(stsd); SampleEntry entry = stsd.getSampleEntry(); if (entry != null) { log.debug("Sample entry type: {}", entry.getType());
protected void createStsd(Track track, SampleTableBox stbl) { SampleDescriptionBox stsd = new SampleDescriptionBox(); stsd.setBoxes(track.getSampleEntries()); stbl.addBox(stsd); }
public FragmentedMp4SampleList(long track, Container isofile, RandomAccessSource randomAccess) { this.isofile = isofile; this.randomAccess = randomAccess; List<TrackBox> tbs = Path.getPaths(isofile, "moov[0]/trak"); for (TrackBox tb : tbs) { if (tb.getTrackHeaderBox().getTrackId() == track) { trackBox = tb; } } if (trackBox == null) { throw new RuntimeException("This MP4 does not contain track " + track); } List<TrackExtendsBox> trexs = Path.getPaths(isofile, "moov[0]/mvex[0]/trex"); for (TrackExtendsBox box : trexs) { if (box.getTrackId() == trackBox.getTrackHeaderBox().getTrackId()) { trex = box; } } sampleEntries = new ArrayList<>(trackBox.getSampleTableBox().getSampleDescriptionBox().getBoxes(SampleEntry.class)); if (sampleEntries.size() != trackBox.getSampleTableBox().getSampleDescriptionBox().getBoxes().size()) throw new AssertionError("stsd contains not only sample entries. Something's wrong here! Bailing out"); sampleCache = (SoftReference<Sample>[]) Array.newInstance(SoftReference.class, size()); initAllFragments(); }
log.debug("stsd children: {}", stsd.getBoxes().size()); dumpBox(stsd); SampleEntry entry = stsd.getSampleEntry(); if (entry != null) { log.debug("Sample entry type: {}", entry.getType());