如何在c#中访问视频文件信息

Ale*_*utu 0 c# video file visual-studio-2015

我正在从一个文件夹中读取.mp4文件当前我正在使用FileInfo来提取名称FileInfo仅限于电影中包含的一些细节.我还需要提取其他信息,例如Title Subtitle Comments Genre Directors Producers

DirectoryInfo dirInfo = new DirectoryInfo(@"..\bin\Debug\Folder");
FileInfo[] fileNames = dirInfo.GetFiles("*.mp4");
foreach (FileInfo fi in fileNames)
{
    string movieName = fi.Name.Split('.')[0]; // returns the file name
    VideoFile newVideo = new VideoFile(movieName); // insert name in object
            director.ListVid.Add(newVideo); // add object to a director object - aka another list
}
 listVideoDirector.Add(director); //add director object to list
Run Code Online (Sandbox Code Playgroud)

我的videoFile对象有更多属性.我需要从实际文件中提取它们

Mas*_*ali 6

我用过FFProbe库

下载库:https://www.nrecosite.com/downloads/video_info_free.zip

例如 :

string path = "Video path";
NReco.VideoInfo.FFProbe ffProbe = new NReco.VideoInfo.FFProbe();
MediaInfo videoInfo = ffProbe.GetMediaInfo(path ); 

TimeSpan videoDuration = videoInfo.Duration;

if (videoInfo.Streams[index].CodecType.ToLower() == "video")
{
 int iWidth = videoInfo.Streams[index].Width;
 int iHeight = videoInfo.Streams[index].Height;
 string sVideoFrameRate = videoInfo.Streams[index].FrameRate.ToString();
 string sVideoCodecName = videoInfo.Streams[index].VideoCodecName;
  //...
}
else if(videoInfo.Streams[index].CodecType.ToLower() == "audio")
{
   string sAudioCodecName = videoInfo.Streams[index].CodecName;
  //...
}
Run Code Online (Sandbox Code Playgroud)