Exemple #1
0
        private void ExtractFFMpeg(FFMpegInstallInfo downloadinfo, string tempFile, string targetFolder)
        {
            _logger.Info("Extracting ffmpeg from {0}", tempFile);

            var tempFolder = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());

            _fileSystem.CreateDirectory(tempFolder);

            try
            {
                ExtractArchive(downloadinfo, tempFile, tempFolder);

                var files = Directory.EnumerateFiles(tempFolder, "*", SearchOption.AllDirectories)
                            .ToList();

                foreach (var file in files.Where(i =>
                {
                    var filename = Path.GetFileName(i);

                    return
                    (string.Equals(filename, downloadinfo.FFProbeFilename, StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(filename, downloadinfo.FFMpegFilename, StringComparison.OrdinalIgnoreCase));
                }))
                {
                    var targetFile = Path.Combine(targetFolder, Path.GetFileName(file));
                    _fileSystem.CopyFile(file, targetFile, true);
                    SetFilePermissions(targetFile);
                }
            }
            finally
            {
                DeleteFile(tempFile);
            }
        }
Exemple #2
0
        private async Task <bool> DownloadFFMpeg(FFMpegInstallInfo downloadinfo, string directory, IProgress <double> progress)
        {
            foreach (var url in downloadinfo.DownloadUrls)
            {
                progress.Report(0);

                try
                {
                    var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = CancellationToken.None,
                        Progress          = progress
                    }).ConfigureAwait(false);

                    ExtractFFMpeg(downloadinfo, tempFile, directory);
                    return(true);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
            }
            return(false);
        }
Exemple #3
0
 public FFMpegLoader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment, FFMpegInstallInfo ffmpegInstallInfo)
 {
     _logger            = logger;
     _appPaths          = appPaths;
     _httpClient        = httpClient;
     _zipClient         = zipClient;
     _fileSystem        = fileSystem;
     _environment       = environment;
     _ffmpegInstallInfo = ffmpegInstallInfo;
 }
Exemple #4
0
 public FFMpegLoader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment, FFMpegInstallInfo ffmpegInstallInfo)
 {
     _logger = logger;
     _appPaths = appPaths;
     _httpClient = httpClient;
     _zipClient = zipClient;
     _fileSystem = fileSystem;
     _environment = environment;
     _ffmpegInstallInfo = ffmpegInstallInfo;
 }
Exemple #5
0
 private async void DownloadFFMpegInBackground(FFMpegInstallInfo downloadinfo, string directory)
 {
     try
     {
         await DownloadFFMpeg(downloadinfo, directory, new Progress <double>()).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         _logger.ErrorException("Error downloading ffmpeg", ex);
     }
 }
Exemple #6
0
        private void ExtractArchive(FFMpegInstallInfo downloadinfo, string archivePath, string targetPath)
        {
            _logger.Info("Extracting {0} to {1}", archivePath, targetPath);

            if (string.Equals(downloadinfo.ArchiveType, "7z", StringComparison.OrdinalIgnoreCase))
            {
                _zipClient.ExtractAllFrom7z(archivePath, targetPath, true);
            }
            else if (string.Equals(downloadinfo.ArchiveType, "gz", StringComparison.OrdinalIgnoreCase))
            {
                _zipClient.ExtractAllFromTar(archivePath, targetPath, true);
            }
        }
Exemple #7
0
        private async Task DownloadFFMpeg(FFMpegInstallInfo downloadinfo, string directory, IProgress <double> progress)
        {
            if (downloadinfo.IsEmbedded)
            {
                var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());
                _fileSystem.CreateDirectory(Path.GetDirectoryName(tempFile));

                using (var stream = _ownerAssembly.GetManifestResourceStream(downloadinfo.DownloadUrls[0]))
                {
                    using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true))
                    {
                        await stream.CopyToAsync(fs).ConfigureAwait(false);
                    }
                }
                ExtractFFMpeg(downloadinfo, tempFile, directory);
                return;
            }

            foreach (var url in downloadinfo.DownloadUrls)
            {
                progress.Report(0);

                try
                {
                    var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = CancellationToken.None,
                        Progress          = progress
                    }).ConfigureAwait(false);

                    ExtractFFMpeg(downloadinfo, tempFile, directory);
                    return;
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
            }

            if (downloadinfo.DownloadUrls.Length == 0)
            {
                throw new ApplicationException("ffmpeg unvailable. Please install it and start the server with two command line arguments: -ffmpeg \"{PATH}\" and -ffprobe \"{PATH}\"");
            }

            throw new ApplicationException("Unable to download required components. Please try again later.");
        }
Exemple #8
0
        public static FFMpegInstallInfo GetInfo(NativeEnvironment environment)
        {
            var info = new FFMpegInstallInfo();

            // Windows builds: http://ffmpeg.zeranoe.com/builds/
            // Linux builds: http://johnvansickle.com/ffmpeg/
            // OS X builds: http://ffmpegmac.net/
            // OS X x64: http://www.evermeet.cx/ffmpeg/

            switch (environment.OperatingSystem)
            {
                case OperatingSystem.Osx:
                case OperatingSystem.Bsd:
                    break;
                case OperatingSystem.Linux:

                    info.ArchiveType = "7z";
                    info.Version = "20160215";
                    break;
            }

            info.DownloadUrls = GetDownloadUrls(environment);

            return info;
        }
