我从那里的.mp4文件夹中读取文件 目前我正在使用FileInfo来提取名称 FileInfo仅限于电影包含的一些细节。 我还需要提取其他信息 标题 字幕 评论 类型 董事 生产者
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
我的videoFile对象有更多属性。我需要从实际文件中提取它们
答案 0 :(得分: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;
//...
}
答案 1 :(得分:2)
您可以使用ffmpeg(ffmpeg.exe或ffprobe.exe)从视频或音频文件中提取元数据(它支持几乎所有已知格式)。可以使用System.Diagnostics.Process从C#代码执行FFMpeg,并且应该从控制台输出中解析视频文件元数据(您可以重定向stdout并将其作为字符串读取)。
作为编写执行ffprobe的自定义代码的替代方法,您可以使用一个现有的.NET包装器,它将返回一行代码的结果(如NReco VideoInfo - 我是此库的作者)。