2010-06-22 124 views
1

有誰知道將mp4文件轉換爲ogg文件的簡單方法嗎?用C轉換MP4到Ogg#

必須這樣做,但沒有太多的知識,而我所能找到的只是程序,而不是示例或庫。

在此先感謝

回答

1
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; 
     } 

    } 
} 

How to converts a mp4 file to an ogg file

4

擴展乍得的回答我用NReco.VideoConverter which is a helpful wrapper for FFMPEG。我將MP4轉換爲OGG的代碼如下。

1.將文件保存到本地存儲器中的臨時文件。

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.現在使用視頻轉換器來轉換文件,很簡單!

var output = new MemoryStream(); 
var ffMpeg = new FFMpegConverter(); 
ffMpeg.ConvertMedia(filePath, output, Format.ogg); 
output.Seek(0, SeekOrigin.Begin); 
return output;