public List<Sample> getSamples() { return source.getSamples(); }
public List<Sample> getSamples() { return source.getSamples(); }
public List<Sample> getSamples() { return parent.getSamples(); }
public List<Sample> getSamples() { return source.getSamples(); }
@Override public int size() { return ReplaceSampleTrack.this.origTrack.getSamples().size(); } }
@Override public Sample get(int index) { if (ReplaceSampleTrack.this.sampleNumber == index) { return ReplaceSampleTrack.this.sampleContent; } else { return ReplaceSampleTrack.this.origTrack.getSamples().get(index); } }
public List<Sample> getSamples() { return origTrack.getSamples().subList(fromSample, toSample); }
/** * Gets all samples starting with <code>startSample</code> (one based -> one is the first) and * ending with <code>endSample</code> (exclusive). * * @param startSample low endpoint (inclusive) of the sample sequence * @param endSample high endpoint (exclusive) of the sample sequence * @param track source of the samples * @return a <code>List<Sample></code> of raw samples */ protected List<Sample> getSamples(long startSample, long endSample, Track track) { // since startSample and endSample are one-based substract 1 before addressing list elements return track.getSamples().subList(l2i(startSample) - 1, l2i(endSample) - 1); }
public static void main(String[] args) throws IOException { Movie m = MovieCreator.build("C:\\Users\\sannies\\Downloads\\3ae39746-7e83-4653-860b-78a59e6ef474 (3).mp4"); for (Track track : m.getTracks()) { System.err.print(track.getHandler()); System.err.print(track.getSamples().size()); } } }
public static void main(String[] args) throws IOException { Movie movie = MovieCreator.build(DumpAmf0TrackToPropertyFile.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/example.f4v"); for (Track track : movie.getTracks()) { if (track.getHandler().equals("data") ) { long time = 0; Iterator<Sample> samples = track.getSamples().iterator(); Properties properties = new Properties(); File f = File.createTempFile(DumpAmf0TrackToPropertyFile.class.getSimpleName(), "" + track.getTrackMetaData().getTrackId()); for (long decodingTime : track.getSampleDurations()) { ByteBuffer sample = samples.next().asByteBuffer(); byte[] sampleBytes = new byte[sample.limit()]; sample.reset(); sample.get(sampleBytes); properties.put("" + time, new String(Base64.encodeBase64(sampleBytes, false, false))); time += decodingTime; } FileOutputStream fos = new FileOutputStream(f); System.err.println(properties); properties.store(fos, ""); } } }
/** * Gets the chunk sizes for the given track. * * @param track the track we are talking about * @return the size of each chunk in number of samples */ int[] getChunkSizes(Track track) { long[] referenceChunkStarts = fragmenter.sampleNumbers(track); int[] chunkSizes = new int[referenceChunkStarts.length]; for (int i = 0; i < referenceChunkStarts.length; i++) { long start = referenceChunkStarts[i] - 1; long end; if (referenceChunkStarts.length == i + 1) { end = track.getSamples().size(); } else { end = referenceChunkStarts[i + 1] - 1; } chunkSizes[i] = l2i(end - start); } assert DefaultMp4Builder.this.track2Sample.get(track).size() == sum(chunkSizes) : "The number of samples and the sum of all chunk lengths must be equal"; return chunkSizes; }
public static void main(String[] args) throws IOException { String audioEnglish = RemoveSomeSamplesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-english-audio.mp4"; Movie originalMovie = MovieCreator.build(audioEnglish); Track audio = originalMovie.getTracks().get(0); Movie nuMovie = new Movie(); nuMovie.addTrack(new AppendTrack(new ClippedTrack(audio, 0, 10), new ClippedTrack(audio, 100, audio.getSamples().size()))); Container out = new DefaultMp4Builder().build(nuMovie); FileOutputStream fos = new FileOutputStream(new File("output.mp4")); out.writeContainer(fos.getChannel()); fos.close(); }
time += (double) nextChunksTrack.getSampleDurations()[j] / nextChunksTrack.getTrackMetaData().getTimescale(); chunkList.add(nextChunksTrack.getSamples().subList(startSample, startSample + numberOfSampleInNextChunk));
public AppendTrack(Track... tracks) throws IOException { super(appendTracknames(tracks)); this.tracks = tracks; for (Track track : tracks) { sampleEntries.addAll(track.getSampleEntries()); } 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 Avc1ToAvc3TrackImpl(Track parent) throws IOException { super(parent); for (SampleEntry sampleEntry : parent.getSampleEntries()) { if (sampleEntry.getType().equals("avc1")) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { // This creates a copy cause I can't change the original instance sampleEntry.getBox(Channels.newChannel(baos)); VisualSampleEntry avc3SampleEntry = (VisualSampleEntry) new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray()))).getBoxes().get(0); avc3SampleEntry.setType("avc3"); avc1toavc3.put(sampleEntry, avc3SampleEntry); } catch (IOException e) { throw new RuntimeException("Dumping sample entry to memory failed"); } } else { avc1toavc3.put(sampleEntry, sampleEntry); } } samples = new ReplaceSyncSamplesList(parent.getSamples()); }
protected void createStsc(Track track, Map<Track, int[]> chunks, SampleTableBox stbl) { int[] tracksChunkSizes = chunks.get(track); SampleToChunkBox stsc = new SampleToChunkBox(); stsc.setEntries(new LinkedList<SampleToChunkBox.Entry>()); long lastChunkSize = Integer.MIN_VALUE; // to be sure the first chunks hasn't got the same size long lastSampleDescriptionIndex = Integer.MIN_VALUE; List<Sample> samples = track.getSamples(); int currentSampleIndex = 0; List<SampleEntry> sampleEntries = track.getSampleEntries(); for (int i = 0; i < tracksChunkSizes.length; i++) { Sample sample = samples.get(currentSampleIndex); int currentSampleDescriptionIndex = sampleEntries.indexOf(sample.getSampleEntry()) + 1; // one base if (lastChunkSize != tracksChunkSizes[i] || lastSampleDescriptionIndex != currentSampleDescriptionIndex) { stsc.getEntries().add(new SampleToChunkBox.Entry(i + 1, tracksChunkSizes[i], currentSampleDescriptionIndex)); lastChunkSize = tracksChunkSizes[i]; lastSampleDescriptionIndex = currentSampleDescriptionIndex; } currentSampleIndex += tracksChunkSizes[i]; } stbl.addBox(stsc); }
public ReplaceSampleTrack(Track origTrack, long sampleNumber, ByteBuffer content) { super("replace(" + origTrack.getName() + ")"); this.origTrack = origTrack; this.sampleNumber = sampleNumber; this.sampleContent = new SampleImpl(content, this.origTrack.getSamples().get(l2i(sampleNumber)).getSampleEntry()); this.samples = new ReplaceASingleEntryList(); }
public long[] getSyncSamples() { if (tracks[0].getSyncSamples() != null && tracks[0].getSyncSamples().length > 0) { int numSyncSamples = 0; for (Track track : tracks) { numSyncSamples += track.getSyncSamples() != null ? track.getSyncSamples().length : 0; } long[] returnSyncSamples = new long[numSyncSamples]; int pos = 0; long samplesBefore = 0; for (Track track : tracks) { if (track.getSyncSamples() != null) { for (long l : track.getSyncSamples()) { returnSyncSamples[pos++] = samplesBefore + l; } } samplesBefore += track.getSamples().size(); } return returnSyncSamples; } else { return null; } }
sbgp.setGroupingType(type); SampleToGroupBox.Entry last = null; for (int i = 0; i < track.getSamples().size(); i++) { int index = 0; for (int j = 0; j < sg.getValue().size(); j++) {
protected void createTfhd(long startSample, long endSample, Track track, int sequenceNumber, TrackFragmentBox parent) { TrackFragmentHeaderBox tfhd = new TrackFragmentHeaderBox(); SampleFlags sf = new SampleFlags(); tfhd.setDefaultSampleFlags(sf); tfhd.setBaseDataOffset(-1); tfhd.setSampleDescriptionIndex(track.getSampleEntries().indexOf(track.getSamples().get(l2i(startSample)).getSampleEntry()) + 1); tfhd.setTrackId(track.getTrackMetaData().getTrackId()); tfhd.setDefaultBaseIsMoof(true); parent.addBox(tfhd); }