Esempio n. 1
0
        public static void IntroVideoss(string VideoFile)
        {
            // this.FileName = VideoFile;

            var inputFile = new MediaFile { Filename = VideoFile };
            var outputFile = new MediaFile {Filename = @"Z:\ddd.mp4"};
            var inputFiles = new MediaToolkit.Options.ConversionOptions();

            var engine = new MediaToolkit.Engine();

            TimeSpan t = new TimeSpan(0, 0, 2, 10, 49);
            TimeSpan d = new TimeSpan(0, 0, inputFile.Metadata.Duration.Minutes, inputFile.Metadata.Duration.Seconds, inputFile.Metadata.Duration.Milliseconds);
            d = inputFile.Metadata.Duration;
             d = d - t;

             inputFiles.CutMedia (t, d);
             engine.Convert(inputFile, outputFile, inputFiles);
        }
Esempio n. 2
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            var options = new MediaToolkit.Options.ConversionOptions();
            var inputFiled = new MediaFile { Filename = VideoToTrim };
            var outputFile = new MediaFile { Filename = VideoToTrimTo };

            string video2trim = "\"" + VideoToTrim + "\"";
            string video2trim2 = "\"" + VideoToTrimTo + "\"";
            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFiled);
                options.CutMedia(Start, End);
                //fade=in:0:30
                engine.ConvertProgressEvent += ConvertProgressEvent;
                engine.ConversionCompleteEvent += engine_ConversionCompleteEvent;
                engine.Convert(inputFiled, outputFile, options);

                //ffmpeg -i input.mp4 -filter:v 'fade=in:0:50' \ -c:v libx264 -crf 22 -preset veryfast -c:a copy output.mp4
                //engine.CustomCommand("-ss " + Start + " -t " + End + " -i " + video2trim + " " + "\"" + " fade=in:0:03" + "\"" +  " " + video2trim2);
                //engine.CustomCommand("-ss " + Start + " -t " + End + " -i" + " " + video2trim + " -filter:v" + " fade=in=0:130 " + "-c:v libx264 -crf 22 -preset veryfast -c:a copy " + video2trim2);
                //std trim
               // string startTime = Start.Hours + ":" + Start.m
                //engine.CustomCommand("-ss " + Start. + " -t " + End + " -i " + video2trim + " -acodec copy -vcodec copy " + video2trim2);
            }
        }
        private static void TrimFileToNewDuration(string inputFilePath, decimal newDurationInMilliseconds, TrailerClipperOptions clipperOptions)
        {
            var outputFilePath = ComputeOutputFilePath(inputFilePath, clipperOptions.OutputDirectoryPath);

            var inputFile = new MediaFile {Filename = inputFilePath};

            var outputFile = new MediaFile {Filename = outputFilePath};

            var options = InitializeClippingData(newDurationInMilliseconds, clipperOptions);

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);

                engine.Convert(inputFile, outputFile, options);
            }

            if (clipperOptions.OutputToConsole)
                Console.WriteLine("Finished on trimming file, output: " + outputFilePath);
        }
