使用 C# 将 MP4 转换为 Ogg

发布于 2024-09-06 18:07:42 字数 91 浏览 1 评论 0原文

有谁知道将 mp4 文件转换为 ogg 文件的简单方法?

必须这样做,但对此没有太多了解,我能找到的只是程序,而不是示例或库。

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

几味少女 2024-09-13 18:07:43

我建议将其发送到 FFMPEG - http://www.ffmpeg.org/ - 使用 进程 和命令行参数。如果需要(例如日志记录),您可以重定向 I/O。只需在启动后执行 process.WaitForExit() 之类的操作即可。您可以在后台线程上执行此操作(BackgroundWorkerThreadPool 等...)如果您不需要阻止 UI 。

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.

天暗了我发光 2024-09-13 18:07:43

扩展Chad的答案我使用了NReco.VideoConverter,它是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;

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;
若水微香 2024-09-13 18:07:43
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;
        }

    }
}

来自如何将 mp4 文件转换为 ogg 文件

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文