在 Apple 的文档中 AVAssetReaderTrackOutput
, 表示outputSettings
的参数如下使用 +[AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:outputSettings:]
实例化实例时
A value of nil configures the output to vend samples in their original format as stored by the specified track.
当使用它时,例如一个 MP4 视频 Assets ,它似乎会按解码顺序逐步通过帧(即关于显示的乱序),但是所有查询都已交付 CMSampleBufferRef
使用 CMSampleBufferGetImageBuffer
的对象产量 NULL
CVImageBufferRef
对象。
我能确保传递图像缓冲对象的唯一方法是为 outputSettings:
提供像素缓冲格式。 ,例如 kCVPixelFormatType_32ARGB
对于 kCVPixelBufferPixelFormatTypeKey
字典词条。
这样做的另一个有趣的副作用是,帧随后按显示顺序传送,并且帧的底层解码顺序被抽象/隐藏。
知道为什么会这样吗?
最佳答案
像您一样,我希望将 outputSettings
设置为 nil
会导致输出原生格式视频帧,但事实并非如此,您必须指定一些内容才能获取有效的 CVSampleBufferRef
。
一切都没有丢失,使用“勉强存在”字典似乎以其 native 格式输出帧,
AVAsset asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetTrack *videoTrack = [[asset tracksWithMediaCharacteristic:AVMediaCharacteristicVisual] objectAtIndex:0];
NSDictionary *decompressionSettings =
@{ (id)kCVPixelBufferIOSurfacePropertiesKey : [NSDictionary dictionary] };
AVAssetReaderTrackOutput trackOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:decompressionSettings];
...
IOSurfaceOptions 只是默认设置 - 进一步阅读以供引用:https://developer.apple.com/documentation/corevideo/kcvpixelbufferiosurfacepropertieskey?language=objc
关于avfoundation - 如何使用 AVFoundation 从视频流中获取原始格式的图像缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50187204/