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

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

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

那么我的问题在哪里呢? 我已经像这样初始化了 Asset writer

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

最佳答案

我也遇到过这种情况。对我来说,问题只出现在 OS X 10.7 (Lion) 上,它根本不支持 AVVideoProfileLevelKey ...您仍然可以在 H.264 中编码,但只需要省略该参数,操作系统将处理选择一个配置文件以利用。如果您在 OS X 10.8/10.9 或 iOS 4 或更高版本上看到此失败,则说明您遇到了其他问题。

关于avfoundation - AVAssetWriter 无法使用 AVVideoProfileLevelKey 对视频进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18505140/

相关文章:

ios - AVAssetWriter 编解码器类型 hevc

ios - AVFoundation 在 iPhone 12 上录制 10 位 HDR 视频

ios - 如何从录制的视频中提取音频?

iOS 如何在使用 AVAssetWriter 捕获视频时正确处理方向

iphone - 如何将后置摄像头实时视频显示到 UIImageView?

ios - 使用iOS CIDetector人脸检测触发功能

iphone - 在录制 OpenGL View 时录制音频

objective-c - AVAssetWriterInputPixelBufferAdaptor 和 CMTime

ios - 使用 AVFoundation 随机播放 mp3

objective-c - 使用回调确定 OpenAL 何时完成播放音频