Exemple #9
0
        public static FFMpegInstallInfo GetInfo(NativeEnvironment environment)
        {
            var info = new FFMpegInstallInfo();

            info.ArchiveType = "7z";

            switch (environment.SystemArchitecture)
            {
                case Architecture.X86_X64:
                    info.Version = "20160124";
                    break;
                case Architecture.X86:
                    info.Version = "20150110";
                    break;
            }

            info.DownloadUrls = GetDownloadUrls(environment);

            return info;
        }
Exemple #10
0
        private void ExtractArchive(FFMpegInstallInfo downloadinfo, string archivePath, string targetPath)
        {
            _logger.Info("Extracting {0} to {1}", archivePath, targetPath);

            if (string.Equals(downloadinfo.ArchiveType, "7z", StringComparison.OrdinalIgnoreCase))
            {
                _zipClient.ExtractAllFrom7z(archivePath, targetPath, true);
            }
            else if (string.Equals(downloadinfo.ArchiveType, "gz", StringComparison.OrdinalIgnoreCase))
            {
                _zipClient.ExtractAllFromTar(archivePath, targetPath, true);
            }
        }
Exemple #11
0
        private void ExtractFFMpeg(FFMpegInstallInfo downloadinfo, string tempFile, string targetFolder)
        {
            _logger.Info("Extracting ffmpeg from {0}", tempFile);

            var tempFolder = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());

            _fileSystem.CreateDirectory(tempFolder);

            try
            {
                ExtractArchive(downloadinfo, tempFile, tempFolder);

                var files = Directory.EnumerateFiles(tempFolder, "*", SearchOption.AllDirectories)
                    .ToList();

                foreach (var file in files.Where(i =>
                    {
                        var filename = Path.GetFileName(i);

                        return
                            string.Equals(filename, downloadinfo.FFProbeFilename, StringComparison.OrdinalIgnoreCase) ||
                            string.Equals(filename, downloadinfo.FFMpegFilename, StringComparison.OrdinalIgnoreCase);
                    }))
                {
                    var targetFile = Path.Combine(targetFolder, Path.GetFileName(file));
                    _fileSystem.CopyFile(file, targetFile, true);
                    SetFilePermissions(targetFile);
                }
            }
            finally
            {
                DeleteFile(tempFile);
            }
        }
Exemple #12
0
        private async Task DownloadFFMpeg(FFMpegInstallInfo downloadinfo, string directory, IProgress<double> progress)
        {
            if (downloadinfo.IsEmbedded)
            {
                var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());
                _fileSystem.CreateDirectory(Path.GetDirectoryName(tempFile));

                using (var stream = _ownerAssembly.GetManifestResourceStream(downloadinfo.DownloadUrls[0]))
                {
                    using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true))
                    {
                        await stream.CopyToAsync(fs).ConfigureAwait(false);
                    }
                }
                ExtractFFMpeg(downloadinfo, tempFile, directory);
                return;
            }

            foreach (var url in downloadinfo.DownloadUrls)
            {
                progress.Report(0);

                try
                {
                    var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = CancellationToken.None,
                        Progress = progress

                    }).ConfigureAwait(false);

                    ExtractFFMpeg(downloadinfo, tempFile, directory);
                    return;
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
            }

            if (downloadinfo.DownloadUrls.Length == 0)
            {
                throw new ApplicationException("ffmpeg unvailable. Please install it and start the server with two command line arguments: -ffmpeg \"{PATH}\" and -ffprobe \"{PATH}\"");
            }

            throw new ApplicationException("Unable to download required components. Please try again later.");
        }
Exemple #13
0
 private async void DownloadFFMpegInBackground(FFMpegInstallInfo downloadinfo, string directory)
 {
     try
     {
         await DownloadFFMpeg(downloadinfo, directory, new Progress<double>()).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         _logger.ErrorException("Error downloading ffmpeg", ex);
     }
 }
Exemple #14
0
        public FFMpegInstallInfo GetFfmpegInstallInfo()
        {
            var info = new FFMpegInstallInfo();

            info.FFMpegFilename = "ffmpeg.exe";
            info.FFProbeFilename = "ffprobe.exe";
            info.Version = "0";

            return info;
        }
Exemple #15
0
        private async Task<bool> DownloadFFMpeg(FFMpegInstallInfo downloadinfo, string directory, IProgress<double> progress)
        {
            foreach (var url in downloadinfo.DownloadUrls)
            {
                progress.Report(0);

                try
                {
                    var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = CancellationToken.None,
                        Progress = progress

                    }).ConfigureAwait(false);

                    ExtractFFMpeg(downloadinfo, tempFile, directory);
                    return true;
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
            }
            return false;
        }
Exemple #16
0
        public FFMpegInstallInfo GetFfmpegInstallInfo()
        {
            var info = new FFMpegInstallInfo();

            info.FFMpegFilename = "ffmpeg.exe";
            info.FFProbeFilename = "ffprobe.exe";
            info.Version = "20160410";
            info.ArchiveType = "7z";
            info.IsEmbedded = false;
            info.DownloadUrls = GetDownloadUrls();

            return info;
        }