Question

Does anyone know a simple way of converting a mp4 file to an ogg file?

Have to do it, but don't have much knowlegde about it, and all I can find are programs, not examples or libraries.

Thanks in advance

Was it helpful?

Solution

I would recommend dispatching this to FFMPEG - http://www.ffmpeg.org/ - using a Process and command line arguments. You can redirect I/O if you need to (e.g. logging). Just do something like process.WaitForExit() after you've started it. You could do this on a background thread (BackgroundWorker, ThreadPool, etc...) if you need to not block the UI.

OTHER TIPS

Extending Chad's answer I used the NReco.VideoConverter which is a helpful wrapper for FFMPEG. My code to convert a MP4 to OGG is as follows.

1.Save the file to a temporary file in local storage.

var path = Path.GetTempPath() + name;
using (var file = File.Create(path))
{
 stream.Seek(0, SeekOrigin.Begin);
 await stream.CopyToAsync(file);
 file.Close();
 return path;
}

2.Now use the video converter to convert the file, simple!

var output = new MemoryStream();
var ffMpeg = new FFMpegConverter();
ffMpeg.ConvertMedia(filePath, output, Format.ogg);
output.Seek(0, SeekOrigin.Begin);
return output;
static void Mp4ToOgg(string fileName)
{
    DsReader dr = new DsReader(fileName);
    if (dr.HasAudio)
    {
        string waveFile = fileName + ".wav";
        WaveWriter ww = new WaveWriter(File.Create(waveFile),
            AudioCompressionManager.FormatBytes(dr.ReadFormat()));
        ww.WriteData(dr.ReadData());
        ww.Close();
        dr.Close();
        try
        {
            Sox.Convert(@"sox.exe", waveFile, waveFile + ".ogg", SoxAudioFileType.Ogg);
        }
        catch (SoxException ex)
        {
            throw;
        }

    }
}

from How to converts a mp4 file to an ogg file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top