本文介绍了在ASP.Net MVC中使用C#从MP4文件获取视频元数据的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google和StackOverflow上搜索了好几个小时。在StackOverflow上似乎有很多类似的问题,但是它们大概是3-5岁。



现在使用FFMPEG还是最好的方式来从.NET Web应用程序中的视频文件?如果是这样,最好的C#包装在那里?



我尝试过MediaToolkit,MediaFile.dll没有任何运气。我看到ffmpeg-csharpe,但看起来它几年没有被触及。



我没有发现任何关于这个问题的当前数据。是否有能力从内置于最新版本的.NET中的视频中提取元数据?



我基本上正在寻找任何方向。



我应该补充说,无论我使用什么都可以每小时调用数千次,因此需要高效。

看看 MediaInfo 项目()



它获取大多数媒体类型的大量信息,该库与ac#helper类捆绑在一起很容易使用。



您可以从这里下载Windows的图书馆和助手类:



(不带安装程序的DLL)



助手类位于 Developers\Source\MediaInfoDLL\MediaInfoDLL.cs ,sim ply将其添加到您的项目中,并将 MediaInfo.dll 复制到您的bin。



strong>



您可以通过从库中请求特定参数来获取信息,以下是一个示例:

  [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;私人集}
public int Width {get;私人集}
public int Heigth {get;私人集}
public double FrameRate {get;私人集}
public string FrameRateMode {get;私人集}
public string ScanType {get;私人集}
public TimeSpan Duration {get;私人集}
public int Bitrate {get;私人集}
public string AspectRatioMode {get;私人集}
public double AspectRatio {get;私人集

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));
持续时间= 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;私人集}
public string CompressionMode {get;私人集}
public string ChannelPositions {get;私人集}
public TimeSpan Duration {get;私人集}
public int Bitrate {get;私人集}
public string BitrateMode {get;私人集}
public int SamplingRate {get;私人集

public AudioInfo(MediaInfo mi)
{
Codec = mi.Get(StreamKind.Audio,0,Format);
持续时间= 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()

  var mi = new MediaInfo(); 
mi.Open(@video path here);
Console.WriteLine(mi.Inform());
mi.Close();

如果您需要有关可用参数的更多信息,可以通过调用选项(Info_Parameters)

  var mi = new MediaInfo(); 
Console.WriteLine(mi.Option(Info_Parameters));
mi.Close();


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.

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?

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.

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.

解决方案

Have a look at MediaInfo project (http://mediaarea.net/en/MediaInfo)

it gets extensive information about most media types, and the library is bundled with a c# helper class which is easy to use.

You can download the library and helper class for windows from here:

http://mediaarea.net/en/MediaInfo/Download/Windows (DLL without installer)

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.

Usage

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"));
    }
}

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();

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();

这篇关于在ASP.Net MVC中使用C#从MP4文件获取视频元数据的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 03:56