3

I am using javascript to capture audio data from MediaRecorder, and base64 encode it so I can send it back to the web server where it can be saved for later playback.

data:audio/webm;codecs=opus;base64,GkXfo59ChoEBQveBA...(too much data to post, but you get the idea)

I can put that data into an HTML5 audio element's .src field, and play it back on a Chrome browser just fine. But Safari can't handle the data in that format, I guess it doesn't support the opus codec.

One solution for me would be to figure out how to write the audio data into a properly formatted .webm container file, and then use ffmpeg.exe to convert it to some other Safari friendly format.

But I don't know the file format for .webm file - I'm looking for tips or guidance how to write such a .webm file.

Anybody have any suggestions, libraries, or tips to write data like above to a .webm file? I prefer a C# .net answer, but javascript will also do, or any examples are appreciated.

Bo A
  • 138
  • 9

1 Answers1

1

Well, I got a tip from smart developer (earnabler) that if I stripped off the header portion of the content:

"data:audio/webm;codecs=opus;base64,"

and decoded just the base64 portion:

"GkXfo59ChoEBQveBA...(too much data to post, but you get the idea)"

...back to binary (example in C#):

byte[] decodedBinaryData;

decodedBinaryData = Convert.FromBase64String(encodedBase64String);

...and wrote that binary to a file with a matching file extension (.webm in this example), that the file would be a properly formatted file of that type understandable by other media software.

Lo and behold, it was! I could play the file in MediaPlayer, or QuickTime, or whatever, and could use FFMPEG to convert it to other types.

So that gives me a pathway to save/use/convert the media in many ways. Problem solved.

Bo A
  • 138
  • 9