FFMpegDownloadInfo.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. #if __MonoCS__
  3. using Mono.Unix.Native;
  4. using System.Text.RegularExpressions;
  5. using System.IO;
  6. #endif
  7. namespace MediaBrowser.ServerApplication.FFMpeg
  8. {
  9. public static class FFMpegDownloadInfo
  10. {
  11. // Windows builds: http://ffmpeg.zeranoe.com/builds/
  12. // Linux builds: http://ffmpeg.gusari.org/static/
  13. // OS X builds: http://ffmpegmac.net/
  14. public static string Version = ffmpegOsType("Version");
  15. public static string[] FfMpegUrls = GetDownloadUrls();
  16. public static string FFMpegFilename = ffmpegOsType("FFMpegFilename");
  17. public static string FFProbeFilename = ffmpegOsType("FFProbeFilename");
  18. public static string ArchiveType = ffmpegOsType("ArchiveType");
  19. private static string ffmpegOsType(string arg)
  20. {
  21. OperatingSystem os = Environment.OSVersion;
  22. PlatformID pid = os.Platform;
  23. switch (pid)
  24. {
  25. case PlatformID.Win32NT:
  26. switch (arg)
  27. {
  28. case "Version":
  29. return "20140304";
  30. case "FFMpegFilename":
  31. return "ffmpeg.exe";
  32. case "FFProbeFilename":
  33. return "ffprobe.exe";
  34. case "ArchiveType":
  35. return "7z";
  36. }
  37. break;
  38. #if __MonoCS__
  39. case PlatformID.Unix:
  40. if (PlatformDetection.IsMac)
  41. {
  42. if (PlatformDetection.IsX86_64)
  43. {
  44. switch (arg)
  45. {
  46. case "Version":
  47. return "20131121";
  48. case "FFMpegFilename":
  49. return "ffmpeg";
  50. case "FFProbeFilename":
  51. return "ffprobe";
  52. case "ArchiveType":
  53. return "gz";
  54. }
  55. break;
  56. }
  57. }
  58. if (PlatformDetection.IsLinux)
  59. {
  60. if (PlatformDetection.IsX86)
  61. {
  62. switch (arg)
  63. {
  64. case "Version":
  65. return "20140304";
  66. case "FFMpegFilename":
  67. return "ffmpeg";
  68. case "FFProbeFilename":
  69. return "ffprobe";
  70. case "ArchiveType":
  71. return "gz";
  72. }
  73. break;
  74. }
  75. else if (PlatformDetection.IsX86_64)
  76. {
  77. // Linux on x86 or x86_64
  78. switch (arg)
  79. {
  80. case "Version":
  81. return "20140304";
  82. case "FFMpegFilename":
  83. return "ffmpeg";
  84. case "FFProbeFilename":
  85. return "ffprobe";
  86. case "ArchiveType":
  87. return "gz";
  88. }
  89. break;
  90. }
  91. }
  92. // Unsupported Unix platform
  93. return "";
  94. #endif
  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-20140304-git-f34cceb-win32-static.7z",
  107. "https://www.dropbox.com/s/6brdetuzbld93jk/ffmpeg-20140304-git-f34cceb-win32-static.7z?dl=1"
  108. };
  109. #if __MonoCS__
  110. case PlatformID.Unix:
  111. if (PlatformDetection.IsMac && PlatformDetection.IsX86_64)
  112. {
  113. return new[]
  114. {
  115. "https://www.dropbox.com/s/n188rxbulqem8ry/ffmpeg-osx-20131121.gz?dl=1"
  116. };
  117. }
  118. if (PlatformDetection.IsLinux)
  119. {
  120. if (PlatformDetection.IsX86)
  121. {
  122. return new[]
  123. {
  124. "http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.2014-03-04.tar.gz",
  125. "https://www.dropbox.com/s/0l76mcauqqkta31/ffmpeg.static.32bit.2014-03-04.tar.gz?dl=1"
  126. };
  127. }
  128. if (PlatformDetection.IsX86_64)
  129. {
  130. return new[]
  131. {
  132. "http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.2014-03-04.tar.gz",
  133. "https://www.dropbox.com/s/9wlxz440mdejuqe/ffmpeg.static.64bit.2014-03-04.tar.gz?dl=1"
  134. };
  135. }
  136. }
  137. //No Unix version available
  138. return new string[] {};
  139. #endif
  140. }
  141. return new string[] {};
  142. }
  143. }
  144. #if __MonoCS__
  145. public static class PlatformDetection
  146. {
  147. public readonly static bool IsWindows;
  148. public readonly static bool IsMac;
  149. public readonly static bool IsLinux;
  150. public readonly static bool IsX86;
  151. public readonly static bool IsX86_64;
  152. public readonly static bool IsArm;
  153. static PlatformDetection ()
  154. {
  155. IsWindows = Path.DirectorySeparatorChar == '\\';
  156. //Don't call uname on windows
  157. if (!IsWindows)
  158. {
  159. Utsname uname;
  160. var callResult = Syscall.uname(out uname);
  161. if (callResult == 0)
  162. {
  163. IsMac = uname.sysname == "Darwin";
  164. IsLinux = !IsMac && uname.sysname == "Linux";
  165. Regex archX86 = new Regex("(i|I)[3-6]86");
  166. IsX86 = archX86.IsMatch(uname.machine);
  167. IsX86_64 = !IsX86 && uname.machine == "x86_64";
  168. IsArm = !IsX86 && !IsX86 && uname.machine.StartsWith("arm");
  169. }
  170. }
  171. else
  172. {
  173. if (System.Environment.Is64BitOperatingSystem)
  174. IsX86_64 = true;
  175. else
  176. IsX86 = true;
  177. }
  178. }
  179. }
  180. #endif
  181. }