如何在C#中剪切,编辑和合并OGG文件? [英] How to cut, edit and merge OGG files in C#?

查看:109
本文介绍了如何在C#中剪切,编辑和合并OGG文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ogg vorbis文件,我必须对其进行两项操作:

I have an ogg vorbis file and I have to do two operations with it:

  1. 将文件的一部分从一个位置剪切到另一个位置
  2. 与现有文件合并另一个文件

如何在C#中执行这两项操作?

How can I do these two operations in C#?

推荐答案

我将研究libogg的c文档,并弄清楚如何使用c做到这一点.然后使用libogg上的包装器在C#中编写几乎相同的代码.

I'd look into the c documentation for libogg, and figure out how to do this with c. And then write almost the same code in C# using a wrapper over libogg.

我使用互操作助手在libogg和libvorbis上创建了一个低层包装器: https://github.com/CodesInChaos/Xiph/blob/master/LowLevel.cs

I've created a low level wrapper over libogg and libvorbis using the interop assistant: https://github.com/CodesInChaos/Xiph/blob/master/LowLevel.cs

该项目还包含一些更高层次的结构,但我认为它们对您的工作不会有用.

That project also contains some higher level constructs, but I don't think they'll be useful for what you're doing.

顺便说一句,如果文件之间的流ID不同,则可以简单地将一个文件追加到另一个文件,以创建一个有效文件,该文件依次播放两个流.

BTW if the stream IDs between the files differ, you can simply append a file to another creating a valid file that plays both streams in sequence.

您可能需要使用解码API逐包读取输入文件,然后将组合数据逐包写出.可能会在两者之间替换流ID和granulepos.

You probably need to read the input files packet wise using the decoding API, and then write the combined data out packet wise. Possibly replacing the stream ID and granulepos in between.

StreamID是一个整数,用于标识ogg文件中的子流.要附加多个此类子流,您只需确保它们具有不同的ID,然后写入数据即可.

StreamID is an integer that identifies substreams in an ogg file. To append multiple such substreams you can simply ensure that they have a different ID and then write the data.

拆分比较烦人,因为granulepos是依赖编解码器的时间戳,而且我不记得它是如何为vorbis定义的.这里的另一个问题是,您不能在不重新编码的情况下简单地在数据包中间进行拆分.

Splitting is a bit more annoying, since granulepos is a codec dependent timestamp, and I don't remember how it is defined for vorbis. Another problem here is that you can't simply split in the middle of a packet without reencoding.

这篇关于如何在C#中剪切,编辑和合并OGG文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