Esempio n. 4
0
        private void downloadTheme(string[] manifest)
        {
            try
            {
                string[] fileMetaData = manifest.Skip(1).ToArray();
                BaseUpdateRegion updateRegion = BaseUpdateRegion.GetUpdateRegion(Client.UpdateRegion);

                if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "themes")))
                    Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "themes"));

                foreach (string s in fileMetaData)
                {
                    if (string.IsNullOrEmpty(s))
                        continue;

                    string location = s.Split(',')[0];
                    string savePlace = location.Split(new[] { "/files/" }, StringSplitOptions.None)[1];
                    if (savePlace.Contains("theme.properties"))
                    {
                        using (var newClient = new WebClient())
                        {
                            LogTextBox("Checking Theme...");
                            newClient.DownloadFile(updateRegion.BaseLink + location,
                                Path.Combine(Client.ExecutingDirectory, "Assets", "themes", "theme.properties"));
                        }
                    }
                }

                if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "themes", "theme.properties")))
                    return;

                string[] file =
                    File.ReadAllLines(Path.Combine(Client.ExecutingDirectory, "Assets", "themes", "theme.properties"));
                string theme = "";

                foreach (string s in file)
                    if (s.StartsWith("themeConfig="))
                        theme = s.Split('=')[1].Split(',')[0];

                if (theme == "")
                    return;

                if (!Directory.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "themes", theme)))
                    Directory.CreateDirectory(Path.Combine(Client.ExecutingDirectory, "Assets", "themes", theme));
                else
                {
                    Client.Theme = theme;
                    return;
                }

                List<string> themeLink = fileMetaData.Where(
                                   line => (line.Contains("loop") || line.Contains("Loop")) &&
                                       line.Contains(theme)).ToList(); //loop is exacly the same as intro
                themeLink = themeLink.Select(link => link.Split(',')[0]).ToList();

                using (var newClient = new WebClient())
                {
                    foreach (var item in themeLink)
                    {
                        string fileName = item.Split('/').Last();
                        LogTextBox("Downloading " + fileName + " from http://l3cdn.riotgames.com");
                        newClient.DownloadFile(updateRegion.BaseLink + item,
                            Path.Combine(Client.ExecutingDirectory, "Assets", "themes", theme, fileName));

                    }
                }
                string[] flv = Directory.GetFiles(
                    Path.Combine(Client.ExecutingDirectory, "Assets", "themes", theme), "*.flv");

                foreach(var item in flv)
                {
                    var inputFile = new MediaFile { Filename = 
                        Path.Combine(Client.ExecutingDirectory, "Assets", "themes", theme, item) };
                    var outputFile = new MediaFile { Filename = 
                        Path.Combine(Client.ExecutingDirectory, "Assets", "themes", theme, item).Replace(".flv", ".mp4") };

                    using (var engine = new Engine())
                    {
                        engine.Convert(inputFile, outputFile);
                    }

                }
                Client.Theme = theme;
            }
            catch
            {
            }
        }
        private async Task DownloadTheme(PatcherFile[] files)
        {
            try
            {
                if (!Directory.Exists(GetAssetsDirectory("themes")))
                    Directory.CreateDirectory(GetAssetsDirectory("themes"));

                using (var wc = new WebClient())
                {
                    LogTextBox("Updating Theme");
                    await wc.DownloadFileTaskAsync(files.First(f => f.RelativePath.Contains("theme.properties")).AbsolutePath, GetAssetsDirectory("themes", "theme.properties"));
                }

                if (!File.Exists(GetAssetsDirectory("themes", "theme.properties")))
                    throw new Exception("Downloading of the file \"theme.properties\" failed");

                var theme = File.ReadAllLines(GetAssetsDirectory("themes", "theme.properties")).First(s => s.StartsWith("themeConfig=")).Split('=')[1].Split(',')[0];
                if (theme == "")
                    return;

                if (!Directory.Exists(GetAssetsDirectory("themes", theme)))
                    Directory.CreateDirectory(GetAssetsDirectory("themes", theme));
                else if (Directory.GetFiles(GetAssetsDirectory("themes", theme)).Any())
                {
                    Client.Theme = theme;
                    return;
                }

                var themePatcherFiles = files.Where(l => l.RelativePath.ToLower().Contains("loop") && l.RelativePath.Contains(theme)).ToList();
                Parallel.ForEach(themePatcherFiles,
                    new ParallelOptions {MaxDegreeOfParallelism = 10},
                    file =>
                    {
                        LogTextBox(String.Format("Downloading {0} ({1} KB) from http://l3cdn.riotgames.com", Path.GetFileName(file.RelativePath), file.FileSize/1024));
                        var fname = Path.GetFileName(file.RelativePath);
                        var localPath = GetAssetsDirectory("themes", theme, fname);
                        new WebClient().DownloadFile(file.AbsolutePath, localPath);
                    });

                var flv = Directory.GetFiles(GetAssetsDirectory("themes", theme), "*.flv");

                foreach (var item in flv)
                {
                    var inputFile = new MediaFile {Filename = GetAssetsDirectory("themes", theme, item)};

                    var outputFile = new MediaFile {Filename = GetAssetsDirectory("themes", theme, item).Replace(".flv", ".mp4")};

                    LogTextBox(String.Format("Converting {0}", Path.GetFileName(item)));
                    await Task.Run(() =>
                    {
                        using (var engine = new Engine())
                            engine.Convert(inputFile, outputFile);
                    });
                }
                Client.Theme = theme;
            }
            catch (Exception ex)
            {
                Client.Log(ex);
            }
        }
