You don't need any external library; you can use MediaTranscoder
A test :
// Add reference to C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd
// Add reference to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
string sInputFile = "E:\\Sources\\CSharp_ConvertToAAC\\sample_1280x720_surfing_with_audio.mp4";
string sOutputFile = "E:\\Sources\\CSharp_ConvertToAAC\\sample_1280x720_surfing_with_audio.m4a";
var cts = new CancellationTokenSource();
try
{
await ConvertToAacAsync(sInputFile, sOutputFile, cts.Token);
}
catch (TaskCanceledException)
{
System.Diagnostics.Debug.WriteLine("Conversion canceled.");
}
static async Task ConvertToAacAsync(string sInputFile, string sOutputFile, CancellationToken cancellationToken)
{
StorageFile inputFile = await StorageFile.GetFileFromPathAsync(sInputFile);
string sOutputFolderPath = System.IO.Path.GetDirectoryName(sOutputFile);
string sOutputFileName = System.IO.Path.GetFileName(sOutputFile);
StorageFolder outputFolder = await StorageFolder.GetFolderFromPathAsync(sOutputFolderPath);
StorageFile outputFile = await outputFolder.CreateFileAsync(sOutputFileName, CreationCollisionOption.ReplaceExisting);
var transcoder = new MediaTranscoder();
transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default; // No video processing needed
var profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateM4a(Windows.Media.MediaProperties.AudioEncodingQuality.High); // AAC inside .m4a container
var prepared = await transcoder.PrepareFileTranscodeAsync(inputFile, outputFile, profile);
if (!prepared.CanTranscode)
{
System.Diagnostics.Debug.WriteLine($"Transcoding not possible: {prepared.FailureReason}");
return;
}
System.Diagnostics.Debug.WriteLine("Conversion started...");
var progressHandler = new Progress<double>(progress =>
{
System.Diagnostics.Debug.WriteLine($"Progress: {progress}%");
});
await prepared.TranscodeAsync().AsTask(cancellationToken, progressHandler);
System.Diagnostics.Debug.WriteLine("Conversion completed!");
}