FFMpegDownloadInfo.cs 9.3 KB

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