4

我正在使用 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 的错误。我尝试使用如何使用 AVAssetWriter 制作缩小尺寸的视频?但它仍然对我不起作用。

4

1 回答 1

5

我添加AVVideoScalingModeFit,AVVideoScalingModeKey到我videoCompressionSettings的让它工作。

于 2013-07-27T06:02:19.730 回答