Merging MP4 video files with Mp4parser

Source: Internet
Author: User

First, import the associated. jar file

Compile ' com.googlecode.mp4parser:isoparser:1.1.21 '
You can also use the download jar package

After the association is complete, use the following code to implement the merge

public class MergerMp4 {

    public  void MergeMP4 () {
        list<string> fileList = new arraylist<string> ();
        list<com.googlecode.mp4parser.authoring.movie> movieslist = new linkedlist<> ();
Add files that need to be merged Filelist.add ("/sdcard/video/20161122135659.mp4");
        Filelist.add ("/sdcard/video/20161122135810.mp4");
        Filelist.add ("/sdcard/video/20161122144321.mp4");
        Filelist.add ("/sdcard/video/20161122144357.mp4");

        Filelist.add ("/sdcard/video/20161122144447.mp4");
            try{for (String file:filelist) {movieslist.add (moviecreator.build (file));
        }} catch (IOException e) {e.printstacktrace ();
        } list<track> videotracks = new linkedlist<track> ();
        list<track> audiotracks = new linkedlist<track> ();
            for (Com.googlecode.mp4parser.authoring.Movie m:movieslist) {to (track t:m.gettracks ())
                {if (T.gethandler (). Equals ("Soun")) {Audiotracks.add (t);
       } if (T.gethandler (). Equals ("vide"))         {Videotracks.add (t);

        }}} Movie result = new movie (); try {if (audiotracks.size () > 0) {result.addtrack (new Appendtrack (AUD
            Iotracks.toarray (New Track[audiotracks.size ()))); } if (Videotracks.size () > 0) {result.addtrack (new Appendtrack (Videotracks.toa
            Rray (New Track[videotracks.size ()))); }} catch (IOException e) {//TODO auto-generated catch block E.printstac
        Ktrace ();

        } Container out = new Defaultmp4builder (). Build (result); try {
Output the merged file
            filechannel fc = new Randomaccessfile ("/sdcard/video/small/output2.mp4", "RW"). Getchannel ();
            Out.writecontainer (FC);
            Fc.close ();
        }
        catch (Exception e)
        {
            //TODO auto-generated catch block
            e.printstacktrace ();
        }

        Movieslist.clear ();
        Filelist.clear ();

    }

}

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.