我正在使用AVAssetWriter录制视频,我希望能够将视频剪裁成一个偏离顶部的正方形。这是我的代码 -
NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
@320, AVVideoCleanApertureWidthKey,
@320, AVVideoCleanApertureHeightKey,
@10, AVVideoCleanApertureHorizontalOffsetKey,
@10, AVVideoCleanApertureVerticalOffsetKey,
nil];
NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
@3, AVVideoPixelAspectRatioHorizontalSpacingKey,
@3,AVVideoPixelAspectRatioVerticalSpacingKey,
nil];
NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:bitsPerSecond], AVVideoAverageBitRateKey,
@1,AVVideoMaxKeyFrameIntervalKey,
videoCleanApertureSettings, AVVideoCleanApertureKey,
//AVVideoScalingModeFit,AVVideoScalingModeKey,
videoAspectRatioSettings, AVVideoPixelAspectRatioKey,
nil];
NSDictionary *videoCompressionSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
codecSettings,AVVideoCompressionPropertiesKey,
@320, AVVideoWidthKey,
@320, AVVideoHeightKey,
nil];
每当我取消注释AVVideoScalingModeKey时,我的assetWriter会给我一个关于无法应用videoCompressionSettings的错误。我尝试使用How do make a reduced size video using AVAssetWriter?,但它仍然不适用于我。
答案 0 :(得分:5)
我已将AVVideoScalingModeFit,AVVideoScalingModeKey
添加到videoCompressionSettings
以使其正常运行。