FFMpegDownloadInfo.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. public static string Version = ffmpegOsType("Version");
  17. public static string[] FfMpegUrls = GetDownloadUrls();
  18. public static string FFMpegFilename = ffmpegOsType("FFMpegFilename");
  19. public static string FFProbeFilename = ffmpegOsType("FFProbeFilename");
  20. public static string ArchiveType = ffmpegOsType("ArchiveType");
  21. private static string ffmpegOsType(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 "20140506";
  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 "20131121";
  49. case "FFMpegFilename":
  50. return "ffmpeg";
  51. case "FFProbeFilename":
  52. return "ffprobe";
  53. case "ArchiveType":
  54. return "gz";
  55. }
  56. break;
  57. }
  58. }
  59. if (PlatformDetection.IsLinux)
  60. {
  61. if (PlatformDetection.IsX86)
  62. {
  63. switch (arg)
  64. {
  65. case "Version":
  66. return "20140506";
  67. case "FFMpegFilename":
  68. return "ffmpeg";
  69. case "FFProbeFilename":
  70. return "ffprobe";
  71. case "ArchiveType":
  72. return "gz";
  73. }
  74. break;
  75. }
  76. else if (PlatformDetection.IsX86_64)
  77. {
  78. // Linux on x86 or x86_64
  79. switch (arg)
  80. {
  81. case "Version":
  82. return "20140505";
  83. case "FFMpegFilename":
  84. return "ffmpeg";
  85. case "FFProbeFilename":
  86. return "ffprobe";
  87. case "ArchiveType":
  88. return "gz";
  89. }
  90. break;
  91. }
  92. }
  93. // Unsupported Unix platform
  94. return "";
  95. }
  96. return "";
  97. }
  98. private static string[] GetDownloadUrls()
  99. {
  100. var pid = Environment.OSVersion.Platform;
  101. switch (pid)
  102. {
  103. case PlatformID.Win32NT:
  104. return new[]
  105. {
  106. "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20140506-git-2baf1c8-win32-static.7z",
  107. "https://www.dropbox.com/s/lxlzxs0r83iatsv/ffmpeg-20140506-git-2baf1c8-win32-static.7z?dl=1"
  108. };
  109. case PlatformID.Unix:
  110. if (PlatformDetection.IsMac && PlatformDetection.IsX86_64)
  111. {
  112. return new[]
  113. {
  114. "https://www.dropbox.com/s/n188rxbulqem8ry/ffmpeg-osx-20131121.gz?dl=1"
  115. };
  116. }
  117. if (PlatformDetection.IsLinux)
  118. {
  119. if (PlatformDetection.IsX86)
  120. {
  121. return new[]
  122. {
  123. "http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.latest.tar.gz",
  124. "https://www.dropbox.com/s/k9s02pv5to6slfb/ffmpeg.static.32bit.2014-05-06.tar.gz?dl=1"
  125. };
  126. }
  127. if (PlatformDetection.IsX86_64)
  128. {
  129. return new[]
  130. {
  131. "http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.latest.tar.gz",
  132. "https://www.dropbox.com/s/onuregwghywnzjo/ffmpeg.static.64bit.2014-05-05.tar.gz?dl=1"
  133. };
  134. }
  135. }
  136. //No Unix version available
  137. return new string[] { };
  138. }
  139. return new string[] { };
  140. }
  141. }
  142. public static class PlatformDetection
  143. {
  144. public readonly static bool IsWindows;
  145. public readonly static bool IsMac;
  146. public readonly static bool IsLinux;
  147. public readonly static bool IsX86;
  148. public readonly static bool IsX86_64;
  149. public readonly static bool IsArm;
  150. static PlatformDetection()
  151. {
  152. IsWindows = Path.DirectorySeparatorChar == '\\';
  153. //Don't call uname on windows
  154. if (!IsWindows)
  155. {
  156. var uname = GetUnixName();
  157. IsMac = uname.sysname == "Darwin";
  158. IsLinux = uname.sysname == "Linux";
  159. var archX86 = new Regex("(i|I)[3-6]86");
  160. IsX86 = archX86.IsMatch(uname.machine);
  161. IsX86_64 = !IsX86 && uname.machine == "x86_64";
  162. IsArm = !IsX86 && !IsX86_64 && uname.machine.StartsWith("arm");
  163. }
  164. else
  165. {
  166. if (Environment.Is64BitOperatingSystem)
  167. IsX86_64 = true;
  168. else
  169. IsX86 = true;
  170. }
  171. }
  172. private static Uname GetUnixName()
  173. {
  174. var uname = new Uname();
  175. #if __MonoCS__
  176. Utsname utsname;
  177. var callResult = Syscall.uname(out utsname);
  178. if (callResult == 0)
  179. {
  180. uname.sysname= utsname.sysname;
  181. uname.machine= utsname.machine;
  182. }
  183. #endif
  184. return uname;
  185. }
  186. }
  187. public class Uname
  188. {
  189. public string sysname = string.Empty;
  190. public string machine = string.Empty;
  191. }
  192. }