我在OSX Lion上使用AVFoundation來執行屏幕捕獲。完成如下:OSX Lion上AVFoundation屏幕捕獲的比特率限制
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;
,而是經由
self->writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videosettings] retain];
應用視頻設置到writerinput的線I得到的比特率太低(通常爲100 Kbps的=> 300 Kbps)的。我認爲這是因爲編碼是通過軟件而不是硬件發生的(從AVCaptureSession
返回數據後發生)。
我能做些什麼來強制捕獲從1-3 Mbps下降到512K?如果它可以走得更高,我無法想象它爲什麼不能限制它使用的速率。
感謝,
-G
「iPhone 3G以外」讓我相信這是來自iPhone版AVFoundation的文檔。 – George
你是對的。即使如此,至少在我看來,將H264編碼參數附加到視頻輸出上很有意義。至少在iOS上,直接進行H264編碼的唯一類是AVAssetWriter。 –