1

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

    }
Richard Chambers
  • 16,643
  • 4
  • 81
  • 106

1 Answers1

6

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, Video Data.

MediaToolkit uses an MIT license

All the above are wrappers of the c++ FFmpeg Library

mahlatse
  • 1,322
  • 12
  • 24
  • 1
    Ohh I simply can't thank you enough. Both work fine when the files are local but when I am giving a path from url (in my case I am using azure blob Storage), only the first works. I also had to dowload the ffprobe.exe file from here (https://ffbinaries.com/downloads ) and add it in the project folder. However, I needed a lot more metadata from videos so in the end I am using Media Info ( https://stackoverflow.com/questions/26051273/whats-the-best-way-to-get-video-metadata-from-a-mp4-file-in-asp-net-mvc-using-c ). However, I am struggling to get it working with url and not only with local paths – Dimitris Selalmazidis Aug 01 '18 at 13:12
  • I am not sure about URL's, but maybe you can check this [Github](https://github.com/fcingolani/video-metadata-api) link out, its using ffprobe.exe to get metadata from a video – mahlatse Aug 01 '18 at 14:42