Reputation: 95
This question is about a asp.net WEB Application and not about .net windows application. In my application I am uploading video files (mp4) using asp.net core.
I need to get metadata from this video file, but for now I am focusing on the duration of this video file.
I have created the form and in my controller I am successfully receiving an IFormFile file
object. I can find the size the file by just calling the .length method ( file.Length
) but I am really struggling to get the exact date and especially the duration of this object.
How can I determine the exact date and the duration of this object?
This is my code:
public async Task UploadVideos(IList<IFormFile> files)
{
long size = files.Sum(f => f.Length);
Console.WriteLine("The size of all the selected files is:"+size);
Console.WriteLine("the file name is" + files[0].FileName);
string type = files[0].ContentType;
if (type.Equals("video/mp4"))
{
Console.WriteLine("Indeed a mp4 format");
}
}
Upvotes: 1
Views: 7271
Reputation: 1307
Sorry for the late reply, here is how you would go about getting the duration of a video after it is uploaded,
You can use NReco,the provided link has a nice little example on how to get the info of a video,
var ffProbe = new NReco.VideoInfo.FFProbe();
var videoInfo = ffProbe.GetMediaInfo(pathToVideoFile);
Console.WriteLine(videoInfo.FormatName);
Console.WriteLine(videoInfo.Duration);
The the only issue being licensing for commercial use.
The other one you can try is the mediatoolkit, I have used this before and it works great, especially for the functionality that you are looking for, a simple usage would be along the lines of
var inputFile = new MediaFile { Filename = video_name };
using (var engine = new Engine())
{
engine.GetMetadata(inputFile);
}
A sample image shows the output of calling the getmetadata method,
.
MediaToolkit uses an MIT license
All the above are wrappers of the c++ FFmpeg Library
Upvotes: 7