简体   繁体   English

iOS视频录制

[英]iOS video recording in chunks

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. 我要寻找的是说我录制了视频,我想每5秒将视频片段发送到服务器,直到停止录制。 For example a video file is recorded for 10 seconds. 例如,视频文件录制了10秒钟。 I want to send 2 video files each of 5 seconds duration. 我想每5秒发送2个视频文件。 The 1st file is sent while the video continuous to get recorded for the next 5 seconds. 在连续播放视频的同时发送第一个文件,以便在接下来的5秒钟内进行录制。

Take a look at this tutorial: 看一下本教程:

http://www.ios-developer.net/iphone-ipad-programmer/development/camera/record-video-with-avcapturesession-2 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: 每执行X秒:

[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. 您有X个第二个文件,可以对它们进行任何操作。

The preview display doesn't show that there was some kind of stop, the same with record buttons. 预览显示不显示有某种停止,与录制按钮相同。

This is the correct way to record a video in 5 second clips. 这是在5秒的剪辑中录制视频的正确方法。

Record button is pressed and you start recording the first video clip to a URL. 按下“录制”按钮,您便开始将第一个视频剪辑录制到URL。

[MovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];

Set a 5 second timer when the record button is pressed. 按下录制按钮时,设置5秒定时器。

[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. 为下一个剪辑生成一个新的URL。

-(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. 传入片段编号以创建新的临时URL。 For example, this method will create video files clip-1.mov, clip-2.mov, clip-3.mov etc. 例如,此方法将创建视频文件clip-1.mov,clip-2.mov,clip-3.mov等。

-(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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM