Search code examples
videoasp.net-coreazure-blob-storagequicktimeazure-media-services

Efficient method to determine video encoding of upload to Azure Blob in ASP .Net Core 2


Our SPA uploads cell phone videos. Newer iPhones upload videos in .Mov container with H.265 under some circumstances which chrome doesn't play natively.

We are using Azure Media Services to perform the transcoding. Potential solutions are:

  1. Use Azure Media Services / Azure Blob functionality. FetchAttributesAsync doesn't contain codec information.. Hanven't found any other applicable mehod.
  2. I am only concerned with if == H.264 || if != H.265. Use knowledge of the .Mov Container and download using CloudBlockBlob.DownloadRangeToStream() or intercept the iFormFile Stream on upload and read the specific bytes(FOURCCs?) to make determination.

Holding the entire video in server memory is not an option.

Any direction is appreciated.


Solution

  • If the goal is to decide whether or not to encode the source MOV, based on video codec, then you could implement the following:

    1. User uploads the MOV file

    2. Upon upload complete, Event Grid topic on Azure Storage fires an event

    3. An Azure Function is the event handler/subscriber receiving the event

    4. That Function then (a) Determines that this is a new video upload, (b) Creates a SAS URL for the video, (c) Runs ffprobe to determine the video codec, (d) If H.265 then submits an encoding Task

    Note: if you don't want to use ffprobe, then you can submit a Thumbnail task on the source video. This will be a low cost job, and the output Asset will contain the input metadata XML file which can be parsed to determine the codec. In my comment above, I've provided a link to the schema for this XML file.

    Hope this helps!