AVAssetWriter无法使用AVVideoProfileLevelKey编码视频 [英] AVAssetWriter failing to encode video with AVVideoProfileLevelKey
问题描述
有人可以帮我解决这个问题吗? 我可以使用具有以下输出设置的AVAssetWriter对视频进行编码.
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];
但是,当我尝试通过指定配置文件进行编码时,请说AVVideoProfileLevelH264Baseline30输出设置,这看起来像
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];
推荐答案
我也遇到了这种失败.对我来说,问题仅存在于OS X 10.7(Lion)上,它根本不支持AVVideoProfileLevelKey ...您仍然可以在H.264中进行编码,但是只需要省略该参数,OS便可以处理选择配置文件的问题.使用.如果您在OS X 10.8/10.9或iOS 4或更高版本上看到此操作失败,则说明您还有其他问题.
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.
这篇关于AVAssetWriter无法使用AVVideoProfileLevelKey编码视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!