使用C#从ASP.Net MVC中的视频文件中获取视频元数据的最佳方法是什么? [英] What's the best way to get video metadata from a video file in ASP.Net MVC using C#?
问题描述
我已经在Google和StackOverflow上搜索了好几个小时.在StackOverflow上似乎有很多类似的问题,但它们都存在大约3-5年.
I've been searching on Google and StackOverflow for a good couple of hours. There seems to be a lot of similar questions on StackOverflow but they are all about 3-5 years old.
如今,使用FFMPEG还是从.NET Web应用程序中的视频文件中提取元数据的最佳方法吗?如果是这样,那里最好的C#包装器是什么?
Is using FFMPEG still the best way these days to pull metadata from a video file in a .NET web application? And if so, what's the best C# wrapper out there?
我已经尝试了MediaToolkit,MediaFile.dll,但没有任何运气.我看到了ffmpeg-csharpe,但看起来好像几年都没碰过.
I've tried MediaToolkit, MediaFile.dll without any luck. I saw ffmpeg-csharpe but that looks like it hasn't been touched in a few years.
我尚未找到有关此主题的任何最新数据.现在是否可以从内置到最新版本的.NET的视频中提取元数据?
I haven't found any current data on this subject. Is the ability to pull metadata from a video built into the latest version of .NET now?
我现在基本上正在寻找任何方向.
I'm basically looking for any direction at this point.
我应该补充一点,就是我所使用的任何内容都可以每小时被调用数千次,因此它必须高效.
I should add that whatever I use could be invoked thousands of times per hour so it will need to be efficient.
推荐答案
看看MediaInfo
项目( http://mediaarea. net/zh/MediaInfo )
它获取有关大多数媒体类型的广泛信息,并且该库与易于使用的c#helper类捆绑在一起.
it gets extensive information about most media types, and the library is bundled with a c# helper class which is easy to use.
您可以从此处下载Windows的库和帮助程序类:
You can download the library and helper class for windows from here:
http://mediaarea.net/en/MediaInfo/Download/Windows (没有DLL的安装程序)
helper类位于Developers\Source\MediaInfoDLL\MediaInfoDLL.cs
,只需将其添加到您的项目中,然后将MediaInfo.dll
复制到bin中即可.
The helper class is located at Developers\Source\MediaInfoDLL\MediaInfoDLL.cs
, simply add it to your project and copy the MediaInfo.dll
to your bin.
用法
您可以通过从库中请求特定参数来获取信息,这是一个示例:
you can obtain information by requesting specific parameter from the library, Here is a sample:
[STAThread]
static void Main(string[] Args)
{
var mi = new MediaInfo();
mi.Open(@"video path here");
var videoInfo = new VideoInfo(mi);
var audioInfo = new AudioInfo(mi);
mi.Close();
}
public class VideoInfo
{
public string Codec { get; private set; }
public int Width { get; private set; }
public int Heigth { get; private set; }
public double FrameRate { get; private set; }
public string FrameRateMode { get; private set; }
public string ScanType { get; private set; }
public TimeSpan Duration { get; private set; }
public int Bitrate { get; private set; }
public string AspectRatioMode { get; private set; }
public double AspectRatio { get; private set; }
public VideoInfo(MediaInfo mi)
{
Codec=mi.Get(StreamKind.Video, 0, "Format");
Width = int.Parse(mi.Get(StreamKind.Video, 0, "Width"));
Heigth = int.Parse(mi.Get(StreamKind.Video, 0, "Height"));
Duration = TimeSpan.FromMilliseconds(int.Parse(mi.Get(StreamKind.Video, 0, "Duration")));
Bitrate = int.Parse(mi.Get(StreamKind.Video, 0, "BitRate"));
AspectRatioMode = mi.Get(StreamKind.Video, 0, "AspectRatio/String"); //as formatted string
AspectRatio =double.Parse(mi.Get(StreamKind.Video, 0, "AspectRatio"));
FrameRate = double.Parse(mi.Get(StreamKind.Video, 0, "FrameRate"));
FrameRateMode = mi.Get(StreamKind.Video, 0, "FrameRate_Mode");
ScanType = mi.Get(StreamKind.Video, 0, "ScanType");
}
}
public class AudioInfo
{
public string Codec { get; private set; }
public string CompressionMode { get; private set; }
public string ChannelPositions { get; private set; }
public TimeSpan Duration { get; private set; }
public int Bitrate { get; private set; }
public string BitrateMode { get; private set; }
public int SamplingRate { get; private set; }
public AudioInfo(MediaInfo mi)
{
Codec = mi.Get(StreamKind.Audio, 0, "Format");
Duration = TimeSpan.FromMilliseconds(int.Parse(mi.Get(StreamKind.Audio, 0, "Duration")));
Bitrate = int.Parse(mi.Get(StreamKind.Audio, 0, "BitRate"));
BitrateMode = mi.Get(StreamKind.Audio, 0, "BitRate_Mode");
CompressionMode = mi.Get(StreamKind.Audio, 0, "Compression_Mode");
ChannelPositions = mi.Get(StreamKind.Audio, 0, "ChannelPositions");
SamplingRate = int.Parse(mi.Get(StreamKind.Audio, 0, "SamplingRate"));
}
}
您可以通过调用Inform()
轻松获得字符串格式的所有信息:
You can easily obtain all information in string format by callingInform()
:
var mi = new MediaInfo();
mi.Open(@"video path here");
Console.WriteLine(mi.Inform());
mi.Close();
如果您需要有关可用参数的更多信息,只需调用Options("Info_Parameters")
即可简单查询所有参数:
if you need more information about available parameters, you can simply query all of them by calling Options("Info_Parameters")
:
var mi = new MediaInfo();
Console.WriteLine(mi.Option("Info_Parameters"));
mi.Close();
这篇关于使用C#从ASP.Net MVC中的视频文件中获取视频元数据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!