2

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...

CianM
  • 397
  • 5
  • 17

3 Answers3

2

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

Jérôme Martinez
  • 1,118
  • 5
  • 10
  • Thanks Jerome, I will check that out tomorrow and update the post if I get it working! – CianM Oct 17 '20 at 08:11
  • Hi Jerome, I've gotten the code working now on my local machine. I'm targeting .Net Core 3.1 so I've used the nuget package MediaInfo.Wrapper.Core. The issue I am having is that when the code is uploaded to AWS Lambda I get "Unable to load MediaInfo library". Under what circumstances is this error message returned? I can see the MediaInfo.Wrapper.Core.dll in my bin and I know its in the zipped package that goes to AWS Lambda which also targets .Net Core 3.1. Any ideas? – CianM Oct 20 '20 at 10:09
  • We don't develop the nuget package MediaInfo.Wrapper.Core, so you need to ask their developer. the "Unable to load MediaInfo library" error is when the library (.dll, .so...) is not found by your software, it is your responsibility to make your software point to the MediaInfo location. FYI there is a ready to use MediaInfo Lambda at https://mediaarea.net/MediaInfo/Download/Lambda (not C# though). – Jérôme Martinez Oct 20 '20 at 14:21
  • Thanks Jerome, is there any documentation on how that lambda layer is uploaded and subsequently used? I'm sure my C# function could simply call into it but I can't find any info / examples on how to use the lambda layer on your site. – CianM Oct 20 '20 at 22:53
  • This is a classic binary (executable or library .so) built for compatibility (all dependencies are included) with AWS Lambda, after that this is classic AWS Lambda management (the binary need to be called, either through system call or from the library interface), nothing specific to MediaInfo. I am not the one who developed and I'll see for adding a basic example of AWS Lambda usage. – Jérôme Martinez Oct 21 '20 at 05:31
0

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)

SuRGeoNix
  • 482
  • 1
  • 3
  • 10
0

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.
flip
  • 99
  • 6