public static void main(String[] args) throws IOException { Movie m = MovieCreator.build("C:\\Users\\sannies\\Downloads\\GOPR1008.MP4"); for (Track track : m.getTracks()) { System.err.println(track); } } }
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 m = MovieCreator.build("c:\\content\\big_buck_bunny_1080p_h264-2min-handbraked.mp4"); double movieDuration = 0; for (Track track : m.getTracks()) { movieDuration = Math.max((double) track.getDuration() / track.getTrackMetaData().getTimescale(), movieDuration); } // We got the full duration in seconds System.err.println("Bitrate in bit/s: " + (new File("c:\\content\\big_buck_bunny_1080p_h264-2min-handbraked.mp4").length() * 8 /movieDuration)); } }
public static void main(String[] args) throws IOException { File dest = File.createTempFile("Unmux", "main"); FileOutputStream fos = new FileOutputStream(dest); IOUtils.copy(new URL("http://org.mp4parser.s3.amazonaws.com/examples/Cosmos%20Laundromat%20small.mp4").openStream(), fos); fos.close(); Movie m = MovieCreator.build(dest.getAbsolutePath()); DefaultMp4Builder builder = new DefaultMp4Builder(); for (Track track : m.getTracks()) { Movie singleTrackMovie = new Movie(Collections.singletonList(track)); builder.build(singleTrackMovie).writeContainer(new RandomAccessFile(track.getHandler() + "_" + track.getTrackMetaData().getTrackId() + ".mp4", "rw").getChannel()); } } }
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, ""); } } }
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(); }
public static void main(String[] args) throws IOException { //Movie movie = new MovieCreator().build(new RandomAccessFile("/home/sannies/suckerpunch-distantplanet_h1080p/suckerpunch-distantplanet_h1080p.mov", "r").getChannel()); Movie movie = MovieCreator.build("C:\\content\\843D111F-E839-4597-B60C-3B8114E0AA72_ABR05.mp4"); List<Track> tracks = movie.getTracks(); assert tracks.size() == 1; Track track = movie.getTracks().get(0); movie.setTracks(new LinkedList<Track>()); // remove all tracks we will create new tracks from the old double startTime = 10; double endTime = 20; long startSample = findNextSyncSample(track, startTime); long endSample = findNextSyncSample(track, endTime); movie.addTrack(new ClippedTrack(track, startSample, endSample)); Container out = new DefaultMp4Builder().build(movie); FileOutputStream fos = new FileOutputStream(String.format("output-%f-%f.mp4", startTime, endTime)); FileChannel fc = fos.getChannel(); out.writeContainer(fc); fc.close(); fos.close(); }
public static void main(String[] args) throws IOException { Movie audioMovie = MovieCreator.build("/home/sannies/scm/svn/mp4parser/silence/sample.mp4"); Movie result = new Movie(); Track audio = audioMovie.getTracks().get(0); Track silence = new SilenceTrackImpl(audio, 2000); result.addTrack(new AppendTrack(silence, audio)); Container isoFile = new DefaultMp4Builder().build(result); FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel(); fc.position(0); isoFile.writeContainer(fc); fc.close(); } }
/** * Calculates the timestamp of all tracks' sync samples. * * @param movie <code>track</code> is located in this movie * @param track get this track's samples timestamps * @return a list of timestamps */ public static List<long[]> getSyncSamplesTimestamps(Movie movie, Track track) { List<long[]> times = new LinkedList<long[]>(); for (Track currentTrack : movie.getTracks()) { if (currentTrack.getHandler().equals(track.getHandler())) { long[] currentTrackSyncSamples = currentTrack.getSyncSamples(); if (currentTrackSyncSamples != null && currentTrackSyncSamples.length > 0) { final long[] currentTrackTimes = getTimes(currentTrack, movie); times.add(currentTrackTimes); } } } return times; }
public static void main(String[] args) throws IOException { Movie m = MovieCreator.build("C:\\dev\\mp4parser\\examples\\src\\main\\resources\\1365070453555.mp4"); for (Track track : m.getTracks()) { track.getEdits().clear();; track.getEdits().add(new Edit(0, 1, 1, 2.0)); } new DefaultMp4Builder().build(m).writeContainer(new FileOutputStream("output.mp4").getChannel()); } }
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 ReplaceSampleTrack( new ReplaceSampleTrack( new ReplaceSampleTrack( audio, 25, ByteBuffer.allocate(5)), 27, ByteBuffer.allocate(5)), 29, ByteBuffer.allocate(5))); Container out = new DefaultMp4Builder().build(nuMovie); FileOutputStream fos = new FileOutputStream(new File("output.mp4")); FileChannel fc = fos.getChannel(); out.writeContainer(fc); fos.close(); }
public static void main(String[] args) throws IOException { String f = Avc1ToAvc3Example.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/1365070268951.mp4"; Movie m = MovieCreator.build(new FileInputStream(f).getChannel(), new FileRandomAccessSourceImpl(new RandomAccessFile(f, "r")), "inmem"); Movie m2 = new Movie(); for (Track track : m.getTracks()) { if (track.getSampleEntries().get(0).getType().equals("avc1")) { m2.addTrack(new Avc1ToAvc3TrackImpl(track)); } else { m2.addTrack(track); } } new FragmentedMp4Builder().build(m2).writeContainer(new FileOutputStream("output.mp4").getChannel()); IsoFile i = new IsoFile("output.mp4"); for (Box box : i.getBoxes()) { System.err.println(box + "@-nooffsets"); } } }
public static void main(String[] args) throws IOException { Movie mWithVideo = MovieCreator.build("C:\\dev\\mp4parser\\examples\\src\\main\\resources\\davidappend\\v1.mp4"); Movie mWOutVideo = new Movie(); for (Track track : mWithVideo.getTracks()) { if (track.getHandler().equals("soun")) { mWOutVideo.addTrack(track); } } DefaultMp4Builder b = new DefaultMp4Builder(); Container c = b.build(mWOutVideo); c.writeContainer(new FileOutputStream("output.mp4").getChannel()); } }
public static void main(String[] args) throws IOException { IsoFile isofile = new IsoFile("C:\\content\\bbb-small\\output_320x180-mjpeg.mp4"); ESDescriptorBox esDescriptorBox = Path.getPath(isofile, "/moov[0]/trak[0]/mdia[0]/minf[0]/stbl[0]/stsd[0]/mp4v[0]/esds[0]"); byte[] d = new byte[esDescriptorBox.getData().rewind().remaining()]; esDescriptorBox.getData().get(d); System.err.println(Hex.encodeHex(d)); Movie mRef = MovieCreator.build("C:\\content\\bbb-small\\output_320x180_150.mp4"); Track refTrack = mRef.getTracks().get(0); File baseDir = new File("C:\\content\\bbb-small"); File[] iFrameJpegs = baseDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".jpg"); } }); Arrays.sort(iFrameJpegs); Movie mRes = new Movie(); mRes.addTrack(new OneJpegPerIframe("iframes", iFrameJpegs, refTrack)); new DefaultMp4Builder().build(mRes).writeContainer(new FileOutputStream("output-mjpeg.mp4").getChannel()); } }
public static void main(String[] args) throws IOException { Movie m1 = MovieCreator.build(("C:\\dev\\DRMTODAY-872\\Tears_Of_Steel_128000_eng.mp4")); Movie m2 = MovieCreator.build(("C:\\dev\\DRMTODAY-872\\Tears_Of_Steel_600000.mp4")); //WebVttTrack webVttTrack = new WebVttTrack(new , "subs", Locale.ENGLISH); TextTrackImpl textTrack = new TextTrackImpl(); textTrack.getSubs().addAll( WebVttParser.parse(new FileInputStream("C:\\dev\\DRMTODAY-872\\Tears_Of_Steel_eng.vtt"))); Movie m = new Movie(); for (Track track : m2.getTracks()) { m.addTrack(track); } for (Track track : m1.getTracks()) { m.addTrack(track); } m.addTrack(textTrack); DefaultMp4Builder builder = new DefaultMp4Builder(); builder.setFragmenter(new DefaultFragmenterImpl(2)); Container c = builder.build(m); WritableByteChannel wbc = new FileOutputStream("output.mp4").getChannel(); c.writeContainer(wbc); }
private static long calculateTracktimesScalingFactor(Movie m, Track track) { long timeScale = 1; for (Track track1 : m.getTracks()) { if (track1.getHandler().equals(track.getHandler())) { if (track1.getTrackMetaData().getTimescale() != track.getTrackMetaData().getTimescale()) { timeScale = lcm(timeScale, track1.getTrackMetaData().getTimescale()); } } } return timeScale; }
/** * Creates a 'mfra' - movie fragment random access box for the given movie in the given * isofile. Uses {@link #createTfra(Track, Container)} * to generate the child boxes. * * @param movie concerned movie * @param isoFile concerned isofile * @return a complete 'mfra' box */ protected ParsableBox createMfra(Movie movie, Container isoFile) { MovieFragmentRandomAccessBox mfra = new MovieFragmentRandomAccessBox(); for (Track track : movie.getTracks()) { mfra.addBox(createTfra(track, isoFile)); } MovieFragmentRandomAccessOffsetBox mfro = new MovieFragmentRandomAccessOffsetBox(); mfra.addBox(mfro); mfro.setMfraSize(mfra.getSize()); return mfra; }
/** * Creates a single 'mvhd' movie header box for a given movie. * * @param movie the concerned movie * @return an 'mvhd' box */ protected ParsableBox createMvhd(Movie movie) { MovieHeaderBox mvhd = new MovieHeaderBox(); mvhd.setVersion(1); mvhd.setCreationTime(getDate()); mvhd.setModificationTime(getDate()); mvhd.setDuration(0);//no duration in moov for fragmented movies long movieTimeScale = movie.getTimescale(); mvhd.setTimescale(movieTimeScale); // find the next available trackId long nextTrackId = 0; for (Track track : movie.getTracks()) { nextTrackId = nextTrackId < track.getTrackMetaData().getTrackId() ? track.getTrackMetaData().getTrackId() : nextTrackId; } mvhd.setNextTrackId(++nextTrackId); return mvhd; }