Esempio n. 6
0
        protected virtual void Convert(String inputFilepath,String outputFolder, ConversionOptions conversionOptions, bool convertToAudio)
        {
            if(String.IsNullOrWhiteSpace(FileName))
                FileName = Path.GetFileNameWithoutExtension(inputFilepath) + GetFormat(true);

            string outputFilePath = Path.Combine(outputFolder, FileName);
            MediaFile inputFile = new MediaFile(@inputFilepath);
            MediaFile outputFile = new MediaFile(outputFilePath);
            using (var engine = new Engine())
            {
                if (processStartingEventHandler != null)
                    processStartingEventHandler(this, EventArgs.Empty);
                engine.Convert(inputFile, outputFile);
                if (processCompletionEventHandler != null)
                    processCompletionEventHandler(this, EventArgs.Empty);

            }
        }
        private async Task ExtractAudio(string path) {
            var cache = new FileInfo(context.audioSaveableFilename); //target cache
            var SavePath = context.audioSaveableFilename;//to universal string
            for (int i = 1; File.Exists(SavePath); i++) {
                SavePath = Path.Combine(cache.Directory.FullName, $"{cache.Name.Replace(cache.Extension,"")} ({i}){cache.Extension}");
            }
            context.AudioPath = new FileInfo(SavePath);
            switch (context.VideoInfo.VideoType) {
                case VideoType.Mobile:
                    break;
                case VideoType.Flash:
                    using (var flvFile = new FlvFile(path, SavePath)) {
                        flvFile.ConversionProgressChanged += (sender, args) => {
                            context.OnProgresStateChanged(YoutubeStage.ExtractingAudio, args.ProgressPercentage);
                        };

                        await Task.Run(()=>flvFile.ExtractStreams());
                    }
                    break;
                case VideoType.Mp4:
                    var @in = new MediaFile(path);
                    var @out = new MediaFile(SavePath);
                    using (var engine = new Engine()) {
                        //Desperate attempt to catch the extraction from the MediaToolkit lib but it simply does not pass into those events.
                        //engine.ConvertProgressEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //engine.ConversionCompleteEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //informing on 0% and 100%, btw those conversions are pretty fast, 5 to 10 seconds for a 50MB 1048p video.
                        context.OnProgresStateChanged(YoutubeStage.StartingAudioExtraction);
                        await Task.Run(()=>engine.Convert(@in, @out)); //begin conversion progress. it is executed serially.
                        context.OnProgresStateChanged(YoutubeStage.FinishedAudioExtraction);
                    }
                    break;
                case VideoType.WebM:
                    break;
                case VideoType.Unknown:
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
        private async Task ExtractAudio(string path) {
            var cache = new FileInfo(context.AudioPath?.FullName ?? context.AudioSaveableFilename); //target cache
            var SavePath = context.AudioPath?.FullName ?? context.AudioSaveableFilename;//to universal string
            for (int i = 1; File.Exists(SavePath); i++) {
                SavePath = Path.Combine(cache.Directory.FullName, $"{cache.Name.Replace(cache.Extension,"")} ({i}){cache.Extension}");
            }
            SavePath = Path.ChangeExtension(SavePath, "aac");
            context.OnProgresStateChanged(YoutubeStage.StartingAudioExtraction);
            switch (context.VideoInfo.VideoType) {
                case VideoType.Mobile:
                    //no one is really going to use this..
                    break;
                case VideoType.Flash: {
                    using (var flvFile = new FlvFile(path, SavePath)) {
                        flvFile.ConversionProgressChanged += (sender, args) => {
                            context.OnProgresStateChanged(YoutubeStage.ExtractingAudio, args.ProgressPercentage);
                        };

                        await Task.Run(() => flvFile.ExtractStreams());
                    }
                    break;
                }
                case VideoType.Mp4: {
                    var @in = new MediaFile(new FileInfo(path).FullName);
                    var @out = new MediaFile(new FileInfo(SavePath).FullName);
                    using (var engine = new Engine()) {
                        //Desperate attempt to catch the extraction from the MediaToolkit lib but it simply does not pass into those events.
                        //engine.ConvertProgressEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //engine.ConversionCompleteEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //informing on 0% and 100%, btw those conversions are pretty fast, 5 to 10 seconds for a 50MB 1048p video.
                        await Task.Run(()=> engine.CustomCommand($"-i \"{@in.Filename.Replace("\\", "/")}\" -vn -acodec copy \"{@out.Filename.Replace("\\", "/")}\"")); //begin conversion progress. it is executed serially.
                    }
                    break;
                }
                case VideoType.WebM:
                    //the mkv files do not contain any audio files.
                    break;
                case VideoType.Unknown:
                    switch (context.VideoInfo?.AudioType ?? AudioType.None) {
                        case AudioType.Unknown:
                            break;
                        case AudioType.Aac:
                            File.Move(path, SavePath);
                            break;
                        case AudioType.Mp3:
                            SavePath = Path.ChangeExtension(SavePath, "mp3");
                            File.Move(path, SavePath);
                            break;
                        case AudioType.Vorbis: {
                            var @in = new MediaFile(new FileInfo(path).FullName);
                            var @out = new MediaFile(new FileInfo(SavePath).FullName);
                            using (var engine = new Engine()) {
                                await Task.Run(() => engine.Convert(@in, @out));
                            }
                            break;
                        }
                        case AudioType.Opus: {
                            var @in = new MediaFile(new FileInfo(path).FullName);
                            var @out = new MediaFile(new FileInfo(SavePath).FullName);
                            using (var engine = new Engine()) {
                                await Task.Run(()=> engine.CustomCommand($"-i {@in.Filename.Replace("\\","/")} -c:a libvo_aacenc -b:a 192k  {@out.Filename.Replace("\\","/")}"));
                            }
                            break;
                        }
                        default:
                            break;
                    }
                    break;
                default:
                    SavePath = Path.ChangeExtension(SavePath, cache.Extension.Replace(".",""));
                    File.Move(path, SavePath);
                    break;
            }
            context.OnProgresStateChanged(YoutubeStage.FinishedAudioExtraction);
            context.AudioPath = new FileInfo(SavePath);
        }
Esempio n. 9
-1
        public IEnumerable<MediaSegment> Segment(FileInfo file, long fileId)
        {
            var source = new MediaFile(file.FullName);
            using (var engine = new Engine())
            {
                engine.GetMetadata(source);
                var progressMs = 0.0;
                while (progressMs < source.Metadata.Duration.TotalMilliseconds)
                {
                    var options = new ConversionOptions();
                    var endMs = Math.Min(progressMs + _segmentLengthMs, source.Metadata.Duration.TotalMilliseconds);

                    options.CutMedia(TimeSpan.FromMilliseconds(progressMs),
                        TimeSpan.FromMilliseconds(endMs));

                    var outputFile = Path.Combine(file.DirectoryName,
                        string.Format("{0}_audio_{1}ms.wav", file.Name, progressMs));

                    engine.Convert(source, new MediaFile(outputFile), options);
                    yield return new MediaSegment
                    {
                        FileId = fileId,
                        File = new FileInfo(outputFile),
                        OffsetMs = progressMs,
                        DurationMs = endMs - progressMs
                    };
                    progressMs = endMs;
                }
            }
        }