public static void main(String[] args) throws IOException { List<Movie> movies = new LinkedList<Movie>(); movies.add(MovieCreator.build(DavidAppend.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/davidappend/v1.mp4")); movies.add(MovieCreator.build(DavidAppend.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/davidappend/v2.mp4")); movies.add(MovieCreator.build(DavidAppend.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/davidappend/v2.mp4")); List<Track> videoTracks = new LinkedList<Track>(); List<Track> audioTracks = new LinkedList<Track>(); for (Movie m : movies) { for (Track track : m.getTracks()) { if (track.getHandler().equals("vide")) { videoTracks.add(track); } if (track.getHandler().equals("soun")) { audioTracks.add(track); } } } Movie concatMovie = new Movie(); concatMovie.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()]))); concatMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()]))); Container out2 = new DefaultMp4Builder().build(concatMovie); FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel(); fc.position(0); out2.writeContainer(fc); fc.close(); }
public static void main(String[] args) throws IOException { String f1 = AppendExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/1365070268951.mp4"; Movie inMovie = MovieCreator.build(f1); inMovie.setMatrix(Matrix.ROTATE_90); new DefaultMp4Builder().build(inMovie).writeContainer(new FileOutputStream("output.mp4").getChannel()); } }
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 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 { 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 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(); } }
List<Track> tracks = movie.getTracks(); movie.setTracks(new LinkedList<Track>()); if (track.getSyncSamples() != null && track.getSyncSamples().length > 0) { if (timeCorrected) { long endSample1 = -1; for (int i = 0; i < track.getSampleDurations().length; i++) { long delta = track.getSampleDurations()[i]; currentSample++; movie.addTrack(new AppendTrack(new ClippedTrack(track, startSample1, endSample1))); Container out = new DefaultMp4Builder().build(movie); long start2 = System.currentTimeMillis(); FileOutputStream fos = new FileOutputStream(String.format("output-%f-%f.mp4", startTime1, endTime1)); FileChannel fc = fos.getChannel(); out.writeContainer(fc); fos.close(); long start3 = System.currentTimeMillis(); System.err.println("Building IsoFile took : " + (start2 - start1) + "ms");
public static void main(String[] args) throws IOException { String basePath = GetDuration.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/dash/"; Movie m = new Movie(); IsoFile baseIsoFile = new IsoFile(basePath + "redbull_100kbit_dash.mp4"); List<IsoFile> fragments = new LinkedList<IsoFile>(); for (int i = 1; i < 9; i++) { fragments.add(new IsoFile(basePath + "redbull_10sec" + i + ".m4s")); } m.addTrack(new Mp4TrackImpl(1, new IsoFile("redbull_100kbit_dash.mp4"), new FileRandomAccessSourceImpl(new RandomAccessFile("redbull_100kbit_dash.mp4", "r")), "test")); DefaultMp4Builder builder = new DefaultMp4Builder(); Container stdMp4 = builder.build(m); FileOutputStream fos = new FileOutputStream("out.mp4"); stdMp4.writeContainer(fos.getChannel()); fos.close(); } }
List<Track> videoTracks = new LinkedList<Track>(); for (Track t : video.getTracks()) { if (t.getHandler().equals("vide")) { videoTracks.add(t); Track audioTrack = audio.getTracks().get(0);// get your audio track to dub the video Movie result = new Movie(); result.addTrack(videoTracks.get(0)); // add the video seprated from the originals result.addTrack(audioTrack); //add the track to be put in resul video Container out = new DefaultMp4Builder().build(result); fos = new FileOutputStream(OutPutVideoPath); } catch (FileNotFoundException e) { e.printStackTrace(); out.writeContainer(byteBufferByteChannel); byteBufferByteChannel.close(); fos.close(); } catch (IOException e) { e.printStackTrace();
public static void main(String[] args) throws IOException { String audioDeutsch = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-deutsch-audio.mp4"; String audioEnglish = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-english-audio.mp4"; String video = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-video.mp4"; Movie countVideo = MovieCreator.build(video); Movie countAudioDeutsch = MovieCreator.build(audioDeutsch); Movie countAudioEnglish = MovieCreator.build(audioEnglish); Track audioTrackDeutsch = countAudioDeutsch.getTracks().get(0); audioTrackDeutsch.getTrackMetaData().setLanguage("deu"); Track audioTrackEnglish = countAudioEnglish.getTracks().get(0); audioTrackEnglish.getTrackMetaData().setLanguage("eng"); countVideo.addTrack(audioTrackDeutsch); countVideo.addTrack(audioTrackEnglish); { Container out = new DefaultMp4Builder().build(countVideo); FileOutputStream fos = new FileOutputStream(new File("output.mp4")); out.writeContainer(fos.getChannel()); fos.close(); } { FragmentedMp4Builder fragmentedMp4Builder = new FragmentedMp4Builder(); fragmentedMp4Builder.setFragmenter(new SyncSampleIntersectFinderImpl(countVideo, null, -1)); Container out = fragmentedMp4Builder.build(countVideo); FileOutputStream fos = new FileOutputStream(new File("output-frag.mp4")); out.writeContainer(fos.getChannel()); fos.close(); } }
}; List<Track> audioTracks = new LinkedList<Track>(); for (Track t : m.getTracks()) { if (t.getHandler().equals("soun")) { audioTracks.add(t); Movie result = new Movie(); result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()]))); Container out = new DefaultMp4Builder().build(result); out.writeContainer(new FileOutputStream(outputVideo).getChannel());
public static void main(String[] args) throws IOException { String videoFile = MuxVideoWithAmf0.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/example-sans-amf0.mp4"; Movie video = MovieCreator.build(videoFile); Properties props = new Properties(); props.load(MuxVideoWithAmf0.class.getResourceAsStream("/amf0track.properties")); HashMap<Long, byte[]> samples = new HashMap<Long, byte[]>(); for (String key : props.stringPropertyNames()) { samples.put(Long.parseLong(key), Base64.decodeBase64(props.getProperty(key))); } Track amf0Track = new Amf0Track(samples); amf0Track.getTrackMetaData(); video.addTrack(amf0Track); FragmentedMp4Builder fragmentedMp4Builder = new FragmentedMp4Builder(); fragmentedMp4Builder.setFragmenter(new DefaultFragmenterImpl(2)); Container out = fragmentedMp4Builder.build(video); FileOutputStream fos = new FileOutputStream(new File(String.format("output.mp4"))); FileChannel fc = fos.getChannel(); out.writeContainer(fc); fos.close(); } }
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { for (Track track : m.getTracks()) { if (track.getHandler().endsWith("vide")) { Movie vide = new Movie(Collections.singletonList(track)); DefaultMp4Builder builder = new DefaultMp4Builder(); builder.build(vide).writeContainer(new RandomAccessFile("vide_" + track.getTrackMetaData().getTrackId() + ".mp4", "rw").getChannel()); if (track.getHandler().endsWith("soun")) { Movie vide = new Movie(Collections.singletonList(track)); DefaultMp4Builder builder = new DefaultMp4Builder(); builder.build(vide).writeContainer(new RandomAccessFile("soun_" + track.getTrackMetaData().getTrackId() + ".mp4", "rw").getChannel()); if (track.getHandler().endsWith("subt")) { ByteBuffer pic = (ByteBuffer) sample.slice().limit(l2i(picSubSampleEntry.getSubsampleSize())); sample = ((ByteBuffer) sample.position(l2i(picSubSampleEntry.getSubsampleSize()))).slice(); FileOutputStream fosPic = new FileOutputStream( "subtitle_" + track.getTrackMetaData().getTrackId() + "_" + i + "_" + imageNames.get(p++).replace(":", "_")); fosPic.getChannel().write(pic); "subtitle_" + track.getTrackMetaData().getTrackId() + "_" + i + "_" + imageName.replace(":", "_")); IOUtils.write(content, new FileOutputStream(f));
List<Track> tracks = movie.getTracks(); Log.e("tracks size", "track size =" + tracks.size()); movie.setTracks(new LinkedList<Track>()); movie.addTrack(new CroppedTrack(track, startSample, endSample)); Container mp4file = new DefaultMp4Builder().build(movie); try { RandomAccessFile ram = new RandomAccessFile(String.format(outFileDir), "rw"); FileChannel fc = ram.getChannel();//nwew FileOutputStream(new File(outFileDir)).getChannel(); mp4file.writeContainer(fc); fc.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 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()); } }
/** * 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\\schaf-schleppt-knüppel.mp4"); Track videoTrack = null; for (Track track : m.getTracks()) { if ("vide".equals(track.getHandler())) { videoTrack = track; throw new RuntimeException("You need a video track!"); int refNumSamples = videoTrack.getSamples().size(); long[] refSampleDuration = videoTrack.getSampleDurations(); long[] syncSamples = videoTrack.getSyncSamples(); double[] syncSampleTimes = new double[0]; for (Track track : m.getTracks()) { List<Track> chops = new ArrayList<Track>(); Mp4Builder b = new DefaultMp4Builder(); Movie chopped = new Movie(); chopped.addTrack(tracks.get(track).get(i)); b.build(chopped).writeContainer(new FileOutputStream("out-" + i + ".mp4").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 void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String start = request.getParameter("start"); List<Track> tracks = movie.getTracks(); movie.setTracks(new LinkedList<Track>()); double endTime = (double) tracks.get(0).getDuration() / tracks.get(0).getTrackMetaData().getTimescale(); if (track.getSyncSamples() != null && track.getSyncSamples().length > 0) { if (timeCorrected) { currentSample++; movie.addTrack(new ClippedTrack(track, startSample, endSample)); Container out = new DefaultMp4Builder().build(movie); response.setHeader("content-type", "video/mp4"); WritableByteChannel reponse = Channels.newChannel(response.getOutputStream());