浏览代码

Extract ffmpeg during init

LukePulverenti Luke Pulverenti luke pulverenti 13 年之前
父节点
当前提交
19a4dd83c2
共有 2 个文件被更改,包括 39 次插入38 次删除
  1. 2 37
      MediaBrowser.Controller/Configuration/ServerApplicationPaths.cs
  2. 37 1
      MediaBrowser.Controller/Kernel.cs

+ 2 - 37
MediaBrowser.Controller/Configuration/ServerApplicationPaths.cs

@@ -1,5 +1,4 @@
 using System.IO;
-using System.Reflection;
 using MediaBrowser.Common.Configuration;
 
 namespace MediaBrowser.Controller.Configuration
@@ -227,24 +226,7 @@ namespace MediaBrowser.Controller.Configuration
             {
                 if (_FFMpegPath == null)
                 {
-                    string filename = "ffmpeg.exe";
-
-                    _FFMpegPath = Path.Combine(FFMpegDirectory, filename);
-
-                    // Always re-extract the first time to handle new versions
-                    if (File.Exists(_FFMpegPath))
-                    {
-                        File.Delete(_FFMpegPath);
-                    }
-
-                    // Extract exe
-                    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Controller.FFMpeg." + filename))
-                    {
-                        using (FileStream fileStream = new FileStream(_FFMpegPath, FileMode.Create))
-                        {
-                            stream.CopyTo(fileStream);
-                        }
-                    }
+                    _FFMpegPath = Path.Combine(FFMpegDirectory, "ffmpeg.exe");
                 }
 
                 return _FFMpegPath;
@@ -261,24 +243,7 @@ namespace MediaBrowser.Controller.Configuration
             {
                 if (_FFProbePath == null)
                 {
-                    string filename = "ffprobe.exe";
-
-                    _FFProbePath = Path.Combine(FFMpegDirectory, filename);
-
-                    /*// Always re-extract the first time to handle new versions
-                    if (File.Exists(_FFProbePath))
-                    {
-                        File.Delete(_FFProbePath);
-                    }
-
-                    // Extract exe
-                    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Controller.FFMpeg." + filename))
-                    {
-                        using (FileStream fileStream = new FileStream(_FFProbePath, FileMode.Create))
-                        {
-                            stream.CopyTo(fileStream);
-                        }
-                    }*/
+                    _FFProbePath = Path.Combine(FFMpegDirectory, "ffprobe.exe");
                 }
 
                 return _FFProbePath;

+ 37 - 1
MediaBrowser.Controller/Kernel.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.ComponentModel.Composition;
 using System.IO;
 using System.Linq;
+using System.Reflection;
 using System.Security.Cryptography;
 using System.Text;
 using System.Threading.Tasks;
@@ -73,7 +74,10 @@ namespace MediaBrowser.Controller
                 progress.Report(new TaskProgress() { Description = "Loading Users", PercentComplete = 15 });
                 ReloadUsers();
 
-                progress.Report(new TaskProgress() { Description = "Loading Media Library", PercentComplete = 20 });
+                progress.Report(new TaskProgress() { Description = "Extracting FFMpeg", PercentComplete = 20 });
+                await ExtractFFMpeg();
+
+                progress.Report(new TaskProgress() { Description = "Loading Media Library", PercentComplete = 25 });
                 await ReloadRoot();
 
                 progress.Report(new TaskProgress() { Description = "Loading Complete", PercentComplete = 100 });
@@ -252,8 +256,12 @@ namespace MediaBrowser.Controller
             return list;
         }
 
+        /// <summary>
+        /// Runs all metadata providers for an entity
+        /// </summary>
         internal async Task ExecuteMetadataProviders(BaseEntity item, ItemResolveEventArgs args)
         {
+            // Get all supported providers
             var supportedProviders = Kernel.Instance.MetadataProviders.Where(i => i.Supports(item));
 
             // Start with non-internet providers. Run them sequentially
@@ -273,6 +281,34 @@ namespace MediaBrowser.Controller
             }
         }
 
+        /// <summary>
+        /// Run these during Init.
+        /// Can't run do this on-demand because there will be multiple workers accessing them at once and we'd have to lock them
+        /// </summary>
+        private async Task ExtractFFMpeg()
+        {
+            // FFMpeg.exe
+            await ExtractFFMpeg(ApplicationPaths.FFMpegPath);
+            await ExtractFFMpeg(ApplicationPaths.FFProbePath);
+        }
+
+        private async Task ExtractFFMpeg(string exe)
+        {
+            if (File.Exists(exe))
+            {
+                File.Delete(exe);
+            }
+
+            // Extract exe
+            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Controller.FFMpeg." + Path.GetFileName(exe)))
+            {
+                using (FileStream fileStream = new FileStream(exe, FileMode.Create))
+                {
+                    await stream.CopyToAsync(fileStream);
+                }
+            }
+        }
+
         protected override void DisposeComposableParts()
         {
             base.DisposeComposableParts();