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