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.logError(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.<Box>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); }
public AppendTrack(Track... tracks) throws IOException { this.tracks = tracks; for (Track track : tracks) { if (stsd == null) { stsd = track.getSampleDescriptionBox(); } else { ByteArrayOutputStream curBaos = new ByteArrayOutputStream(); ByteArrayOutputStream refBaos = new ByteArrayOutputStream(); track.getSampleDescriptionBox().getBox(Channels.newChannel(curBaos)); stsd.getBox(Channels.newChannel(refBaos)); byte[] cur = curBaos.toByteArray(); byte[] ref = refBaos.toByteArray(); if (!Arrays.equals(ref, cur)) { SampleDescriptionBox curStsd = track.getSampleDescriptionBox(); if (stsd.getBoxes().size() == 1 && curStsd.getBoxes().size() == 1) { if (stsd.getBoxes().get(0) instanceof AudioSampleEntry && curStsd.getBoxes().get(0) instanceof AudioSampleEntry) { AudioSampleEntry aseResult = mergeAudioSampleEntries((AudioSampleEntry) stsd.getBoxes().get(0), (AudioSampleEntry) curStsd.getBoxes().get(0)); if (aseResult != null) { stsd.setBoxes(Collections.<Box>singletonList(aseResult)); return; } } } throw new IOException("Cannot append " + track + " to " + tracks[0] + " since their Sample Description Boxes differ: \n" + track.getSampleDescriptionBox() + "\n vs. \n" + tracks[0].getSampleDescriptionBox()); } } } }
public AppendTrack(Track... tracks) throws IOException { this.tracks = tracks; for (Track track : tracks) { if (stsd == null) { stsd = track.getSampleDescriptionBox(); } else { ByteArrayOutputStream curBaos = new ByteArrayOutputStream(); ByteArrayOutputStream refBaos = new ByteArrayOutputStream(); track.getSampleDescriptionBox().getBox(Channels.newChannel(curBaos)); stsd.getBox(Channels.newChannel(refBaos)); byte[] cur = curBaos.toByteArray(); byte[] ref = refBaos.toByteArray(); if (!Arrays.equals(ref, cur)) { SampleDescriptionBox curStsd = track.getSampleDescriptionBox(); if (stsd.getBoxes().size() == 1 && curStsd.getBoxes().size() == 1) { if (stsd.getBoxes().get(0) instanceof AudioSampleEntry && curStsd.getBoxes().get(0) instanceof AudioSampleEntry) { AudioSampleEntry aseResult = mergeAudioSampleEntries((AudioSampleEntry) stsd.getBoxes().get(0), (AudioSampleEntry) curStsd.getBoxes().get(0)); if (aseResult != null) { stsd.setBoxes(Collections.<Box>singletonList(aseResult)); return; } } } throw new IOException("Cannot append " + track + " to " + tracks[0] + " since their Sample Description Boxes differ: \n" + track.getSampleDescriptionBox() + "\n vs. \n" + tracks[0].getSampleDescriptionBox()); } } } }
public AppendTrack(Track... tracks) throws IOException { super(appendTracknames(tracks)); this.tracks = tracks; for (Track track : tracks) { if (stsd == null) { stsd = new SampleDescriptionBox(); stsd.addBox(track.getSampleDescriptionBox().getBoxes(SampleEntry.class).get(0)); } else { stsd = mergeStsds(stsd, track.getSampleDescriptionBox()); } } lists = new ArrayList<Sample>(); for (Track track : tracks) { //System.err.println("Track " + track + " is about to be appended"); lists.addAll(track.getSamples()); } int numSamples = 0; for (Track track : tracks) { numSamples += track.getSampleDurations().length; } decodingTimes = new long[numSamples]; int index = 0; // should use system arraycopy but this works too (yes it's slow ...) for (Track track : tracks) { long[] durs = track.getSampleDurations(); System.arraycopy(durs, 0, decodingTimes, index, durs.length); index += durs.length; } }