[英]How to access video file info in c#
我正在從文件夾中讀取.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對象具有更多屬性。 我需要從實際文件中提取它們
我用過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;
//...
}
您可以使用ffmpeg(ffmpeg.exe或ffprobe.exe)從視頻或音頻文件中提取元數據(它支持幾乎所有已知格式)。 可以使用System.Diagnostics從C#代碼執行FFMpeg。應從控制台輸出中解析過程和視頻文件元數據(您可以重定向stdout並將其讀取為字符串)。
作為編寫執行ffprobe的自定義代碼的替代方法,您可以使用現有的.NET包裝器之一,該包裝器將使用一行代碼返回結果(例如NReco VideoInfo,我是該庫的作者)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.