FFMpegDownloadInfo.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 "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. if (PlatformDetection.IsX86_64)
  106. {
  107. return new[]
  108. {
  109. "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20140827-git-9e8ab36-win64-static.7z",
  110. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20140612-git-3a1c895-win32-static.7z"
  111. };
  112. }
  113. return new[]
  114. {
  115. "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20140827-git-9e8ab36-win32-static.7z",
  116. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20140612-git-3a1c895-win32-static.7z"
  117. };
  118. case PlatformID.Unix:
  119. if (PlatformDetection.IsMac && PlatformDetection.IsX86)
  120. {
  121. return new[]
  122. {
  123. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffmpeg-osx-20131121.gz"
  124. };
  125. }
  126. if (PlatformDetection.IsMac && PlatformDetection.IsX86_64)
  127. {
  128. return new[]
  129. {
  130. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffprobe-x64-2.2.4.7z"
  131. };
  132. }
  133. if (PlatformDetection.IsLinux)
  134. {
  135. if (PlatformDetection.IsX86)
  136. {
  137. return new[]
  138. {
  139. "http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.latest.tar.gz",
  140. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.32bit.2014-05-06.tar.gz"
  141. };
  142. }
  143. if (PlatformDetection.IsX86_64)
  144. {
  145. return new[]
  146. {
  147. "http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.latest.tar.gz",
  148. "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.64bit.2014-05-05.tar.gz"
  149. };
  150. }
  151. }
  152. // No Unix version available
  153. return new string[] { };
  154. default:
  155. throw new ApplicationException("No ffmpeg download available for " + pid);
  156. }
  157. }
  158. }
  159. public static class PlatformDetection
  160. {
  161. public readonly static bool IsWindows;
  162. public readonly static bool IsMac;
  163. public readonly static bool IsLinux;
  164. public readonly static bool IsX86;
  165. public readonly static bool IsX86_64;
  166. public readonly static bool IsArm;
  167. static PlatformDetection()
  168. {
  169. IsWindows = Path.DirectorySeparatorChar == '\\';
  170. //Don't call uname on windows
  171. if (!IsWindows)
  172. {
  173. var uname = GetUnixName();
  174. IsMac = uname.sysname == "Darwin";
  175. IsLinux = uname.sysname == "Linux";
  176. var archX86 = new Regex("(i|I)[3-6]86");
  177. IsX86 = archX86.IsMatch(uname.machine);
  178. IsX86_64 = !IsX86 && uname.machine == "x86_64";
  179. IsArm = !IsX86 && !IsX86_64 && uname.machine.StartsWith("arm");
  180. }
  181. else
  182. {
  183. if (Environment.Is64BitOperatingSystem)
  184. IsX86_64 = true;
  185. else
  186. IsX86 = true;
  187. }
  188. }
  189. private static Uname GetUnixName()
  190. {
  191. var uname = new Uname();
  192. #if __MonoCS__
  193. Utsname utsname;
  194. var callResult = Syscall.uname(out utsname);
  195. if (callResult == 0)
  196. {
  197. uname.sysname= utsname.sysname;
  198. uname.machine= utsname.machine;
  199. }
  200. #endif
  201. return uname;
  202. }
  203. }
  204. public class Uname
  205. {
  206. public string sysname = string.Empty;
  207. public string machine = string.Empty;
  208. }
  209. }