コード例 #1
0
 public void Dispose()
 {
     if (!_converter.Stop())
     {
         _converter.Abort();
     }
 }
コード例 #2
0
ファイル: Music.cs プロジェクト: GreatArcStudios/Equator
 private static async Task ConvertTask(FFMpegConverter ffMpegConverter, string inputFilePath, string saveName)
 {
     ffMpegConverter.Convertmedia(inputFilePath, Path.Combine(FilePaths.SaveLocation(),
                                                              FilePaths.RemoveIllegalPathCharacters(saveName)), Format.mp4);
     ffMpegConverter.Stop();
     isConverting = false;
 }
コード例 #3
0
        private void AbortConverter()
        {
            if (!_converter.Stop())
            {
                _converter.Abort();
            }

            _converter.Dispose();
        }
コード例 #4
0
        static async Task MainAsync(string[] args)
        {
            string dir    = "envivio";
            string mpdUrl = "http://10.5.5.7/q/p/userapi/streams/32/mpd";
            //"http://10.5.7.207/userapi/streams/30/mpd";
            //"http://10.5.7.207/userapi/streams/11/mpd?start_time=1458816642&stop_time=1458819642";
            //"http://dash.edgesuite.net/envivio/EnvivioDash3/manifest.mpd";
            //"http://dash.edgesuite.net/dash264/TestCases/1a/netflix/exMPD_BIP_TC1.mpd";
            var stopwatch = Stopwatch.StartNew();

            var downloader          = new MpdDownloader(new Uri(mpdUrl), dir);
            var trackRepresentation = downloader.GetTracksFor(TrackContentType.Video).First().TrackRepresentations.OrderByDescending(r => r.Bandwidth).First();
            var prepareTime         = stopwatch.Elapsed;

            var chunks =
                //Directory.GetFiles(@"C:\Users\Alexander\Work\Github\qoollo\SharpDashTools\DashTools.Samples\bin\Debug\envivio", "*.mp4")
                //.Select(f => Path.GetFileName(f) == "make_chunk_path_longer_32.mp4"
                //    ? new Mp4InitFile(Path.Combine("envivio", Path.GetFileName(f)))
                //    : new Mp4File(Path.Combine("envivio", Path.GetFileName(f))))
                //    .ToArray();
                await downloader.Download(trackRepresentation, TimeSpan.FromMinutes(60), TimeSpan.FromMinutes(60 + 60 * 6 / 6));

            var downloadTime = stopwatch.Elapsed - prepareTime;

            var ffmpeg = new FFMpegConverter();

            ffmpeg.LogReceived += (s, e) => Console.WriteLine(e.Data);
            var combined = downloader.CombineChunksFast(chunks, s => ffmpeg.Invoke(s));
            //downloader.CombineChunks(chunks, s => ffmpeg.Invoke(s));
            var combineTime = stopwatch.Elapsed - prepareTime - downloadTime;

            if (!ffmpeg.Stop())
            {
                ffmpeg.Abort();
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("================================================================");
            Console.WriteLine("Prepared in {0} s", prepareTime.TotalSeconds);
            Console.WriteLine("Downloaded {0} chunks in {1} s", chunks.Count(), downloadTime.TotalSeconds);
            Console.WriteLine("Combined in {0} s", combineTime.TotalSeconds);
            Console.WriteLine("Total: {0} s", (prepareTime + downloadTime + combineTime).TotalSeconds);
            Console.ReadLine();

            return;

            string mpdFilePath = //@"C:\Users\Alexander\AppData\Local\Temp\note_5_video_5_source_2-index_00000\manifest.mpd";
                                 await DownloadMpdStreams(mpdUrl, dir);

            await ConcatStreams(mpdFilePath, Path.Combine(Path.GetDirectoryName(mpdFilePath), "output.mp4"));
        }
コード例 #5
0
        /// <summary> Загрузка изображения из середины видео по пути к файлу. </summary>
        public static BitmapImage LoadBitMapFromVideo(string path, int vidWidth, float vidPos)
        {
            BitmapImage coverImage = new BitmapImage();

            if (string.IsNullOrWhiteSpace(path))
            {
                return(coverImage);
            }
            FileInfo fi = new FileInfo(path);

            if (!fi.Exists)
            {
                return(coverImage);
            }

            using (MemoryStream memory = new MemoryStream()) {
                try {
                    FFMpegConverter ffMpeg = new FFMpegConverter();
                    if (App.FoundFFMpegLibs)
                    {
                        ffMpeg.FFMpegToolPath = Properties.Settings.Default.FFMpegBinPath;
                    }

                    var imgWidth = Properties.Settings.Default.CoverMaxSize;
                    if (vidWidth < imgWidth)
                    {
                        imgWidth = vidWidth;                                            // формируем кавер размером с видео для экономии
                    }
                    ffMpeg.GetVideoThumbnail(path, memory, vidPos);
                    memory.Position = 0;

                    try {
                        coverImage = new BitmapImage();
                        coverImage.BeginInit();
                        coverImage.StreamSource     = memory;
                        coverImage.CacheOption      = BitmapCacheOption.OnLoad;
                        coverImage.DecodePixelWidth = imgWidth;
                        coverImage.EndInit();
                        coverImage.StreamSource = null;
                    } catch (NotSupportedException ex2) {
                        Console.WriteLine(ex2);
                        coverImage = new BitmapImage();
                    }

                    memory.Close();
                    memory.Dispose();
                    ffMpeg.Stop();
                } catch (FFMpegException ex) {
                    Console.WriteLine(ex);
                } catch (IOException ex3) {
                    Console.WriteLine(ex3);
                } catch (ThreadAbortException ex4) {
                    Console.WriteLine(ex4);
                } catch (Exception ex5) {
                    Console.WriteLine(ex5);
                }
            }

            coverImage.Freeze();                // замораживаем только после избавления от стрима, иначе GC уже не может его ликвидировать
            return(coverImage);
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: Briangta/MkvToMp4
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     conv.Abort();
     conv.Stop();
 }
コード例 #7
0
 /// <inheritdoc />
 public void Stop()
 {
     _convertor.Stop();
     IsStarted = false;
 }
コード例 #8
-1
        /// <summary>
        /// Run Convert Worker
        /// </summary>
        /// <param name="inputPath">Input file path</param>
        /// <param name="outputPath">Output file path</param>
        /// <param name="format">Video file format</param>
        /// <param name="arguments">Arguments for ffmpeg</param>
        /// <param name="passNumber">Pass number</param>
        private void RunConvertWorker(string inputPath, string outputPath, string format, string[] arguments, int passNumber)
        {
            int passCount = arguments.Length;
            if (passNumber > passCount - 1) return;

            string currentPassArguments = arguments[passNumber];
            string currentOutputPath = outputPath;
            string toolTipText = "Выполняется конвертирование";

            if (passCount > 1)
            {
                toolTipText = string.Format("Выполняется проход {0} из {1}", (passNumber + 1), passCount);
                if (passNumber < (passCount - 1))
                    currentOutputPath = "NUL";
            }

            bw = new BackgroundWorker();
            bw.WorkerSupportsCancellation = true;
            bw.WorkerReportsProgress = true;
            bw.ProgressChanged += new ProgressChangedEventHandler(delegate (object sender, ProgressChangedEventArgs e)
            {
                int progressPercentage = Math.Min(100, e.ProgressPercentage);
                if (progressPercentage > 0)
                {
                    ProgressBarPercentage(progressPercentage);
                }
                showToolTip(toolTipText);
            });
            bw.DoWork += delegate (object sender, DoWorkEventArgs e)
            {
                try
                {
                    FFMpegConverter ffMpeg = new FFMpegConverter();
                    ffMpeg.FFMpegProcessPriority = ProcessPriorityClass.Idle;
                    ffMpeg.FFMpegToolPath = Path.Combine(Environment.CurrentDirectory, "Binaries");

                    ConvertSettings settings = new ConvertSettings();
                    settings.CustomOutputArgs = currentPassArguments;

                    ffMpeg.ConvertProgress += delegate (object sendertwo, ConvertProgressEventArgs etwo)
                    {
                        int perc = (int)((etwo.Processed.TotalMilliseconds / etwo.TotalDuration.TotalMilliseconds) * 100);
                        bw.ReportProgress(perc);
                        if (bw.CancellationPending)
                            ffMpeg.Stop();
                    };

                    ffMpeg.ConvertMedia(inputPath, null, currentOutputPath, format, settings);
                }
                catch (Exception ex)
                {
                    if (!ex.Message.StartsWith("Exiting normally") && !closeApp)
                        MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                    return;
                }
            };
            bw.RunWorkerCompleted += delegate (object sender, RunWorkerCompletedEventArgs e)
            {
                if (e.Cancelled)
                {
                    converting = false;

                    // reset pbar
                    ResetProgressBar();
                    toolStripProgressBar.Visible = false;

                    buttonGo.Text = buttonGoText;
                    buttonGo.Enabled = true;

                    showToolTip("Конвертирование отменено");

                    if (closeApp)
                        Application.Exit();

                    return;
                }

                // run next pass
                if (passCount > 1 && passNumber < (passCount - 1))
                {
                    RunConvertWorker(inputPath, outputPath, format, arguments, passNumber + 1);
                }
                else
                {
                    converting = false;

                    // 100% done!
                    ProgressBarPercentage(100);

                    buttonGo.Text = buttonGoText;
                    buttonGo.Enabled = true;

                    showToolTip("Готово");
                    if (MessageBox.Show("Открыть полученный файл?", "Конвертирование выполнено", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            Process.Start(outputPath);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            };

            ResetProgressBar();
            toolStripProgressBar.Visible = true;

            buttonGo.Text = "Отменить";
            buttonGo.Enabled = true;

            converting = true;
            showToolTip(toolTipText);
            bw.RunWorkerAsync();
        }