如何在C#中剪切、编辑和合并OGG文件?
我有一个 ogg vorbis 文件,我必须对其执行两项操作:
- 将文件的一部分从一个位置剪切到另一个位置
- 将另一个文件与现有文件合并
如何在 C# 中执行这两项操作?
I have an ogg vorbis file and I have to do two operations with it:
- Cutting a part of a file from one position to another
- Merging another file with existing one
How can I do these two operations in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 libzplay http://libzplay.sourceforge.net/ 来完成此操作
执行所询问的操作所需的步骤:
格式)
所有内容都在链接网站上以多种语言(包括 c#)详细记录。
这个答案适用于所有其他花了几个小时搜索但没有从以前的答案中得到帮助的人。这不是解决这里问题的非常有效的解决方案,但是在搜索时多次出现这个问题,这可能对其他人有帮助。 :)
You can do this with libzplay http://libzplay.sourceforge.net/
The steps needed to do what is being asked about:
formats)
Everything is extremely well documented on the linked site for multiple languages, including c#.
This answer is for all the other people that spent hours searching and weren't helped by the previous answers. This isn't a very efficient solution to the problem here, but while searching this question came up many times, and this might be helpful to others. :)
我会查看 libogg 的 c 文档,并找出如何使用 c 来做到这一点。然后使用 libogg 上的包装器在 C# 中编写几乎相同的代码。
我使用互操作助手创建了 libogg 和 libvorbis 的低级包装器:
https://github.com/CodesInChaos/Xiph/blob/master/LowLevel.cs
该项目还包含一些更高级别的构造,但我认为它们对您正在做的事情没有用处。
顺便说一句,如果文件之间的流 ID 不同,您可以简单地将一个文件附加到另一个文件,创建一个按顺序播放两个流的有效文件。
您可能需要使用解码 API 按数据包读取输入文件,然后按数据包写出组合数据。可能会替换中间的流 ID 和 capsulepos。
StreamID 是一个整数,用于标识 ogg 文件中的子流。要附加多个此类子流,您只需确保它们具有不同的 ID,然后写入数据即可。
分割有点烦人,因为 capsulepos 是一个依赖于编解码器的时间戳,而且我不记得它是如何为 vorbis 定义的。这里的另一个问题是,您不能简单地在数据包中间分割而不重新编码。
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.
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.
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.
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 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.
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.