FFMpegDownloadInfo.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. #if __MonoCS__
  3. using Mono.Unix.Native;
  4. using System.Text.RegularExpressions;
  5. using System.IO;
  6. #endif
  7. using System.IO;
  8. using System.Text.RegularExpressions;
  9. namespace MediaBrowser.ServerApplication.FFMpeg
  10. {
  11. public static class FFMpegDownloadInfo
  12. {
  13. // Windows builds: http://ffmpeg.zeranoe.com/builds/
  14. // Linux builds: http://ffmpeg.gusari.org/static/
  15. // OS X builds: http://ffmpegmac.net/
  16. // OS X x64: http://www.evermeet.cx/ffmpeg/
  17. public static string Version = ffmpegOsType("Version");
  18. public static string[] FfMpegUrls = GetDownloadUrls();
  19. public static string FFMpegFilename = ffmpegOsType("FFMpegFilename");
  20. public static string FFProbeFilename = ffmpegOsType("FFProbeFilename");
  21. public static string ArchiveType = ffmpegOsType("ArchiveType");
  22. private static string ffmpegOsType(string arg)
  23. {
  24. OperatingSystem os = Environment.OSVersion;
  25. PlatformID pid = os.Platform;
  26. switch (pid)
  27. {
  28. case PlatformID.Win32NT:
  29. switch (arg)
  30. {
  31. case "Version":
  32. return "20140612";
  33. case "FFMpegFilename":
  34. return "ffmpeg.exe";
  35. case "FFProbeFilename":
  36. return "ffprobe.exe";
  37. case "ArchiveType":
  38. return "7z";
  39. }
  40. break;
  41. case PlatformID.Unix:
  42. if (PlatformDetection.IsMac)
  43. {
  44. if (PlatformDetection.IsX86_64)
  45. {
  46. switch (arg)
  47. {
  48. case "Version":
  49. return "20131121";
  50. case "FFMpegFilename":
  51. return "ffmpeg";
  52. case "FFProbeFilename":
  53. return "ffprobe";
  54. case "ArchiveType":
  55. return "gz";
  56. }
  57. break;
  58. }
  59. }
  60. if (PlatformDetection.IsLinux)
  61. {
  62. if (PlatformDetection.IsX86)
  63. {
  64. switch (arg)
  65. {
  66. case "Version":
  67. return "20140506";
  68. case "FFMpegFilename":
  69. return "ffmpeg";
  70. case "FFProbeFilename":
  71. return "ffprobe";
  72. case "ArchiveType":
  73. return "gz";
  74. }
  75. break;
  76. }
  77. else if (PlatformDetection.IsX86_64)
  78. {
  79. // Linux on x86 or x86_64
  80. switch (arg)
  81. {
  82. case "Version":
  83. return "20140505";
  84. case "FFMpegFilename":
  85. return "ffmpeg";
  86. case "FFProbeFilename":
  87. return "ffprobe";
  88. case "ArchiveType":
  89. return "gz";
  90. }
  91. break;
  92. }
  93. }
  94. // Unsupported Unix platform
  95. return "";
  96. }
  97. return "";
  98. }
  99. private static string[] GetDownloadUrls()
  100. {
  101. var pid = Environment.OSVersion.Platform;
  102. switch (pid)
  103. {
  104. case PlatformID.Win32NT:
  105. return new[]
  106. {
  107. "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20140612-git-3a1c895-win32-static.7z",
  108. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20140612-git-3a1c895-win32-static.7z"
  109. };
  110. case PlatformID.Unix:
  111. if (PlatformDetection.IsMac && PlatformDetection.IsX86)
  112. {
  113. return new[]
  114. {
  115. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffmpeg-osx-20131121.gz"
  116. };
  117. }
  118. if (PlatformDetection.IsMac && PlatformDetection.IsX86_64)
  119. {
  120. return new[]
  121. {
  122. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffprobe-x64-2.2.4.7z"
  123. };
  124. }
  125. if (PlatformDetection.IsLinux)
  126. {
  127. if (PlatformDetection.IsX86)
  128. {
  129. return new[]
  130. {
  131. "http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.latest.tar.gz",
  132. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.32bit.2014-05-06.tar.gz"
  133. };
  134. }
  135. if (PlatformDetection.IsX86_64)
  136. {
  137. return new[]
  138. {
  139. "http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.latest.tar.gz",
  140. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.64bit.2014-05-05.tar.gz"
  141. };
  142. }
  143. }
  144. // No Unix version available
  145. return new string[] { };
  146. default:
  147. throw new ApplicationException("No ffmpeg download available for " + pid);
  148. }
  149. }
  150. }
  151. public static class PlatformDetection
  152. {
  153. public readonly static bool IsWindows;
  154. public readonly static bool IsMac;
  155. public readonly static bool IsLinux;
  156. public readonly static bool IsX86;
  157. public readonly static bool IsX86_64;
  158. public readonly static bool IsArm;
  159. static PlatformDetection()
  160. {
  161. IsWindows = Path.DirectorySeparatorChar == '\\';
  162. //Don't call uname on windows
  163. if (!IsWindows)
  164. {
  165. var uname = GetUnixName();
  166. IsMac = uname.sysname == "Darwin";
  167. IsLinux = uname.sysname == "Linux";
  168. var archX86 = new Regex("(i|I)[3-6]86");
  169. IsX86 = archX86.IsMatch(uname.machine);
  170. IsX86_64 = !IsX86 && uname.machine == "x86_64";
  171. IsArm = !IsX86 && !IsX86_64 && uname.machine.StartsWith("arm");
  172. }
  173. else
  174. {
  175. if (Environment.Is64BitOperatingSystem)
  176. IsX86_64 = true;
  177. else
  178. IsX86 = true;
  179. }
  180. }
  181. private static Uname GetUnixName()
  182. {
  183. var uname = new Uname();
  184. #if __MonoCS__
  185. Utsname utsname;
  186. var callResult = Syscall.uname(out utsname);
  187. if (callResult == 0)
  188. {
  189. uname.sysname= utsname.sysname;
  190. uname.machine= utsname.machine;
  191. }
  192. #endif
  193. return uname;
  194. }
  195. }
  196. public class Uname
  197. {
  198. public string sysname = string.Empty;
  199. public string machine = string.Empty;
  200. }
  201. }