0

I am using AVAssetWriter to create an MPEG4 file.

I start a video session with:

[assetWriter startSessionAtSourceTime:kCMTimeZero];

Now the video file is written fine if I finish the session with this:

[assetWriter finishWritingWithCompletionHandler:^{


     }];

But if I call [assetWriter endSessionAtSourceTime:endTime]; before [assetWriter finishWritingWithCompletionHandler then it doesn't write the file.

This is how I call endSessionAtSourceTime:

endTime = CMTimeMakeWithSeconds(secondsRecorded, 30);
    [assetWriter endSessionAtSourceTime:endTime];

Any ideas what i am doing wrong?

Ian
  • 1,221
  • 1
  • 18
  • 30
Zigglzworth
  • 6,645
  • 9
  • 68
  • 107

1 Answers1

0

I think the issue is that the behavior of endSessionAtSourceTime: doesn't do what you're expecting.

endSessionAtSourceTime: is almost the same thing as calling finishRecording() in that it stops the recording when called. The difference is that after recording, endSessionAtSourceTime: will edit out (remove) any frames received after the specified sourceTime.

Instead, if your intended result is to record a 30second clip, you need to setup an NSTimer or something similar and then call endSessionAtSourceTime: or finishRecording() when the 30 seconds has elapsed

johnnyclem
  • 3,284
  • 1
  • 17
  • 14