update ffmpeg

This commit is contained in:
Luke Pulverenti
2016-04-02 00:16:18 -04:00
parent 504c9e34c0
commit 132766ff15
10 changed files with 80 additions and 44 deletions

View File

@@ -618,7 +618,7 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>Task.</returns>
private async Task RegisterMediaEncoder(IProgress<double> progress)
{
var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment)
var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment, NativeApp.GetType().Assembly)
.GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false);
var mediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"),

View File

@@ -8,6 +8,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
public string FFProbeFilename { get; set; }
public string ArchiveType { get; set; }
public string[] DownloadUrls { get; set; }
public bool IsEmbedded { get; set; }
public FFMpegDownloadInfo()
{
@@ -54,8 +55,9 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
info.FFMpegFilename = "ffmpeg.exe";
info.FFProbeFilename = "ffprobe.exe";
info.Version = "20160131";
info.Version = "20160401";
info.ArchiveType = "7z";
info.IsEmbedded = true;
switch (environment.SystemArchitecture)
{
@@ -81,17 +83,9 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
switch (environment.SystemArchitecture)
{
case Architecture.X86_X64:
return new[]
{
"https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160131-win64.7z",
"http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20151109-git-480bad7-win64-static.7z"
};
return new string[] { "MediaBrowser.ServerApplication.ffmpeg.ffmpegx64.7z" };
case Architecture.X86:
return new[]
{
"https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160131-win32.7z",
"http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20151109-git-480bad7-win32-static.7z"
};
return new string[] { "MediaBrowser.ServerApplication.ffmpeg.ffmpegx86.7z" };
}
break;

View File

@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -23,13 +24,14 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
private readonly IZipClient _zipClient;
private readonly IFileSystem _fileSystem;
private readonly NativeEnvironment _environment;
private Assembly _ownerAssembly;
private readonly string[] _fontUrls =
{
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/ARIALUNI.7z"
};
public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment)
public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment, Assembly ownerAssembly)
{
_logger = logger;
_appPaths = appPaths;
@@ -37,6 +39,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
_zipClient = zipClient;
_fileSystem = fileSystem;
_environment = environment;
_ownerAssembly = ownerAssembly;
}
public async Task<FFMpegInfo> GetFFMpegInfo(NativeEnvironment environment, StartupOptions options, IProgress<double> progress)
@@ -78,11 +81,11 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
Version = version
};
_fileSystem.CreateDirectory(versionedDirectoryPath);
_fileSystem.CreateDirectory(versionedDirectoryPath);
var excludeFromDeletions = new List<string> { versionedDirectoryPath };
if (!_fileSystem.FileExists(info.ProbePath) || !_fileSystem.FileExists(info.EncoderPath))
if (!_fileSystem.FileExists(info.ProbePath) || !_fileSystem.FileExists(info.EncoderPath))
{
// ffmpeg not present. See if there's an older version we can start with
var existingVersion = GetExistingVersion(info, rootEncoderPath);
@@ -106,7 +109,10 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
}
}
await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);
if (_environment.OperatingSystem == OperatingSystem.Windows)
{
await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);
}
DeleteOlderFolders(Path.GetDirectoryName(versionedDirectoryPath), excludeFromDeletions);
@@ -189,6 +195,21 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
private async Task DownloadFFMpeg(FFMpegDownloadInfo 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);
}
foreach (var url in downloadinfo.DownloadUrls)
{
progress.Report(0);
@@ -216,10 +237,8 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
{
throw new ApplicationException("ffmpeg unvailable. Please install it and start the server with two command line arguments: -ffmpeg \"{PATH}\" and -ffprobe \"{PATH}\"");
}
else
{
throw new ApplicationException("Unable to download required components. Please try again later.");
}
throw new ApplicationException("Unable to download required components. Please try again later.");
}
private void ExtractFFMpeg(FFMpegDownloadInfo downloadinfo, string tempFile, string targetFolder)
@@ -228,7 +247,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
var tempFolder = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());
_fileSystem.CreateDirectory(tempFolder);
_fileSystem.CreateDirectory(tempFolder);
try
{
@@ -247,7 +266,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
}))
{
var targetFile = Path.Combine(targetFolder, Path.GetFileName(file));
_fileSystem.CopyFile(file, targetFile, true);
_fileSystem.CopyFile(file, targetFile, true);
SetFilePermissions(targetFile);
}
}
@@ -311,13 +330,13 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
{
var fontsDirectory = Path.Combine(targetPath, "fonts");
_fileSystem.CreateDirectory(fontsDirectory);
_fileSystem.CreateDirectory(fontsDirectory);
const string fontFilename = "ARIALUNI.TTF";
var fontFile = Path.Combine(fontsDirectory, fontFilename);
if (_fileSystem.FileExists(fontFile))
if (_fileSystem.FileExists(fontFile))
{
await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false);
}
@@ -360,7 +379,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
{
try
{
_fileSystem.CopyFile(existingFile, Path.Combine(fontsDirectory, fontFilename), true);
_fileSystem.CopyFile(existingFile, Path.Combine(fontsDirectory, fontFilename), true);
return;
}
catch (IOException ex)
@@ -422,7 +441,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
const string fontConfigFilename = "fonts.conf";
var fontConfigFile = Path.Combine(fontsDirectory, fontConfigFilename);
if (!_fileSystem.FileExists(fontConfigFile))
if (!_fileSystem.FileExists(fontConfigFile))
{
var contents = string.Format("<?xml version=\"1.0\"?><fontconfig><dir>{0}</dir><alias><family>Arial</family><prefer>Arial Unicode MS</prefer></alias></fontconfig>", fontsDirectory);