4

Is it possible to clip video files while continuos recoding? What I am looking for is say I record a video, I want to send video clips to a server every 5 seconds until the recording is being stopped. For example a video file is recorded for 10 seconds. I want to send 2 video files each of 5 seconds duration. The 1st file is sent while the video continuous to get recorded for the next 5 seconds.

2 Answers 2

1

Take a look at this tutorial:

http://www.ios-developer.net/iphone-ipad-programmer/development/camera/record-video-with-avcapturesession-2

You set up your preview display (if you need one). You set up your record/stop button. When user presses start recording you use

[MovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];

and every X seconds you do:

[MovieFileOutput stopRecording];
// setting up the url ...
[MovieFileOutput startRecordingToOutputFileURL:nextOutputURL recordingDelegate:self];

Voila! You have a lot of X second files and you can do anything you want with them.

The preview display doesn't show that there was some kind of stop, the same with record buttons.

1
  • 1
    Both of these answers leave a tiny bit of missing time between recordings. When assembling the video afterwards, it is not a natural experience. every X seconds has some missing milliseconds.. Aug 2, 2021 at 14:25
0

This is the correct way to record a video in 5 second clips.

Record button is pressed and you start recording the first video clip to a URL.

[MovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];

Set a 5 second timer when the record button is pressed.

[NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(stopRecording) userInfo:nil repeats:YES];

-(void)stopRecording
{
    [MovieFileOutput stopRecording];
}

This is where you want to start recording the next video clip. This method is called immediately after the first clip is stopped.

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
{
    NSLog(@"end record");
    [MovieFileOutput startRecordingToOutputFileURL:[self getNextURL] recordingDelegate:self];
}

Generate a new URL for the next clip.

-(NSURL*) getNextURL
{
    videoNumber++;
    NSString *outputPath = [self getTempVideoOutputPath:videoNumber];
    NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];

    return outputURL;
}

Pass in the clip number to create a new temp URL. For example, this method will create video files clip-1.mov, clip-2.mov, clip-3.mov etc.

-(NSString*)getTempVideoOutputPath: (int) clipNumber
{
    //Create temporary URL to record to
    NSString *outputFileName = [NSString stringWithFormat:@"clip-%i.mov",clipNumber];
    NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), outputFileName];

    return outputPath;
}
1
  • 1
    Both of these answers leave a tiny bit of missing time between recordings. When assembling the video afterwards, it is not a natural experience. every X seconds has some missing milliseconds.. Aug 2, 2021 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.