Search code examples
.netazureencodingazure-blob-storageazure-media-services

Azure Media Services: Get the duration of a video that needs to be encoded


Is it possible to get the duration of a video using Azure Media Services .NET SDK before creating an encoding job? I have a requirement to ignore encoding requests if the duration exceeds a threshold. The blob is uploaded with a SAS token, and unfortunately the tokens can't enforce this restriction, so I have to do validation on the server side.


Solution

  • Unfortunately no, we dont have an API to "probe" a file in storage or at a remote URL. However... that said, there is a way to do that. I've seen folks build an Azure Function that just hosts FFProbe or MediaInfo.exe to do that really quick. There may even be samples of that out there that you could find.

    For example, here is one we made to use ffmpeg.exe, which you could modify to use ffprobe.exe https://github.com/Azure-Samples/media-services-v3-dotnet-core-functions-integration/blob/master/Encoding/Encoding/VodFunctions/ffmpeg-encoding.cs