AVAssetReaderTrackOutput 的 copyNextSampleBuffer returns CMSampleBufferRef 大小错误
AVAssetReaderTrackOutput's copyNextSampleBuffer returns CMSampleBufferRef with wrong size
我有一段代码读取视频 AVAssetTrack 的 sampleBuffer:
AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
NSDictionary *pixelBufferAttributes = @{
(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)
};
AVAssetReaderTrackOutput *assetReaderTrackOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack
outputSettings:pixelBufferAttributes];
NSError *assetReaderCreationError = nil;
AVAssetReader *assetReader = [[AVAssetReader alloc] initWithAsset:asset
error:&assetReaderCreationError];
[assetReader addOutput:assetReaderTrackOutput];
[assetReader startReading];
while (assetReader.status == AVAssetReaderStatusReading) {
CMSampleBufferRef sampleBuffer = [assetReaderTrackOutput copyNextSampleBuffer];
// Some OpenGL operations here
}
// and other operations here, too
上面的代码几乎对所有视频都能正常工作,但有一个视频总是崩溃。经检查,我发现 CMSampleBufferRef
结果与真实资产的大小不同。
从调试器打印出来时,sampleBuffer
的维度为 848 x 480
,而实际资产的维度为 1154.88720703125 x 480
。
我试图搜索此问题的原因,但找到了 none。你们中有人对此有任何见解吗?非常感谢任何评论或输入。
谢谢!
"real asset" 报告视频的缩放尺寸,以视频从其像素宽度 848 开始水平拉伸的点为单位。
我有一段代码读取视频 AVAssetTrack 的 sampleBuffer:
AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
NSDictionary *pixelBufferAttributes = @{
(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)
};
AVAssetReaderTrackOutput *assetReaderTrackOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack
outputSettings:pixelBufferAttributes];
NSError *assetReaderCreationError = nil;
AVAssetReader *assetReader = [[AVAssetReader alloc] initWithAsset:asset
error:&assetReaderCreationError];
[assetReader addOutput:assetReaderTrackOutput];
[assetReader startReading];
while (assetReader.status == AVAssetReaderStatusReading) {
CMSampleBufferRef sampleBuffer = [assetReaderTrackOutput copyNextSampleBuffer];
// Some OpenGL operations here
}
// and other operations here, too
上面的代码几乎对所有视频都能正常工作,但有一个视频总是崩溃。经检查,我发现 CMSampleBufferRef
结果与真实资产的大小不同。
从调试器打印出来时,sampleBuffer
的维度为 848 x 480
,而实际资产的维度为 1154.88720703125 x 480
。
我试图搜索此问题的原因,但找到了 none。你们中有人对此有任何见解吗?非常感谢任何评论或输入。
谢谢!
"real asset" 报告视频的缩放尺寸,以视频从其像素宽度 848 开始水平拉伸的点为单位。