Saving video from CMSampleBuffer while streaming using ReplayKit

前端 未结 3 975
挽巷
挽巷 2020-12-29 17:41

I\'m streaming a content of my app to my RTMP server and using RPBroadcastSampleHandler.

One of the methods is

override func processSampleBuffer(_ s         


        
3条回答
  •  误落风尘
    2020-12-29 18:17

    @Marty's answer should be accepted because he pointed out the problem and its DispatchGroup solution works perfectly.
    Since he used a while loop and didn't describe how to use DispatchGroups, here's the way I implemented it.

    override func broadcastFinished() {
        let dispatchGroup = DispatchGroup()
        dispatchGroup.enter()
        self.writerInput.markAsFinished()
        self.writer.finishWriting {
            // Do your work to here to make video available
            dispatchGroup.leave()
        }
        dispatchGroup.wait() // <= blocks the thread here
    }
    

提交回复
热议问题