AVAssetWriter无法使用AVVideoProfileLevelKey对视频进行编码

时间:2013-08-29 07:51:55

标签: avfoundation avassetwriter

任何人都可以帮我解决这个问题吗? 我能够使用AVAssetWriter对视频进行编码,并具有以下输出设置。

NSDictionary *videoCompressionSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                          AVVideoCodecH264, AVVideoCodecKey,
                                          [NSNumber numberWithInteger:dimensions.width], AVVideoWidthKey,
                                          [NSNumber numberWithInteger:dimensions.height], AVVideoHeightKey,
                                          [NSDictionary dictionaryWithObjectsAndKeys:
                                           [NSNumber numberWithInteger:bitsPerSecond], AVVideoAverageBitRateKey,
                                           [NSNumber numberWithInteger:30],AVVideoMaxKeyFrameIntervalKey,
                                           nil], AVVideoCompressionPropertiesKey,   
                                          nil];

然而,当我尝试通过指定配置文件进行编码时,说AVVideoProfileLevelH264Baseline30之后的输出设置将如下所示

NSDictionary *videoCompressionSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                          AVVideoCodecH264, AVVideoCodecKey,
                                          [NSNumber numberWithInteger:dimensions.width], AVVideoWidthKey,
                                          [NSNumber numberWithInteger:dimensions.height], AVVideoHeightKey,
                                          [NSDictionary dictionaryWithObjectsAndKeys:
                                           [NSNumber numberWithInteger:bitsPerSecond], AVVideoAverageBitRateKey,
                                           [NSNumber numberWithInteger:30],AVVideoMaxKeyFrameIntervalKey,
                                           AVVideoProfileLevelH264Baseline30,AVVideoProfileLevelKey,
                                           nil], AVVideoCompressionPropertiesKey,   
                                          nil];

我的视频录制因这些设置而失败。

那么我的问题出在哪里? 我已经初始化了像这样的资产作家

_assetWriter = [[AVAssetWriter alloc] initWithURL:_movieURL fileType:AVFileTypeMPEG4 error:&error];

1 个答案:

答案 0 :(得分:1)

我也失败了。对我来说,问题只出现在OS X 10.7(Lion)上,它根本不支持AVVideoProfileLevelKey ......您仍然可以在H.264中进行编码,但只需要省略该参数,操作系统将处理选择使用。如果你在OS X 10.8 / 10.9或iOS 4或更高版本上看到这个失败,那么你就会出现其他问题。