FFMpegDownloadInfo.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 = getFfmpegValue("Version");
  18. public static string FFMpegFilename = getFfmpegValue("FFMpegFilename");
  19. public static string FFProbeFilename = getFfmpegValue("FFProbeFilename");
  20. public static string ArchiveType = getFfmpegValue("ArchiveType");
  21. private static string getFfmpegValue(string arg)
  22. {
  23. OperatingSystem os = Environment.OSVersion;
  24. PlatformID pid = os.Platform;
  25. switch (pid)
  26. {
  27. case PlatformID.Win32NT:
  28. switch (arg)
  29. {
  30. case "Version":
  31. return "20140827";
  32. case "FFMpegFilename":
  33. return "ffmpeg.exe";
  34. case "FFProbeFilename":
  35. return "ffprobe.exe";
  36. case "ArchiveType":
  37. return "7z";
  38. }
  39. break;
  40. case PlatformID.Unix:
  41. if (PlatformDetection.IsMac)
  42. {
  43. if (PlatformDetection.IsX86_64)
  44. {
  45. switch (arg)
  46. {
  47. case "Version":
  48. return "20140827";
  49. case "FFMpegFilename":
  50. return "ffmpeg";
  51. case "FFProbeFilename":
  52. return "ffprobe";
  53. case "ArchiveType":
  54. return "gz";
  55. }
  56. }
  57. if (PlatformDetection.IsX86)
  58. {
  59. switch (arg)
  60. {
  61. case "Version":
  62. return "20131121";
  63. case "FFMpegFilename":
  64. return "ffmpeg";
  65. case "FFProbeFilename":
  66. return "ffprobe";
  67. case "ArchiveType":
  68. return "gz";
  69. }
  70. }
  71. }
  72. else if (PlatformDetection.IsLinux)
  73. {
  74. if (PlatformDetection.IsX86)
  75. {
  76. switch (arg)
  77. {
  78. case "Version":
  79. return "20140506";
  80. case "FFMpegFilename":
  81. return "ffmpeg";
  82. case "FFProbeFilename":
  83. return "ffprobe";
  84. case "ArchiveType":
  85. return "gz";
  86. }
  87. }
  88. else if (PlatformDetection.IsX86_64)
  89. {
  90. // Linux on x86 or x86_64
  91. switch (arg)
  92. {
  93. case "Version":
  94. return "20140505";
  95. case "FFMpegFilename":
  96. return "ffmpeg";
  97. case "FFProbeFilename":
  98. return "ffprobe";
  99. case "ArchiveType":
  100. return "gz";
  101. }
  102. }
  103. }
  104. break;
  105. }
  106. switch (arg)
  107. {
  108. case "Version":
  109. return "path";
  110. case "FFMpegFilename":
  111. return "ffmpeg";
  112. case "FFProbeFilename":
  113. return "ffprobe";
  114. case "ArchiveType":
  115. return "";
  116. default:
  117. return string.Empty;
  118. }
  119. }
  120. public static string[] GetDownloadUrls()
  121. {
  122. var pid = Environment.OSVersion.Platform;
  123. switch (pid)
  124. {
  125. case PlatformID.Win32NT:
  126. if (PlatformDetection.IsX86_64)
  127. {
  128. return new[]
  129. {
  130. "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20140827-git-9e8ab36-win64-static.7z",
  131. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20140827-git-9e8ab36-win64-static.7z"
  132. };
  133. }
  134. return new[]
  135. {
  136. "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20140827-git-9e8ab36-win32-static.7z",
  137. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20140827-git-9e8ab36-win32-static.7z"
  138. };
  139. case PlatformID.Unix:
  140. if (PlatformDetection.IsMac && PlatformDetection.IsX86)
  141. {
  142. return new[]
  143. {
  144. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffmpeg-osx-20131121.gz"
  145. };
  146. }
  147. if (PlatformDetection.IsMac && PlatformDetection.IsX86_64)
  148. {
  149. return new[]
  150. {
  151. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffmpeg-x64-2.3.3.7z"
  152. };
  153. }
  154. if (PlatformDetection.IsLinux)
  155. {
  156. if (PlatformDetection.IsX86)
  157. {
  158. return new[]
  159. {
  160. "http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.latest.tar.gz",
  161. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.32bit.2014-05-06.tar.gz"
  162. };
  163. }
  164. if (PlatformDetection.IsX86_64)
  165. {
  166. return new[]
  167. {
  168. "http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.latest.tar.gz",
  169. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.64bit.2014-05-05.tar.gz"
  170. };
  171. }
  172. }
  173. // No Unix version available
  174. return new string[] { };
  175. default:
  176. throw new ApplicationException("No ffmpeg download available for " + pid);
  177. }
  178. }
  179. }
  180. public static class PlatformDetection
  181. {
  182. public readonly static bool IsWindows;
  183. public readonly static bool IsMac;
  184. public readonly static bool IsLinux;
  185. public readonly static bool IsX86;
  186. public readonly static bool IsX86_64;
  187. public readonly static bool IsArm;
  188. static PlatformDetection()
  189. {
  190. IsWindows = Path.DirectorySeparatorChar == '\\';
  191. // Don't call uname on windows
  192. if (!IsWindows)
  193. {
  194. var uname = GetUnixName();
  195. var sysName = uname.sysname ?? string.Empty;
  196. IsMac = string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase);
  197. IsLinux = string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase);
  198. var archX86 = new Regex("(i|I)[3-6]86");
  199. IsX86 = archX86.IsMatch(uname.machine);
  200. IsX86_64 = !IsX86 && uname.machine == "x86_64";
  201. IsArm = !IsX86 && !IsX86_64 && uname.machine.StartsWith("arm");
  202. }
  203. else
  204. {
  205. if (Environment.Is64BitOperatingSystem)
  206. IsX86_64 = true;
  207. else
  208. IsX86 = true;
  209. }
  210. }
  211. private static Uname GetUnixName()
  212. {
  213. var uname = new Uname();
  214. #if __MonoCS__
  215. Utsname utsname;
  216. var callResult = Syscall.uname(out utsname);
  217. if (callResult == 0)
  218. {
  219. uname.sysname= utsname.sysname;
  220. uname.machine= utsname.machine;
  221. }
  222. #endif
  223. return uname;
  224. }
  225. }
  226. public class Uname
  227. {
  228. public string sysname = string.Empty;
  229. public string machine = string.Empty;
  230. }
  231. }