FFMpegDownloadInfo.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. #if __MonoCS__
  3. using System.Runtime.InteropServices;
  4. #endif
  5. namespace MediaBrowser.ServerApplication.FFMpeg
  6. {
  7. public static class FFMpegDownloadInfo
  8. {
  9. // Windows builds: http://ffmpeg.zeranoe.com/builds/
  10. // Linux builds: http://ffmpeg.gusari.org/static/
  11. public static string Version = ffmpegOsType("Version");
  12. public static string[] FfMpegUrls = GetDownloadUrls();
  13. public static string FFMpegFilename = ffmpegOsType("FFMpegFilename");
  14. public static string FFProbeFilename = ffmpegOsType("FFProbeFilename");
  15. public static string ArchiveType = ffmpegOsType("ArchiveType");
  16. private static string ffmpegOsType(string arg)
  17. {
  18. OperatingSystem os = Environment.OSVersion;
  19. PlatformID pid = os.Platform;
  20. switch (pid)
  21. {
  22. case PlatformID.Win32NT:
  23. switch (arg)
  24. {
  25. case "Version":
  26. return "20140105";
  27. case "FFMpegFilename":
  28. return "ffmpeg.exe";
  29. case "FFProbeFilename":
  30. return "ffprobe.exe";
  31. case "ArchiveType":
  32. return "7z";
  33. }
  34. break;
  35. #if __MonoCS__
  36. case PlatformID.Unix:
  37. if (IsRunningOnMac())
  38. {
  39. switch (arg)
  40. {
  41. case "Version":
  42. return "20131121";
  43. case "FFMpegFilename":
  44. return "ffmpeg";
  45. case "FFProbeFilename":
  46. return "ffprobe";
  47. case "ArchiveType":
  48. return "gz";
  49. }
  50. break;
  51. }
  52. else
  53. {
  54. // Linux
  55. switch (arg)
  56. {
  57. case "Version":
  58. return "20140104";
  59. case "FFMpegFilename":
  60. return "ffmpeg";
  61. case "FFProbeFilename":
  62. return "ffprobe";
  63. case "ArchiveType":
  64. return "gz";
  65. }
  66. break;
  67. }
  68. #endif
  69. }
  70. return "";
  71. }
  72. private static string[] GetDownloadUrls()
  73. {
  74. var pid = Environment.OSVersion.Platform;
  75. switch (pid)
  76. {
  77. case PlatformID.Win32NT:
  78. return new[]
  79. {
  80. "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20140105-git-70937d9-win32-static.7z",
  81. "https://www.dropbox.com/s/oghurnp5zh292ry/ffmpeg-20140105-git-70937d9-win32-static.7z?dl=1"
  82. };
  83. #if __MonoCS__
  84. case PlatformID.Unix:
  85. if (IsRunningOnMac())
  86. {
  87. // Mac OS X Intel 64bit
  88. return new[]
  89. {
  90. "https://copy.com/ylAUbbQHYE7x/ffall-2.1.1.7z?download=1"
  91. };
  92. }
  93. else
  94. {
  95. // Linux
  96. return new[]
  97. {
  98. "http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.2014-01-04.tar.gz",
  99. "https://www.dropbox.com/s/b7nkg71sil812hp/ffmpeg.static.32bit.2014-01-04.tar.gz?dl=1"
  100. };
  101. }
  102. #endif
  103. }
  104. return new string[] {};
  105. }
  106. #if __MonoCS__
  107. // From mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUI.cs
  108. [DllImport ("libc")]
  109. static extern int uname (IntPtr buf);
  110. static bool IsRunningOnMac()
  111. {
  112. IntPtr buf = IntPtr.Zero;
  113. try {
  114. buf = Marshal.AllocHGlobal (8192);
  115. // This is a hacktastic way of getting sysname from uname ()
  116. if (uname (buf) == 0) {
  117. string os = Marshal.PtrToStringAnsi (buf);
  118. if (os == "Darwin")
  119. return true;
  120. }
  121. } catch {
  122. } finally {
  123. if (buf != IntPtr.Zero)
  124. Marshal.FreeHGlobal (buf);
  125. }
  126. return false;
  127. }
  128. #endif
  129. }
  130. }