AVAssetWriter在iPhone X分辨率w / h.264失败但不是w / h.265

时间:2017-10-31 03:55:15

标签: ios avfoundation h.264 avassetwriter hevc

我正在使用AVAssetWriter来编写实时视频,附加CMSampleBufferRef s的流。

我选择的一个输出分辨率为1376 x 2436(对于iPhone X,增加一些宽度,使其符合1.77的宽高比)。

奇怪的是......当我把它作为HEVC输出时,一切都很棒。但是,如果我选择h.264(因为只有iPhone 7可以产生HEVC,但iPhone 5s上的某个人可能正在与iPhone X上的某个人交谈),写入失败。

Error Domain = AVFoundationErrorDomain 
Code = -11800 
"The operation could not be completed" 
UserInfo = {
   NSLocalizedFailureReason = An unknown error occurred (-12902), 
   NSLocalizedDescription = The operation could not be completed, 
   NSUnderlyingError = 0x1c424b550 {
      Error Domain = NSOSStatusErrorDomain Code=-12902 "(null)"
   }
 }

h.264设置适用于所有其他输出分辨率:640x1136,750x1334和1080x1920

h.264输出设置:

@{   AVVideoCodecKey:AVVideoCodecH264,
     AVVideoWidthKey:@(mediaSize.width),
     AVVideoHeightKey:@(mediaSize.height),
     AVVideoCompressionPropertiesKey:@{
                        AVVideoAverageBitRateKey: @4500000,
                        AVVideoAllowFrameReorderingKey:@NO,
                        AVVideoProfileLevelKey: AVVideoProfileLevelH264High41,
                        AVVideoH264EntropyModeKey:AVVideoH264EntropyModeCABAC,
                        AVVideoExpectedSourceFrameRateKey: @(30)
                        }
     };

hevc输出设置:

@{ AVVideoCodecKey:AVVideoCodecTypeHEVC,
   AVVideoWidthKey:@(mediaSize.width),
   AVVideoHeightKey:@(mediaSize.height),
   AVVideoCompressionPropertiesKey:@{
        AVVideoProfileLevelKey : (__bridge NSString *)kVTProfileLevel_HEVC_Main_AutoLevel,
        AVVideoAverageBitRateKey: @4500000,
        AVVideoAllowFrameReorderingKey:@NO,
        AVVideoExpectedSourceFrameRateKey: @(30)
        }
};

0 个答案:

没有答案