AVAssetWriter failing to encode video with AVVideoProfileLevelKey

こ雲淡風輕ζ 提交于 2020-01-03 20:05:56

问题


Can anyone help me out with this problem? I am able to encode a video using AVAssetWriter with following output settings.

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];

However when i try to encode by specifying a profile say AVVideoProfileLevelH264Baseline30 output settings after this will look like

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];

My video recording fails with these settings.

So where is my problem here ? I have initialized Asset writer like this

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

回答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.



来源:https://stackoverflow.com/questions/18505140/avassetwriter-failing-to-encode-video-with-avvideoprofilelevelkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!