【问题标题】:AVCaptureSession image dimensions (with GPUImage)AVCaptureSession 图像尺寸(带 GPUImage)
【发布时间】:2013-09-10 01:29:23
【问题描述】:

我正在尝试在 iOS 中基于 GPUImage 实现视频录制。

我有一个 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 并没有任何希望)。

即使将我介绍给处理此问题的示例项目也会非常有帮助。

【问题讨论】:

    标签: ios avcapturesession gpuimage


    【解决方案1】:

    确实可以从捕获会话中提取维度。方法如下:

    // 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)];
    

    【讨论】:

    • 感谢您的回答,对我帮助很大。在这里使用 Xamarin,所以代码有点不同,因为绑定包装了 AVCapureVideoOutput.videoSettings。示例代码供参考:` AVCaptureVideoDataOutput output = camera.CaptureSession.Outputs.OfType().Last(); int h = output.UncompressedVideoSetting.Height ?? 0; int w = output.UncompressedVideoSetting.Width ?? 0; if (h == 0 || w == 0) throw new InvalidOperationException("无法从捕获会话获取视频输出大小");`
    猜你喜欢
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 2018-05-30
    相关资源
    最近更新 更多