我正在尝试在GPUImage上实现iOS中的视频录制。
我有一个GPUImageVideoCamera,我正在尝试设置这样的录音:
-(void)toggleVideoRecording {
if (!self.recording) {
self.recording = true;
GPUImageMovieWriter * mw = [self createMovieWriter: self.filter1];
[self.filter1 addTarget:mw];
mw.shouldPassthroughAudio = YES;
[mw startRecording];
}
else {
self.recording = false;
[self finishWritingMovie];
}
}
-(GPUImageMovieWriter *) createMovieWriter:(GPUImageFilter *) forFilter {
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/CurrentMovie.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
GPUImageMovieWriter * mw = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:forFilter->currentFilterSize];
self.movieWriter = mw;
self.movieURL = movieURL;
return mw;
}
这实际上大部分都有效。但是,MoviewWriter需要输入媒体的CGSize,我不知道如何将其从VideoCamera中取出。首先,尺寸会有所不同,因为相机正在使用sessionPreset:AVCaptureSessionPresetHigh,这意味着它会根据设备的功能而变化。其次,方向改变了相关的CGSize。如果用户以横向模式开始录制,我想转置尺寸。
对于任何知道如何使用vanilla CoreVideo执行此操作的人,我可以将AVCaptureSession拉出我的GPUImageVideoCamera。 (但我已经阅读了AVCaptureSession的API,没有什么看起来很有希望)。
甚至将我引用到处理此项目的示例项目也非常有用。
答案 0 :(得分:7)
确实可以将维度拉出捕获会话。方法如下:
// self.videoCamera is a GPUImageVideoCamera
AVCaptureVideoDataOutput *output = [[[self.videoCamera captureSession] outputs] lastObject];
NSDictionary* outputSettings = [output videoSettings];
long width = [[outputSettings objectForKey:@"Width"] longValue];
long height = [[outputSettings objectForKey:@"Height"] longValue];
if (UIInterfaceOrientationIsPortrait([self.videoCamera outputImageOrientation])) {
long buf = width;
width = height;
height = buf;
}
GPUImageMovieWriter * mw = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(width, height)];