Exemple #1
0
    public void AddMediaInfo(string fName)
    {
        var sourceMovie = new MediaInfo();

        if (sourceMovie.OpenFromFile(fName))
        {
            var firstVideoTrack = sourceMovie.FirstVideoTrack;

            if (sourceMovie.AudioTracks.Count > 0 || firstVideoTrack != null)
            {
                var targetMovie = new MediaInfo();
                sourceMovie.Copyto(targetMovie, false);

                if (firstVideoTrack != null)
                {
                    targetMovie.TargetContainer  = MediaConvertGUIConfiguration.DefaultContainer;
                    targetMovie.TargetVideoCodec = MediaConvertGUIConfiguration.GetVideoCodecByName("copy");
                }

                // leaving only first audio track
                while (targetMovie.AudioTracks.Count > 1)
                {
                    TrackInfo lastAudioTrack = null;
                    foreach (var track in targetMovie.Tracks)
                    {
                        if (track.TrackType == "Audio")
                        {
                            lastAudioTrack = track;
                        }
                    }
                    if (targetMovie.Tracks.Contains(lastAudioTrack))
                    {
                        targetMovie.Tracks.Remove(lastAudioTrack);
                    }
                    else
                    {
                        break;
                    }
                }

                if (targetMovie.AudioTracks.Count > 0)
                {
                    if (firstVideoTrack != null)
                    {
                        targetMovie.FirstAudioTrack.TargetAudioCodec = MediaConvertGUIConfiguration.GetAudioCodecByName("copy");
                    }
                    else
                    {
                        targetMovie.FirstAudioTrack.TargetAudioCodec = MediaConvertGUIConfiguration.GetAudioCodecByName("mp3");
                    }
                }

                MoviesInfo.Add(sourceMovie, targetMovie);

                FillTree();
            }
        }
    }