public static void main(String[] args) throws IOException { Movie video = MovieCreator.build( Channels.newChannel( Mp4WithAudioDelayExample.class.getResourceAsStream("/count-video.mp4"))); Movie audio = MovieCreator.build( Channels.newChannel( Mp4WithAudioDelayExample.class.getResourceAsStream("/count-english-audio.mp4"))); List<Track> videoTracks = video.getTracks(); video.setTracks(new LinkedList<Track>()); List<Track> audioTracks = audio.getTracks(); for (Track videoTrack : videoTracks) { video.addTrack(new AppendTrack(videoTrack, videoTrack)); } for (Track audioTrack : audioTracks) { audioTrack.getTrackMetaData().setStartTime(10.0); video.addTrack(audioTrack); } IsoFile out = new DefaultMp4Builder().build(video); FileOutputStream fos = new FileOutputStream(new File(String.format("output.mp4"))); out.getBox(fos.getChannel()); fos.close(); }
public void testRoundTrip_1(String resource) throws Exception { long start1 = System.currentTimeMillis(); String originalFile = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile() + resource; long start2 = System.currentTimeMillis(); IsoFile isoFile = new IsoFile(originalFile); long start3 = System.currentTimeMillis(); long start4 = System.currentTimeMillis(); Walk.through(isoFile); long start5 = System.currentTimeMillis(); File result = File.createTempFile(this.getName(), resource.replace("/", "_")); FileOutputStream fos = new FileOutputStream(result); FileChannel fcOut = fos.getChannel(); isoFile.getBox(fcOut); fcOut.close(); fos.close(); long start6 = System.currentTimeMillis(); /* System.err.println("Preparing tmp copy took: " + (start2 - start1) + "ms"); System.err.println("Parsing took : " + (start3 - start2) + "ms"); System.err.println("Writing took : " + (start6 - start3) + "ms"); System.err.println("Walking took : " + (start5 - start4) + "ms");*/ IsoFile copyViaIsoFileReparsed = new IsoFile(result.getAbsolutePath()); BoxComparator.check( isoFile, copyViaIsoFileReparsed, "/moov[0]/mvhd[0]", "/moov[0]/trak[0]/tkhd[0]", "/moov[0]/trak[0]/mdia[0]/mdhd[0]"); isoFile.close(); copyViaIsoFileReparsed.close(); result.deleteOnExit(); // as windows cannot delete file when something is memory mapped and the garbage collector // doesn't necessarily free the Buffers quickly enough we cannot delete the file here (we could // but only for linux) }
public void convert(Context context, String infile, String outfile) throws IOException { AACToM4A.context = context; InputStream input = new FileInputStream(infile); PushbackInputStream pbi = new PushbackInputStream(input, 100); System.err.println("well you got " + input.available()); Movie movie = new Movie(); Track audioTrack = new AACTrackImpl(pbi); movie.addTrack(audioTrack); IsoFile out = new DefaultMp4Builder().build(movie); FileOutputStream output = new FileOutputStream(outfile); out.getBox(output.getChannel()); output.close(); }