[英]Convert MP4 to Ogg with C#
Does anyone know a simple way of converting a mp4 file to an ogg file? 有谁知道将mp4文件转换为ogg文件的简单方法?
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 提前致谢
I would recommend dispatching this to FFMPEG - http://www.ffmpeg.org/ - using a Process and command line arguments. 我建议使用“ 进程”和命令行参数将其分发给FFMPEG- http ://www.ffmpeg.org/。 You can redirect I/O if you need to (eg logging).
您可以根据需要重定向I / O(例如,日志记录)。 Just do something like process.WaitForExit() after you've started it.
启动它后,只需执行类似process.WaitForExit()的操作即可 。 You could do this on a background thread ( BackgroundWorker , ThreadPool , etc...) if you need to not block the UI.
如果不需要阻止UI,则可以在后台线程( BackgroundWorker , ThreadPool等)上执行此操作。
Extending Chad's answer I used the NReco.VideoConverter which is a helpful wrapper for FFMPEG . 扩展乍得的答案,我使用了NReco.VideoConverter,它是FFMPEG的有用包装器 。 My code to convert a MP4 to OGG is as follows.
我将MP4转换为OGG的代码如下。
1.Save the file to a temporary file in local storage. 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.Now use the video converter to convert the file, simple! 2.现在使用视频转换器转换文件,简单!
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 from 如何将mp4文件转换为ogg文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.