C# Reading Video / Audio / Image file metadata from a stream

2.2k views Asked by At

I'm currently looking to write an AWS Lambda function in C#

  1. File uploaded to S3 triggers my Lambda
  2. Lambda to interrogate file and get technical metadata about video codecs, frame rates, audio channels, duration
  3. Lambda to post that data to another service

I've taken a look at MediaInfo and FFMPeg wrappers on Nuget but the issue is they all accept FilePaths to open the file whereas in S3 / Lambda land I'm working with streams.

I don't want to create an EFS to temporarily store the file as it seems overkill and I don't think the library should need to read the entire stream to get the metadata either.

Essentially what I would like to do is similar to this but I'm a .net guy and would rather not learn Python / Docker / Linux etc...

3

There are 3 answers

0
SuRGeoNix On

To ensure that you will support all the formats (demuxers/codecs) I would use FFmpeg.Autogen .NET bindings with FFmpeg win builds. Then you can get all the information that you require for all the streams (including codecs & metadata).

(Not familiar with AWS lambda so not sure if that will work)

5
Jérôme Martinez On

You can use MediaInfo library from C#, the DLL without installer has the C# binding and there is also a C# MediaInfo binding example, which provide information about how to use MediaInfo library either by providing a URL (HTTP, FTP, S3...) or by buffer (you get yourself the content, in C#, as you are the only one who knows how to get the stream) the buffer data from your stream, and send buffer data to MediaInfo; MediaInfo says when it does not need any more data, so no read of the entire stream).

Jérôme, developer of MediaInfo

0
flip On

Just want to add here as I have spend a good few hours on this (although the documentation is okay, I feel it would benefit a reorg).

For C# framewrok:

  1. Download DLL and put on debug folder
  2. Download the wrapper class wrapper cs and put it on your project
  3. For S3, you need the libcurl.dll on bin/debug folder too.
  4. Test code:

using System.IO;
using MediaInfoLib;

namespace MediaInfoNetFramework
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var purl = "https://presignedS3URL";

            MediaInfo MI = new MediaInfo();

            MI.Open(purl);
            MI.Option("Complete");
            var x = MI.Inform();
            MI.Close();

            return;
        }
    }
}

Notes:

  1. You can have the DLLs in bin folder, include in project, and on properties, copy to output. That way they allways get copied to the debug/release folder.
  2. If on runtime it says mediainfo could not be loaded, try the other 32 or 64 bit DLL.