C
C#12mo ago
Lexan

Convert files from ogg to wav

Hello! I'm using this code to convert a ogg audio file in to a wave audio file. And that works great if the file was downloaded from firefox but not if it's from crome or explorer. The file seem to be 2000 bytes smaller when they are from crome and explorer but I don't know why or how to account for that. Anyone have a idea on a workaround?
using (FileStream fileIn = new FileStream(oldPath, FileMode.Open)) using (MemoryStream pcmStream = new MemoryStream()) { OpusDecoder decoder = OpusDecoder.Create(48000, 1); OpusOggReadStream oggIn = new OpusOggReadStream(decoder, fileIn); while (oggIn.HasNextPacket) { short[] packet = oggIn.DecodeNextPacket(); if (packet != null) { for (int i = 0; i < packet.Length; i++) { var bytes = BitConverter.GetBytes(packet[i]); pcmStream.Write(bytes, 0, bytes.Length); } } } pcmStream.Position = 0; var wavStream = new RawSourceWaveStream(pcmStream, new WaveFormat(48000, 1)); var sampleProvider = wavStream.ToSampleProvider(); WaveFileWriter.CreateWaveFile16(newPath, sampleProvider); }
6 Replies
Omnissiah
Omnissiah12mo ago
i would run mediainfo on the two converted files
Lexan
LexanOP12mo ago
Thanks! Never used that software but that looks great.
Omnissiah
Omnissiah12mo ago
it's just to understand if there's a difference in duration, or maybe one has metadata that the other one doesn't have, or whatever it could be
Lexan
LexanOP12mo ago
yeah, I just got a lot more info to work with. So I can try a lot more now. And not just shot in the dark Thanks for the help!
Chiyoko_S
Chiyoko_S12mo ago
ffmpeg? blobpeek not if it's part of some application that you intend to deploy somewhere but but it'd be much more flexible
Lexan
LexanOP12mo ago
I made it work. They was of a different file type.
Want results from more Discord servers?
Add your server