Convert to wave file gives COMException
Hello! I have rest API using ASP.NET Core app .net 7 and I'm trying to convert a WebM file into a wav file in runtime,
I'm using NAudio and this code :
using (var reader = new MediaFoundationReader(WebMFilePath))
{
WaveFileWriter.CreateWaveFile(WaveFilePath, reader);
}
This works perfectly locally. But when I deploy and run it gives me this exception:
"error": { "message": "The data specified for the media type is invalid, inconsistent, or not supported by this object. (0xC00D36B4)", "exception": "COMException" }
I have no clue on what to do with it or how to move forward.
Any help is appreciated 🙏
21 Replies
This works perfectly locally. But when I deploy and run it in Chrome.. run it in chrome? As a blazor app? always include project type and .NET version when opening a thread btw
Right sorry. It's a rest API. Using .net 7. The WebM is sent from a react web app. But when I think about it, that is kinda irrelevant. I'm removing that part from the question. Thanks for the input
Ah okay so the C# code pasted above runs in an ASP.NET Core app?
but not a wasm blazor
COMException...
I wonder if it has to do with the target framework host
Yes exactly. That would be good info to have in the post 😅
you say it works locally, but not deployed.
is your local machine a windows OS, and the deployment host is linux?
I think both are windows. I'm at least using Windows locally and the Operating System is Windows in Azure. But not sure if that is what you are asking 🤔
okay, then I dunno tbh
Yeah... Me and my team is also kinda out of ideas
maybe some missing codec or something on the host? I dont know how NAudio works internally
mmm, maybe. It definitely feels like it's something with the host
ah yep
I just googled it.
MediaFoundation
is a windows subsystem that uses codecs
MediaFoundationEncoder.SelectMediaType
use that and pass in webm, if you get a non-null result back you have the right codecMmm, okej. I will try that after lunch. Thanks for the help!
you'll very likely get a null on the server, but a non-null locally. so it wont fix your issue, but it will explain why
Can you send me that link, Not really sure what you meant I should do😅
How to Encode MP3s with NAudio MediaFoundationEncoder
Mark Heath's Development Blog
Determining Codec Availabilityis the part you want to look at
Thanks! I will give that a try
it seems to be non-null even on the server 😅
did you pass the correct parameters thou?
that article wasn't about webm specifically
and webm is just a matroska container format
so you need to know what the actual format of your file is
I see. That changes things. How do I find out what format it is? Media info is just saying it's a webm file 🤔
open it in VLC and press CTRL+J
or https://mediaarea.net/en/MediaInfo
it is an Opus. I think...
I have never worked with media types before 😅