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];
ビットレートが低すぎます (通常は 100 Kbps => 300 Kbps)。これは、エンコーディングがハードウェアではなくソフトウェアを介して行われているためだと思います (データが から返された後に発生していますAVCaptureSession
)。
キャプチャを強制的に 1 ~ 3 Mbps から 512K に下げるにはどうすればよいですか? それがもっと高くなることができるなら、なぜそれが使用しているレートを制限することができないのか想像できません.
ありがとう、
-G