This post is about preparing videos for uploading to Azure media service and not so much about media services itself.
Since December I have been working on a solution that involves Azure media services. To my surprise it’s actually a lot easier to work with than I imagined, the biggest thing for me was to wrap my head around the different combinations and how tokens work with DRM content.
For Azure media services I mainly followed a code example created by Mingfei https://github.com/AzureMediaServicesSamples/Dynamic-Encryption-with-PlayReady. There are a lot of documentation regarding Azure media services so I’m not going to go in depth on it.
A big thing for me and also something I found very little info on was how to prepare my videos for upload. Azure media services accepts a lot of different file formats when uploading a video, but none supported the files I had.
The videos I was going to receive would have been in a RAW uncompressed AVI file format. These files are way too big to upload directly to Azure, and on my 4Mbps ADSL line it will take forever. Sure I can just use a video converter and batch convert them all to .MP4, but I need more control over the file conversion and be able to upload the file as soon as it’s converted along with some meta data to my own database.
After a thorough search I cam across a .Net wrapper for the FFMPEG library created by NReco http://www.nrecosite.com/video_converter_net.aspx
This library had everything I needed to start an application that can convert my videos and upload them to Azure as well as load the assets in my own database.
I wrote a little tool that looks something like this:

This allows me to load a folder full of raw files, add names/descriptions and tags for the files so that I can find them later on.
When you convert and upload the tool will convert the video and add it to the upload queue. While uploading a file it will start converting the next file in line and so on. Multi threading the convert/upload process saves a lot of time. If I had to 1st wait for a tool to convert all the files and upload them to Azure it would have been very painful.
To encode your own video files using NReco you can use the following code:
FFMpegConverter ffMpeg = new FFMpegConverter();
ffMpeg.ConvertProgress += new EventHandler<ConvertProgressEventArgs>(delegate (Object o, ConvertProgressEventArgs eP)
{
double percentage = ((eP.Processed.TotalMilliseconds / eP.TotalDuration.TotalMilliseconds) * 100);
});
//Start conversion
ffMpeg.ConvertMedia(SourcePath, null, DestinationPath, Format.mp4, new ConvertSettings()
{
AudioCodec = "libmp3lame",
VideoCodec = "h264",
VideoFrameSize = "1280x720"
});
After FFMpeg have finished converting the video to MP4, the file can then be uploaded to Azure media services as per the example by Mingfei.