public void Mux(string videoTrackFile, string audioTrackFile, string destinationFolder, string destinationFile)
        {
            Task.Run(() => {
                var res       = System.IO.File.Exists(destinationFolder + "/" + videoTrackFile);
                var h264Track = new H264TrackImpl(new FileDataSourceImpl(Path.Combine(destinationFolder, videoTrackFile)));
                var aacTrack  = new AACTrackImpl(new FileDataSourceImpl(Path.Combine(destinationFolder, audioTrackFile)));

                var movie = new Movie();
                movie.AddTrack(h264Track);
                movie.AddTrack(aacTrack);

                var mp4builder = new DefaultMp4Builder();

                var mp4file = mp4builder.Build(movie);
                var fc      = new FileOutputStream(new Java.IO.File(Path.Combine(destinationFolder, destinationFile))).Channel;
                mp4file.WriteContainer(fc);
                fc.Close();
            });
        }
예제 #2
0
        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();
        }