如何解决AVPlayerItemOutput 像素类型格式
我正在尝试将 AVPlayerItemVideoOutput 添加到 IOS AVPlayer。
-(void)addOutput:(AVPlayerItem*) playerItem{
if(self.videoOutput != nil){
[playerItem removeOutput:self.videoOutput];
}
CGSize size = [self setupSize];
NSDictionary *outputSettings = @{
(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32ARGB),(id)kCVPixelBufferWidthKey: @(size.width),(id)kCVPixelBufferHeightKey: @(size.height),(id)kCVPixelBufferExtendedPixelsLeftKey:@(0),(id)kCVPixelBufferExtendedPixelsTopKey:@(0),(id)kCVPixelBufferExtendedPixelsRightKey:@(0),(id)kCVPixelBufferExtendedPixelsBottomKey:@(0),};
self.videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:outputSettings];
[playerItem addOutput:self.videoOutput];
}
播放器接收带有编解码器 h264(始终相同)的 mp4 文件。 输入文件像素格式始终为 kCVPixelFormatType_32BGRA。 然后我从播放器输出中读取帧
if(![self.videoOutput hasNewPixelBufferForItemTime:time]){
return nil;
}
CVPixelBufferRef pixelBuffer = [self.videoOutput copyPixelBufferForItemTime: time itemTimeFordisplay:nil];
if(!pixelBuffer){
return nil;
}
return pixelBuffer;
结果是,当我在 iPhone 上读取缓冲区时,它的像素类型总是与输入文件中的相同 - kCVPixelFormatType_32BGRA。 但是在 iPad 上 videoOutput 没有返回帧,而是在我设置 kCVPixelFormatType_32ARGB 这种格式时返回帧。 我做了下一个 hack 来修复它,只是根据 iPhone/iPad 更改设置,但这并不是很好的解决方案。也许有更好的解决方案,如何只从播放器接收特定的像素类型?
NSDictionary *outputSettings = @{
(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA),};
if(UIDevice.isIpad){
outputSettings = @{
(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32ARGB),};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。