2

I see there is an app called iFile with a pause feature while recording video. How do they do this? I tried using AVMutableComposition classes and when the user pauses i cut a new video and then merge the video at the end, however the processing time to merge the videos is not desirable.

Can someone give me other good ideas on how to do this? I noticed the iFile way is very seamless.

Thanks

Scoota P
  • 2,622
  • 7
  • 29
  • 45

1 Answers1

2

Here are some ideas. I have not tried either of these.

If you are using an AVAssetWriter to write your captured image then you can simply drop the frames while paused. You will need to keep track of the last presentation time stamp (PTS) that was used. Then you need to calculate the next image PTS based on this last time stamp when you start recording again. Doing this with audio as well might be a little trickier.

An alternate method would be to use empty edits. I am not sure how you would insert an empty edit in the middle of a track using AVAssetWriter. I know you can insert them at the beginning and end. Using AVMutableCompositionTrack you could use insertEmptyTimeRange: where the time range is constructed like

CMTime delta = CMTimeSubtract(new_sample_time, last_sample_time)
CMTimeRangeMake(last_sample_time, delta)

Where new_sample_time is the time of the first sample after un-pausing, and last_sample_time is the time of the last sample before pausing. Again with audio this may be a little tricky as the buffer for audio generally contains 1024 samples. The CMTime returned by CMSampleBufferGetPresentationTimeStamp is the time of the first sample.

Hope this helps or leads you to a solution.

Steve McFarlin
  • 3,576
  • 1
  • 25
  • 24
  • Thanks i am trying to AVAssetWriter, im getting close but for some reason the delegate isnt getting called passing the CMSampleBuffer frames. Do i call the [session startRunning] when i initialize my camera or when i want to start recording? When should startWriting on the AVAssetWriter? AFte the user stops recording or when the user starts recording? BAsically, i am trying to figure out how to "throw" away the frames. Any sample code would be great – Scoota P Apr 25 '11 at 15:39
  • OK it looks like i should be calling [session startRunning] when i initialize the camera and then when i want to start Recording then i would call the `[avAssetWriter startWriting]` and when i want to stop recording i would call the `[avAssetWriter finishWriting]`. Correct @SteveMcFarlin? – Scoota P Apr 25 '11 at 15:55
  • 1
    Not sure why this was down voted now. It is simply a suggestion and not a solution which should be clear. – Steve McFarlin Feb 26 '13 at 22:56
  • Should sample project this! Seems like there are still no nice and simple ways of doing this. Taking a thread approach vs merging multiple tracks. – jgvb Jun 23 '14 at 15:29