3

谁能帮我解决这个问题?我可以使用具有以下输出设置的 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];
4

1 回答 1

1

I've had this fail too. For me, the problem was only on OS X 10.7 (Lion), which simply does not support AVVideoProfileLevelKey... You can still encode in H.264, but just need to omit that parameter, and the OS will handle choosing a profile to use. If you're seeing this fail on OS X 10.8/10.9, or iOS 4 or later, then there's something else going wrong for you.

于 2013-10-06T18:31:14.420 回答