diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-06-29 00:06:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-29 00:06:55 -0400 |
| commit | 04de5b15e6fbcee560140c8f1e2ecdd6665e50ee (patch) | |
| tree | 3f30c973d214f62856ad775d0bba7a5ca2508cfb /MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | |
| parent | 8fe7315afab90470833b11db36d426959262ccfb (diff) | |
| parent | db1130166fb11b726bb37ae2ad2f3c9c1b82076a (diff) | |
Merge pull request #1886 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index f8321f6cd..11291a05a 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -112,9 +112,18 @@ namespace MediaBrowser.MediaEncoding.Encoder // If the path was passed in, save it into config now. var encodingOptions = GetEncodingOptions(); var appPath = encodingOptions.EncoderAppPath; - if (!string.IsNullOrWhiteSpace(FFMpegPath) && !string.Equals(FFMpegPath, appPath, StringComparison.Ordinal)) + + var valueToSave = FFMpegPath; + + // if using system variable, don't save this. + if (string.Equals(valueToSave, "ffmpeg", StringComparison.OrdinalIgnoreCase)) + { + valueToSave = null; + } + + if (!string.Equals(valueToSave, appPath, StringComparison.Ordinal)) { - encodingOptions.EncoderAppPath = FFMpegPath; + encodingOptions.EncoderAppPath = valueToSave; ConfigurationManager.SaveConfiguration("encoding", encodingOptions); } } @@ -161,7 +170,12 @@ namespace MediaBrowser.MediaEncoding.Encoder { appPath = Path.Combine(ConfigurationManager.ApplicationPaths.ProgramDataPath, "ffmpeg"); } + var newPaths = GetEncoderPaths(appPath); + if (string.IsNullOrWhiteSpace(newPaths.Item1) || string.IsNullOrWhiteSpace(newPaths.Item2)) + { + newPaths = TestForInstalledVersions(); + } if (!string.IsNullOrWhiteSpace(newPaths.Item1) && !string.IsNullOrWhiteSpace(newPaths.Item2)) { @@ -192,6 +206,52 @@ namespace MediaBrowser.MediaEncoding.Encoder return new Tuple<string, string>(null, null); } + private Tuple<string, string> TestForInstalledVersions() + { + string encoderPath = null; + string probePath = null; + + if (TestSystemInstalled("ffmpeg")) + { + encoderPath = "ffmpeg"; + } + if (TestSystemInstalled("ffprobe")) + { + probePath = "ffprobe"; + } + + return new Tuple<string, string>(encoderPath, probePath); + } + + private bool TestSystemInstalled(string app) + { + try + { + var startInfo = new ProcessStartInfo + { + FileName = app, + Arguments = "-v", + UseShellExecute = false, + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden, + ErrorDialog = false + }; + + using (var process = Process.Start(startInfo)) + { + process.WaitForExit(); + } + + _logger.Debug("System app installed: " + app); + return true; + } + catch + { + _logger.Debug("System app not installed: " + app); + return false; + } + } + private Tuple<string,string> GetPathsFromDirectory(string path) { // Since we can't predict the file extension, first try directly within the folder |
