我正在尝试在iOS上重新编码一个可变帧率和持续时间被剪辑的输入MOV文件。目前,我有一个AVAssetWriter设置视频属性,类似于以下内容:
NSMutableDictionary* compressionPropertiesDict = [NSMutableDictionary new];
compressionPropertiesDict[AVVideoProfileLevelKey] = AVVideoProfileLevelH264High40;
if(self.fps > 0) {
compressionPropertiesDict[AVVideoAverageNonDroppableFrameRateKey] = [NSNumber numberWithInt:self.fps];
_sessionMgr.videoSettings = @
{
AVVideoCodecKey: AVVideoCodecH264,
AVVideoWidthKey: [NSNumber numberWithFloat:self.outputSize.width],
AVVideoHeightKey: [NSNumber numberWithFloat:self.outputSize.height],
AVVideoCompressionPropertiesKey: compressionPropertiesDict,
};
在运行时,它看起来像这样:
videoSettings =
{
AVVideoCodecKey = avc1;
AVVideoCompressionPropertiesKey = {
AverageNonDroppableFrameRate = 15;
ProfileLevel = "H264_High_4_0";
};
AVVideoHeightKey = 960;
AVVideoWidthKey = 640;
}
在此过程的最后,我收到了一个崩溃报告:NSInvalidArgumentException: "Compression property AverageNonDroppableFrameRate is not supported for video codec type avc1"
。 (在使用模拟器进行单元测试时。)
iOS只支持一种编解码器类型,即AVVideoCodecH264 / "avc1" - 我注意到其他项目已经使用了AVVideoAverageNonDroppableFrameRateKey
。事实上,我正在使用SDAVAssetExportSession,在这个代码库中,我看到了对该键的显式使用。所以我认为一定有一种方法可以使用这个键来设置帧速率...?
我也尝试过使用AVVideoMaxKeyFrameIntervalKey
,但这并没有改变我的帧速率...
因此,总结一下,有谁能帮助我设置iOS AVFoundation基于视频转换的不同(始终较低)的输出帧率吗?谢谢!