Cocoa AvassetWriterInputPixelBufferAdapter有时会丢弃视频比特率
我试着用我的网络摄像机录制视频。 我正在创建带有视频输入的AVCaptureSession,并添加AVAssetWriter、AVAssetWriterInput和AvassetWriterInputPixelBufferAdapter。AVAssetWriterInput我正在配置下一个设置:Cocoa AvassetWriterInputPixelBufferAdapter有时会丢弃视频比特率,cocoa,video,avfoundation,Cocoa,Video,Avfoundation,我试着用我的网络摄像机录制视频。 我正在创建带有视频输入的AVCaptureSession,并添加AVAssetWriter、AVAssetWriterInput和AvassetWriterInputPixelBufferAdapter。AVAssetWriterInput我正在配置下一个设置: [pixelAdaptorSettings setObject:AVVideoCodecH264 forKey:AVVideoCodecKey]; [pixelAdaptorSettings setOb
[pixelAdaptorSettings setObject:AVVideoCodecH264 forKey:AVVideoCodecKey];
[pixelAdaptorSettings setObject:[NSNumber numberWithInt:1920] forKey:AVVideoWidthKey];
[pixelAdaptorSettings setObject:[NSNumber numberWithInt:1080] forKey:AVVideoHeightKey];
NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:1920], AVVideoCleanApertureWidthKey,
[NSNumber numberWithInt:1080], AVVideoCleanApertureHeightKey,
[NSNumber numberWithInt:0], AVVideoCleanApertureHorizontalOffsetKey,
[NSNumber numberWithInt:0], AVVideoCleanApertureVerticalOffsetKey,
nil];
NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:3], AVVideoPixelAspectRatioHorizontalSpacingKey,
[NSNumber numberWithInt:3], AVVideoPixelAspectRatioVerticalSpacingKey,
nil];
NSMutableDictionary * compressionProperties = [[NSMutableDictionary alloc] init];
[compressionProperties setObject:videoCleanApertureSettings forKey:AVVideoCleanApertureKey];
[compressionProperties setObject:videoAspectRatioSettings forKey:AVVideoPixelAspectRatioKey];
[compressionProperties setObject:[NSNumber numberWithInt:4096 * 1000] forKey:AVVideoAverageBitRateKey];
[compressionProperties setObject:[NSNumber numberWithInt: 60] forKey:AVVideoMaxKeyFrameIntervalKey];
[compressionProperties setObject:AVVideoProfileLevelH264Main41 forKey:AVVideoProfileLevelKey];
[pixelAdaptorSettings setObject:compressionProperties forKey:AVVideoCompressionPropertiesKey];
if ([_assetWriter canApplyOutputSettings:pixelAdaptorSettings forMediaType:AVMediaTypeVideo])
{
_assetWriterVideoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:pixelAdaptorSettings];
_assetWriterVideoInput.expectsMediaDataInRealTime = _encodingLiveVideo;
// You need to use BGRA for the video in order to get realtime encoding. I use a color-swizzling shader to line up glReadPixels' normal RGBA output with the movie input's BGRA.
NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey,
[NSNumber numberWithInt:1920], kCVPixelBufferWidthKey,
[NSNumber numberWithInt:1080], kCVPixelBufferHeightKey,
nil];
// NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey,
// nil];
_assetWriterPixelBufferInput = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:_assetWriterVideoInput sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary];
if ([_assetWriter canAddInput:_assetWriterVideoInput])
[_assetWriter addInput:_assetWriterVideoInput];
else
{
NSLog(@"Couldn't add asset writer video input.");
}
}
else
{
NSLog(@"Couldn't apply video output settings.");
}
在开始录像并保存文件后,我在VideoSpec应用程序中检查文件并获取下一个
你也可以在这里查看视频样本
有人能帮我解决这个问题吗
WBR
格言