Приостановите и возобновите захват видео, используя AVCaptureMovieFileOutput и AVCaptureVideoDataOutput в iOS
Я должен реализовать функциональность, чтобы многократно приостанавливать и возобновлять захват видео в одном сеансе, но каждый новый сегмент (захваченные сегменты после каждой паузы) добавлялся в один и тот же видеофайл сAVFoundation
, В настоящее время каждый раз, когда я нажимаю "стоп" затем "запись» опять же, он просто сохраняет новый видеофайл на моем iPhone 's Каталог документов и начинает запись в новый файл. Мне нужно быть в состоянии нажать "запись / стоп» кнопка, только захват видео и звук, когда запись активна ... тогда, когда "сделанный" кнопка нажата, есть один AV-файл со всеми сегментами вместе. И все это должно происходить в одном сеансе захвата / предварительного просмотра.
Я не использую.AVAssetWriterInput
Единственный способ попробовать это - это когдасделанный" Нажмите кнопку, взяв каждый отдельный выходной файл и объединив их в один файл.
Этот код работает для iOS 5, но не для iOS 6. На самом деле для iOS 6, первый раз, когда я приостанавливаю запись (остановить запись)AVCaptureFileOutputRecordingDelegate
метод (captureOutput: didFinishRecordingToOutputFileAtURL: fromConnections: error:
) вызывается, но после этого, когда я начинаю запись, метод делегата (captureOutput: didFinishRecordingToOutputFileAtURL: fromConnections: error:
) вызывается снова, но не вызывается во время остановки записи.
Мне нужно решение этой проблемы. Пожалуйста, помогите мне.
//View LifeCycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.finalRecordedVideoName = [self stringWithNewUUID];
arrVideoName = [[NSMutableArray alloc]initWithCapacity:0];
arrOutputUrl = [[NSMutableArray alloc] initWithCapacity:0];
CaptureSession = [[AVCaptureSession alloc] init];
captureDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
if ([captureDevices count] > 0)
{
NSError *error;
VideoInputDevice = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:&error];
if (!error)
{
if ([CaptureSession canAddInput:VideoInputDevice])
[CaptureSession addInput:VideoInputDevice];
else
NSLog(@"Couldn't add video input");
}
else
{
NSLog(@"Couldn't create video input");
}
}
else
{
NSLog(@"Couldn't create video capture device");
}
//ADD VIDEO PREVIEW LAYER
NSLog(@"Adding video preview layer");
AVCaptureVideoPreviewLayer *layer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:CaptureSession];
[self setPreviewLayer:layer];
UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation;
NSLog(@"%d",currentOrientation);
if (currentOrientation == UIDeviceOrientationPortrait)
{
PreviewLayer.orientation = AVCaptureVideoOrientationPortrait;
}
else if (currentOrientation == UIDeviceOrientationPortraitUpsideDown)
{
PreviewLayer.orientation = AVCaptureVideoOrientationPortraitUpsideDown;
}
else if (currentOrientation == UIDeviceOrientationLandscapeRight)
{
PreviewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
}
else if (currentOrientation == UIDeviceOrientationLandscapeLeft)
{
PreviewLayer.orientation = AVCaptureVideoOrientationLandscapeLeft;
}
[[self PreviewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];
//ADD MOVIE FILE OUTPUT
NSLog(@"Adding movie file output");
MovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
VideoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
[VideoDataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
NSString* key = (NSString*)kCVPixelBufferBytesPerRowAlignmentKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[VideoDataOutput setVideoSettings:videoSettings];
Float64 TotalSeconds = 60; //Total seconds
int32_t preferredTimeScale = 30; //Frames per second
CMTime maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale);//