当前位置 : 主页 > 手机开发 > ios >

ios – AVCaptureSession图像尺寸(带GPUImage)

来源:互联网 收集:自由互联 发布时间:2021-06-11
我试图在iOS上在GPU Image上实现视频录制. 我有一个GPUImageVideoCamera,我正在尝试设置这样的录音: -(void)toggleVideoRecording {if (!self.recording) { self.recording = true; GPUImageMovieWriter * mw = [self createM
我试图在iOS上在GPU Image上实现视频录制.

我有一个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,没有什么看起来很有希望).

甚至将我引用到处理此项目的示例项目也会非常有帮助.

确实可以将维度拉出捕获会话.这是如何做:

// 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)];
网友评论