Pause & resume video capture for same file with AVFoundation in iOS

。_饼干妹妹 提交于 2020-01-01 04:58:09

问题


I'm trying to figure out how I can implement functionality to repeatedly pause and resume video capture in a single session, but have each new segment (the captured segments after each pause) added to the same video file, with AVFoundation. Currently, every time I press "stop" then "record" again, it just saves a new video file to my iphone's album and starts capturing to a separate/new file. I need to be able to press the "record/stop" button over and over... only capture video & audio when record is active... then when the "done" button is pressed, have a single AV file with all the segments together. And all this needs to happen in the same capture session / preview session.

the only way I can think of to try this is when the "done" button is pressed, taking each individual output file and combining them together into a single file... But im pretty sure the processing time to basically paste a bunch of separate clips together won't be acceptable. Plus, it just seems like this will be a really messy & unnecessary way to go about this, with way too much code.

Is there any simple way to just pause video capture within a single session and simply resume capture to the same file? Or any other ideas?

If it's not too much trouble, sample code would help me out a ton... I'm still learning & teaching myself, so I'm not great with following the lingo & terminology in explanations. Thanks

edit: this is the project I am starting with to learn AVFoundation... so this is the code I am looking to alter to achieve the above functionality: http://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html


回答1:


Instead of using the movie file output from the capture session, you could use AVCaptureVideoDataOutput and in your delegate, pass the samples to an instance of AVAssetWriterInput. Then you could decouple the previewing from the recording. If your delegate does not forward the buffers to the asset writer, there's no recording for that portion.

When you wanted to start recording a second (and subsequent) session to the same file, you would need to adjust the timestamps so that they are sequential from the point at which you stopped, and you'd need to ensure that you make the same adjustment to both audio and video so they stay in sink. So a little fiddly, but certainly workable.

Edit: there's a sample iPhone app that demonstrates this at http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html

G




回答2:


In general, I use startRunning and stopRunning if I am using AVCaptureSession. I am assuming you will.

See the documentation for AVCaptureSession.



来源:https://stackoverflow.com/questions/14905892/pause-resume-video-capture-for-same-file-with-avfoundation-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!