Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 26th, 2012  |  syntax: Java  |  size: 1.83 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import com.coremedia.iso.IsoBufferWrapperImpl;
  2. import com.coremedia.iso.IsoFile;
  3. import com.coremedia.iso.IsoOutputStream;
  4. import com.googlecode.mp4parser.authoring.Movie;
  5. import com.googlecode.mp4parser.authoring.Track;
  6. import com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder;
  7. import com.googlecode.mp4parser.authoring.container.mp4.MovieCreator;
  8. import com.googlecode.mp4parser.authoring.tracks.AppendTrack;
  9.  
  10. import java.io.BufferedOutputStream;
  11. import java.io.ByteArrayOutputStream;
  12. import java.io.File;
  13. import java.io.FileOutputStream;
  14. import java.io.IOException;
  15. import java.io.InputStream;
  16. import java.util.LinkedList;
  17. import java.util.List;
  18.  
  19. /**
  20.  *
  21.  */
  22. public class Concat {
  23.     public static void main(String[] args) throws IOException {
  24.  
  25.         Movie video1 = new MovieCreator().build(new IsoBufferWrapperImpl(readFully(Concat.class.getResourceAsStream("/76.mp4"))));
  26.         Movie video2 = new MovieCreator().build(new IsoBufferWrapperImpl(readFully(Concat.class.getResourceAsStream("/7.mp4"))));
  27.  
  28.         Track v1 = video1.getTracks().get(0);
  29.                 Track v2 = video2.getTracks().get(0);
  30.                
  31.         video1.setTracks(new LinkedList<Track>());
  32.                 video1.addTrack(new AppendTrack(v1, v2));
  33.  
  34.         IsoFile out = new DefaultMp4Builder().build(video1);
  35.         FileOutputStream fos = new FileOutputStream(new File(String.format("output.mp4")));
  36.         BufferedOutputStream bos = new BufferedOutputStream(fos);
  37.         out.getBox(new IsoOutputStream(bos));
  38.         bos.close();
  39.     }
  40.  
  41.  
  42.     static byte[] readFully(InputStream is) throws IOException {
  43.         ByteArrayOutputStream baos = new ByteArrayOutputStream();
  44.         byte[] buffer = new byte[2048];
  45.         int n = 0;
  46.         while (-1 != (n = is.read(buffer))) {
  47.             baos.write(buffer, 0, n);
  48.         }
  49.         return baos.toByteArray();
  50.     }
  51. }
clone this paste RAW Paste Data