2
0

MediaInfoLib.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. namespace MediaBrowser.MediaInfo
  6. {
  7. public class MediaInfoLib
  8. {
  9. public MediaInfoResult GetVideoInfo(string path)
  10. {
  11. var lib = new MediaInfo();
  12. lib.Open(path);
  13. var result = new MediaInfoResult();
  14. // TODO: Don't hardcode
  15. var videoStreamIndex = 0;
  16. var text = GetValue(lib, videoStreamIndex, new[] { "ScanType", "Scan type", "ScanType/String" });
  17. if (!string.IsNullOrWhiteSpace(text))
  18. {
  19. result.IsInterlaced = text.IndexOf("interlac", StringComparison.OrdinalIgnoreCase) != -1;
  20. }
  21. int bitDepth;
  22. text = GetValue(lib, videoStreamIndex, new[] { "BitDepth", "BitDepth/String" });
  23. if (!string.IsNullOrWhiteSpace(text) && int.TryParse(text.Split(' ').First(), NumberStyles.Any, CultureInfo.InvariantCulture, out bitDepth))
  24. {
  25. result.BitDepth = bitDepth;
  26. }
  27. int refFrames;
  28. text = GetValue(lib, videoStreamIndex, new[] { "Format_Settings_RefFrames", "Format_Settings_RefFrames/String" });
  29. if (!string.IsNullOrWhiteSpace(text) && int.TryParse(text.Split(' ').First(), NumberStyles.Any, CultureInfo.InvariantCulture, out refFrames))
  30. {
  31. result.RefFrames = refFrames;
  32. }
  33. return result;
  34. }
  35. private string GetValue(MediaInfo lib, int index, IEnumerable<string> names)
  36. {
  37. return names.Select(i => lib.Get(StreamKind.Video, index, i)).FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
  38. }
  39. }
  40. public class MediaInfoResult
  41. {
  42. public bool? IsInterlaced { get; set; }
  43. public int? BitDepth { get; set; }
  44. public int? RefFrames { get; set; }
  45. }
  46. }