Create a silent audio CMSampleBufferRef

后端 未结 3 704
失恋的感觉
失恋的感觉 2021-01-12 10:20

How do you create a silent audio CMSampleBufferRef in Swift? I am looking to append silent CMSampleBufferRefs to an instance of AVAssetWriter

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-12 10:36

    You need to create a block buffer using CMBlockBufferCreateWithMemoryBlock(). Fill the block buffer with a bunch of zeros and then pass it into CMAudioSampleBufferCreateWithPacketDescriptions().

    Disclaimer: I haven't actually done this in Swift, I attempted it but found myself fighting the compiler at every turn so I switched to obj-c. The Core Media Framework is a low level C framework and was a lot easier to use without screwing around with Swifts type system. I know this isn't the answer you're looking for buy hopefully it will point you in the right direction.

    Example

提交回复
热议问题