FFMpegDownloadInfo.cs 9.1 KB

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