Macos OSX Lion上AVFoundation屏幕捕获的比特率限制
我正在使用OSX Lion上的AVFoundation进行屏幕捕获。完成如下工作:Macos OSX Lion上AVFoundation屏幕捕获的比特率限制,macos,avfoundation,osx-lion,screen-capture,bitrate,Macos,Avfoundation,Osx Lion,Screen Capture,Bitrate,我正在使用OSX Lion上的AVFoundation进行屏幕捕获。完成如下工作: self->screenInput = [[AVCaptureScreenInput alloc] initWithDisplayID:self->screen]; self->dataOutput = [[AVCaptureVideoDataOutput alloc] init]; self->session = [[AVCaptureSession alloc]
self->screenInput = [[AVCaptureScreenInput alloc] initWithDisplayID:self->screen];
self->dataOutput = [[AVCaptureVideoDataOutput alloc] init];
self->session = [[AVCaptureSession alloc] init];
self->assetWriter = [[AVAssetWriter alloc] initWithURL:url
fileType:AVFileTypeQuickTimeMovie
error:&error];
self->writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:nil] retain];
self->dataOutput.videoSettings=videosettings;
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
if(!self->startedWriting)
{
[self->assetWriter startSessionAtSourceTime:CMSampleBufferGetPresentationTimeStamp(sampleBuffer)];
self->startedWriting = YES;
}
if(self->writerInput.readyForMoreMediaData)
{
[self->writerInput appendSampleBuffer:sampleBuffer]
}
}
这导致帧速率约为1 Mbps->3 Mbps。问题在于,在视频设置中,我指定了:
NSMutableDictionary * compressionSettings = [[[NSMutableDictionary alloc] initWithCapacity:1] autorelease];
[compressionSettings setObject:[NSNumber numberWithInt:512000] forKey:AVVideoAverageBitRateKey];
[videosettings setObject:compressionSettings forKey:AVVideoCompressionPropertiesKey];
是用于512K的,比特率较高会导致文件太大(毕竟我们需要上传这些文件)
当我拆下线路时
self->dataOutput.videoSettings=videosettings;
而是将视频设置应用到writerinput via
self->writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videosettings] retain];
我得到的比特率太低(通常为100kbps=>300kbps)。我认为这是因为编码是通过软件而不是硬件进行的(它发生在从AVCaptureSession
返回数据之后)
我该怎么做才能强制捕获速度从1-3 Mbps下降到512K?如果它能走得更高,我无法想象为什么它不能限制它使用的利率
谢谢
-G来自AVCaptureVideoDataOutput videoSettings属性的文档
Currently, the only supported key is kCVPixelBufferPixelFormatTypeKey. Supported pixel formats are
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, kCVPixelFormatType_420YpCbCr8BiPlanarFullRange and kCVPixelFormatType_32BGRA,
except on iPhone 3G, where the supported pixel formats are kCVPixelFormatType_422YpCbCr8 and kCVPixelFormatType_32BGRA.
在这个类上设置压缩设置是没有意义的。这意味着您的AVAssetWriterInput压缩设置为零。因此,您将获得设备的任何默认速率
虽然OS-X AVFoundaton实现中肯定存在缺陷,但您收到的比特率可能是正确的。例如,视频中有多少运动?场景有多复杂?还请记住,H264/AVC不是恒定比特率编解码器 “在iPhone 3G上除外”让我相信这是来自iPhone版本AVFoundation的文档。你是对的。即使如此,至少对我来说,将H264编码参数附加到视频输出中也没有多大意义。至少在iOS上,唯一直接进行H264编码的类是AVAssetWriter。