// You can merge any amount of movies, but some format are less stable
        public void Merge(string sourceDirectory, string movie1, string movie2, string destinationDirectory, string destinationFile)
        {
            var inMovies = new Com.Googlecode.Mp4parser.Authoring.Movie[] {
                MovieCreator.Build(Path.Combine(sourceDirectory, movie1)),
                MovieCreator.Build(Path.Combine(sourceDirectory, movie2)),
            };

            var videoTracks = new List <ITrack>();
            var audioTracks = new List <ITrack>();

            foreach (var m in inMovies)
            {
                foreach (var t in m.Tracks)
                {
                    if (t.Handler.Equals("soun"))
                    {
                        audioTracks.Add(t);
                    }
                    if (t.Handler.Equals("vide"))
                    {
                        videoTracks.Add(t);
                    }
                }
            }

            var result = new Com.Googlecode.Mp4parser.Authoring.Movie();

            if (audioTracks.Count > 0)
            {
                result.AddTrack(new AppendTrack(audioTracks.ToArray()));
            }
            if (videoTracks.Count > 0)
            {
                result.AddTrack(new AppendTrack(videoTracks.ToArray()));
            }

            var outContainer = new DefaultMp4Builder().Build(result);

            var fc = new FileOutputStream(Path.Combine(destinationDirectory, destinationFile)).Channel;

            outContainer.WriteContainer(fc);
            fc.Close();
        }
        public void MergeVideos(string[] pathNames, string outputPath)
        {
            List <Movie> inMovies = new List <Movie>();
            Movie        movie    = new Movie();

            foreach (string path in pathNames)
            {
                inMovies.Add(MovieCreator.Build(path));
            }

            List <List <ITrack> > allTracks = new List <List <ITrack> >();

            for (int i = 0; i < pathNames.Length; i++)
            {
                allTracks.Add(new List <ITrack>());
            }

            for (int i = 0; i < inMovies.Count(); i++)
            {
                foreach (ITrack track in inMovies[i].Tracks)
                {
                    allTracks[i].Add(track);
                }
            }

            ITrack[] tracks = new ITrack[allTracks.Count()];
            for (int i = 0; i < allTracks[0].Count(); i++)
            {
                for (int j = 0; j < allTracks.Count(); j++)
                {
                    tracks[j] = allTracks[j][i];
                }
                movie.AddTrack(new AppendTrack(tracks));
                tracks = new ITrack[allTracks.Count()];
            }


            BasicContainer   oout = (BasicContainer) new DefaultMp4Builder().Build(movie);
            FileOutputStream fos  = new FileOutputStream(new File(outputPath));

            oout.WriteContainer(fos.Channel);
            fos.Close();
        }