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"); } }
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"); } }
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; }
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 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()); }
videoFragmentsDurations = checkFragmentsAlign(videoFragmentsDurations, calculateFragmentDurations(track, movie)); SampleDescriptionBox stsd = track.getSampleDescriptionBox(); videoQualities.add(getVideoQuality(track, (VisualSampleEntry) stsd.getSampleEntry())); if (videoTimescale == -1) { videoTimescale = track.getTrackMetaData().getTimescale(); audioFragmentsDurations = checkFragmentsAlign(audioFragmentsDurations, calculateFragmentDurations(track, movie)); SampleDescriptionBox stsd = track.getSampleDescriptionBox(); audioQualities.add(getAudioQuality(track, (AudioSampleEntry) stsd.getSampleEntry())); if (audioTimescale == -1) { audioTimescale = track.getTrackMetaData().getTimescale();
videoFragmentsDurations = checkFragmentsAlign(videoFragmentsDurations, calculateFragmentDurations(track, movie)); SampleDescriptionBox stsd = track.getSampleDescriptionBox(); videoQualities.add(getVideoQuality(track, (VisualSampleEntry) stsd.getSampleEntry())); if (videoTimescale == -1) { videoTimescale = track.getTrackMetaData().getTimescale(); audioFragmentsDurations = checkFragmentsAlign(audioFragmentsDurations, calculateFragmentDurations(track, movie)); SampleDescriptionBox stsd = track.getSampleDescriptionBox(); audioQualities.add(getAudioQuality(track, (AudioSampleEntry) stsd.getSampleEntry())); if (audioTimescale == -1) { audioTimescale = track.getTrackMetaData().getTimescale();
static String getFormat(Track track) { SampleDescriptionBox stsd = track.getSampleDescriptionBox(); OriginalFormatBox frma = Path.getPath(stsd, "enc./sinf/frma"); if (frma!=null) { return frma.getDataFormat(); } else { return stsd.getSampleEntry().getType(); } }
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);
List<Box> boxes = source.getSampleDescriptionBox().getSampleEntry().getBoxes(); int nalLengthSize = -1; for (Box box : boxes) {
for (Track testTrack : movie.getTracks()) { if ("soun".equals(testTrack.getHandler())) { AudioSampleEntry ase = (AudioSampleEntry) testTrack.getSampleDescriptionBox().getSampleEntry(); if (ase.getSampleRate() < minSampleRate) { minSampleRate = ase.getSampleRate(); AudioSampleEntry ase = (AudioSampleEntry) track.getSampleDescriptionBox().getSampleEntry(); TimeToSampleBox.Entry sttsEntry = track.getDecodingTimeEntries().get(0); long samplesPerFrame = sttsEntry.getDelta(); // Assuming all audio tracks have the same number of samples per frame, which they do for all known types
for (Track testTrack : movie.getTracks()) { if ("soun".equals(testTrack.getHandler())) { AudioSampleEntry ase = (AudioSampleEntry) testTrack.getSampleDescriptionBox().getSampleEntry(); if (ase.getSampleRate() < minSampleRate) { minSampleRate = ase.getSampleRate(); AudioSampleEntry ase = (AudioSampleEntry) track.getSampleDescriptionBox().getSampleEntry(); TimeToSampleBox.Entry sttsEntry = track.getDecodingTimeEntries().get(0); long samplesPerFrame = sttsEntry.getDelta(); // Assuming all audio tracks have the same number of samples per frame, which they do for all known types
for (Track testTrack : movie.getTracks()) { if (getFormat(track).equals(getFormat(testTrack))) { AudioSampleEntry ase = (AudioSampleEntry) testTrack.getSampleDescriptionBox().getSampleEntry(); if (ase.getSampleRate() < minSampleRate) { minSampleRate = ase.getSampleRate(); AudioSampleEntry ase = (AudioSampleEntry) track.getSampleDescriptionBox().getSampleEntry();