public SampleDescriptionBox getSampleDescriptionBox() { SampleDescriptionBox stsd = new SampleDescriptionBox(); ActionMessageFormat0SampleEntryBox amf0 = new ActionMessageFormat0SampleEntryBox(); amf0.setDataReferenceIndex(1); stsd.addBox(amf0); return stsd; }
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; }
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; }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); content.get(new byte[4]); parseChildBoxes(content); }
@Override protected void getContent(ByteBuffer byteBuffer) { writeVersionAndFlags(byteBuffer); IsoTypeWriter.writeUInt32(byteBuffer, boxes.size()); writeChildBoxes(byteBuffer); }
@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 { 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; } }
public SilenceTrackImpl(Track ofType, long ms) { source = ofType; if ("mp4a".equals(ofType.getSampleDescriptionBox().getSampleEntry().getType())) { long numFrames = getTrackMetaData().getTimescale() * ms / 1000 / 1024; long standZeit = getTrackMetaData().getTimescale() * ms / numFrames / 1000; entry = new TimeToSampleBox.Entry(numFrames, standZeit); while (numFrames-- > 0) { samples.add((ByteBuffer) ByteBuffer.wrap(new byte[]{ 0x21, 0x10, 0x04, 0x60, (byte) 0x8c, 0x1c, }).rewind()); } } else { throw new RuntimeException("Tracks of type " + ofType.getClass().getSimpleName() + " are not supported"); } }
xmlSubtitleSampleEntry.setSchemaLocation(""); xmlSubtitleSampleEntry.setAuxiliaryMimeTypes(join(",", new ArrayList<String>(mimeTypes).toArray(new String[mimeTypes.size()]))); sampleDescriptionBox.addBox(xmlSubtitleSampleEntry); trackMetaData.setTimescale(30000); trackMetaData.setLayer(65535);
public AbstractSampleEntry getSampleEntry() { for (AbstractSampleEntry box : getBoxes(AbstractSampleEntry.class)) { return box; } return null; }
public SilenceTrackImpl(Track ofType, long ms) { source = ofType; if ("mp4a".equals(ofType.getSampleDescriptionBox().getSampleEntry().getType())) { long numFrames = getTrackMetaData().getTimescale() * ms / 1000 / 1024; long standZeit = getTrackMetaData().getTimescale() * ms / numFrames / 1000; entry = new TimeToSampleBox.Entry(numFrames, standZeit); while (numFrames-- > 0) { samples.add((ByteBuffer) ByteBuffer.wrap(new byte[]{ 0x21, 0x10, 0x04, 0x60, (byte) 0x8c, 0x1c, }).rewind()); } } else { throw new RuntimeException("Tracks of type " + ofType.getClass().getSimpleName() + " are not supported"); } }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); content.get(new byte[4]); parseChildBoxes(content); }
@Override protected void getContent(ByteBuffer byteBuffer) { writeVersionAndFlags(byteBuffer); IsoTypeWriter.writeUInt32(byteBuffer, boxes.size()); writeChildBoxes(byteBuffer); }
public SampleDescriptionBox getSampleDescriptionBox() { SampleDescriptionBox stsd = new SampleDescriptionBox(); ActionMessageFormat0SampleEntryBox amf0 = new ActionMessageFormat0SampleEntryBox(); amf0.setDataReferenceIndex(1); stsd.addBox(amf0); return stsd; }
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 Avc1ToAvc3TrackImpl(Track parent) throws IOException { super(parent); if (!"avc1".equals(parent.getSampleDescriptionBox().getSampleEntry().getType())) { throw new RuntimeException("Only avc1 tracks can be converted to avc3 tracks"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); parent.getSampleDescriptionBox().getBox(Channels.newChannel(baos)); IsoFile isoFile = new IsoFile(new MemoryDataSourceImpl(baos.toByteArray())); this.stsd = Path.getPath(isoFile, "stsd"); ((VisualSampleEntry) stsd.getSampleEntry()).setType("avc3"); avcC = Path.getPath(stsd, "avc./avcC"); samples = new ReplaceSyncSamplesList(parent.getSamples()); }
public SilenceTrackImpl(Track ofType, long ms) { source = ofType; name = "" + ms + "ms silence"; if ("mp4a".equals(ofType.getSampleDescriptionBox().getSampleEntry().getType())) { int numFrames = l2i(getTrackMetaData().getTimescale() * ms / 1000 / 1024); decodingTimes = new long[numFrames]; Arrays.fill(decodingTimes, getTrackMetaData().getTimescale() * ms / numFrames / 1000); while (numFrames-- > 0) { samples.add(new SampleImpl((ByteBuffer) ByteBuffer.wrap(new byte[]{ 0x21, 0x10, 0x04, 0x60, (byte) 0x8c, 0x1c, }).rewind())); } } else { throw new RuntimeException("Tracks of type " + ofType.getClass().getSimpleName() + " are not supported"); } }
public SampleDescriptionBox getSampleDescriptionBox() { SampleDescriptionBox stsd = new SampleDescriptionBox(); ActionMessageFormat0SampleEntryBox amf0 = new ActionMessageFormat0SampleEntryBox(); amf0.setDataReferenceIndex(1); stsd.addBox(amf0); return stsd; }
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()); } } } }
ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { source.getSampleDescriptionBox().getBox(Channels.newChannel(baos)); stsd = (SampleDescriptionBox) new IsoFile(new MemoryDataSourceImpl(baos.toByteArray())).getBoxes().get(0); } catch (IOException e) { originalFormatBox.setDataFormat(stsd.getSampleEntry().getType()); if (stsd.getSampleEntry() instanceof AudioSampleEntry) { ((AudioSampleEntry) stsd.getSampleEntry()).setType("enca"); } else if (stsd.getSampleEntry() instanceof VisualSampleEntry) { ((VisualSampleEntry) stsd.getSampleEntry()).setType("encv"); } else { throw new RuntimeException("I don't know how to cenc " + stsd.getSampleEntry().getType()); stsd.getSampleEntry().addBox(sinf);