How to cut, edit and merge OGG files in C#?

前端 未结 2 709
深忆病人
深忆病人 2021-02-10 13:04

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

  1. Cutting a part of a file from one position to another
  2. Merging another file with existing
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-10 13:37

    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.

提交回复
热议问题