FFMpegDownloadInfo.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. public static string Version = ffmpegOsType("Version");
  14. public static string[] FfMpegUrls = GetDownloadUrls();
  15. public static string FFMpegFilename = ffmpegOsType("FFMpegFilename");
  16. public static string FFProbeFilename = ffmpegOsType("FFProbeFilename");
  17. public static string ArchiveType = ffmpegOsType("ArchiveType");
  18. private static string ffmpegOsType(string arg)
  19. {
  20. OperatingSystem os = Environment.OSVersion;
  21. PlatformID pid = os.Platform;
  22. switch (pid)
  23. {
  24. case PlatformID.Win32NT:
  25. switch (arg)
  26. {
  27. case "Version":
  28. return "20140105";
  29. case "FFMpegFilename":
  30. return "ffmpeg.exe";
  31. case "FFProbeFilename":
  32. return "ffprobe.exe";
  33. case "ArchiveType":
  34. return "7z";
  35. }
  36. break;
  37. #if __MonoCS__
  38. case PlatformID.Unix:
  39. if (PlatformDetection.IsMac)
  40. {
  41. if (PlatformDetection.IsX86_64)
  42. {
  43. switch (arg)
  44. {
  45. case "Version":
  46. return "20131121";
  47. case "FFMpegFilename":
  48. return "ffmpeg";
  49. case "FFProbeFilename":
  50. return "ffprobe";
  51. case "ArchiveType":
  52. return "gz";
  53. }
  54. break;
  55. }
  56. }
  57. if (PlatformDetection.IsLinux)
  58. {
  59. if (PlatformDetection.IsX86)
  60. {
  61. switch (arg)
  62. {
  63. case "Version":
  64. return "linux_x86_20140118";
  65. case "FFMpegFilename":
  66. return "ffmpeg";
  67. case "FFProbeFilename":
  68. return "ffprobe";
  69. case "ArchiveType":
  70. return "gz";
  71. }
  72. break;
  73. }
  74. else if (PlatformDetection.IsX86_64)
  75. {
  76. // Linux on x86 or x86_64
  77. switch (arg)
  78. {
  79. case "Version":
  80. return "linux_x86_64_20140118";
  81. case "FFMpegFilename":
  82. return "ffmpeg";
  83. case "FFProbeFilename":
  84. return "ffprobe";
  85. case "ArchiveType":
  86. return "gz";
  87. }
  88. break;
  89. }
  90. }
  91. // Unsupported Unix platform
  92. return "";
  93. #endif
  94. }
  95. return "";
  96. }
  97. private static string[] GetDownloadUrls()
  98. {
  99. var pid = Environment.OSVersion.Platform;
  100. switch (pid)
  101. {
  102. case PlatformID.Win32NT:
  103. return new[]
  104. {
  105. "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20140105-git-70937d9-win32-static.7z",
  106. "https://www.dropbox.com/s/oghurnp5zh292ry/ffmpeg-20140105-git-70937d9-win32-static.7z?dl=1"
  107. };
  108. #if __MonoCS__
  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.2014-01-18.tar.gz",
  124. "https://www.dropbox.com/s/b7nkg71sil812hp/ffmpeg.static.32bit.2014-01-04.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.2014-01-18.tar.gz"
  132. };
  133. }
  134. }
  135. //No Unix version available
  136. return new string[] {};
  137. #endif
  138. }
  139. return new string[] {};
  140. }
  141. }
  142. #if __MonoCS__
  143. public static class PlatformDetection
  144. {
  145. public readonly static bool IsWindows;
  146. public readonly static bool IsMac;
  147. public readonly static bool IsLinux;
  148. public readonly static bool IsX86;
  149. public readonly static bool IsX86_64;
  150. public readonly static bool IsArm;
  151. static PlatformDetection ()
  152. {
  153. IsWindows = Path.DirectorySeparatorChar == '\\';
  154. //Don't call uname on windows
  155. if (!IsWindows)
  156. {
  157. Utsname uname;
  158. var callResult = Syscall.uname(out uname);
  159. if (callResult == 0)
  160. {
  161. IsMac = uname.sysname == "Darwin";
  162. IsLinux = !IsMac && uname.sysname == "Linux";
  163. Regex archX86 = new Regex("(i|I)[3-6]86");
  164. IsX86 = archX86.IsMatch(uname.machine);
  165. IsX86_64 = !IsX86 && uname.machine == "x86_64";
  166. IsArm = !IsX86 && !IsX86 && uname.machine.StartsWith("arm");
  167. }
  168. }
  169. else
  170. {
  171. if (System.Environment.Is64BitOperatingSystem)
  172. IsX86_64 = true;
  173. else
  174. IsX86 = true;
  175. }
  176. }
  177. }
  178. #endif
  179. }