Is MediaTranscoder supported in Azure Cloud Functions?

Tomoyuki Hayasaka 20 Reputation points
2024-08-29T04:58:23.4233333+00:00

Hi,

We want to know whether MediaTranscoder (link) in C# can be used on Azure Functions.

We are trying to convert videos into WMV files. They need to be Windows Media Video 9 (WMV3), which is not supported in tools like ffmpeg and major cloud media encoding services (as far as we know).

We recently found that MediaTranscoder in Windows.Media.Transcoding (under WinRT API) can output WMV3, so we are now trying to build a converter service on Azure Functions with Windows deployment using C# / .NET8 isolated. It works perfectly on debugging locally, but it gets UnauthorizedAccessException error on the actual Azure Functions on cloud.

System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.

First we thought it was just a read / write permission issue, but our investigation showed there's no problem with reading / writing files. Instead, the exception is thrown when PrepareFileTranscodeAsync() is called. Now we are suspecting that MediaTranscoder (and maybe all WinRT APIs?) is not supported in Azure Functions.

snippets:

            MediaTranscoder transcoder = new MediaTranscoder();
			string sourcePath = "path_to_input.mp4";
            string destinationPath = "path_to_temp_dir";
            var source = await StorageFile.GetFileFromPathAsync(sourcePath);
            StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(destinationPath);
            StorageFile destination = await folder.CreateFileAsync("out.wmv", Windows.Storage.CreationCollisionOption.ReplaceExisting);
            PrepareTranscodeResult prepareOp = await
                transcoder.PrepareFileTranscodeAsync(source, destination, profile);
            if (prepareOp.CanTranscode)
            {
                await prepareOp.TranscodeAsync();
       		}

We currently use .NET8 isolated and net8.0-windows10.0.22000.0 as TargetFramework. We already tried other neighbor versions but no luck.

	<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>

Is it impossible to use MediaTranscoder on Azure Functions?

Is there any alternative solution?

Thanks!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,978 questions
Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Gowtham CP 4,820 Reputation points
    2024-08-30T03:49:24.6766667+00:00

    Hi Tomoyuki Hayasaka ,

    Thanks for reaching out on Microsoft Q and A.

    Unfortunately, MediaTranscoder isn’t supported in Azure Functions because it's a WinRT API meant for UWP apps, and Azure Functions operate in a sandboxed environment that restricts access to such APIs. However, you can still handle video conversion with Azure Media Services, which provides robust support for a variety of video formats, including WMV. Alternatively, you might use third-party libraries like FFmpeg.NET, though you'll need to check for licensing and compatibility issues.

    I hope this helps! If you found this answer useful, please consider accepting and upvoting it to close the thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.