gpt4 book ai didi

iOS AVWritter Key 从中心裁剪视频偏移

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:32:51 24 4
gpt4 key购买 nike

我正在使用 AVCapture 来录制视频。我需要裁剪视频。我能够通过设置

AVVideoWidthKey : [NSNumber numberWithInteger:outputSize.width],
AVVideoHeightKey : [NSNumber numberWithInteger:outputSize.height],

但是,我需要用偏移裁剪,我不想从中心裁剪,因为它默认工作。

我在 AVFoundation 的 AVVideoSettings.h 中读到我可以使用 AVVideoCleanApertureVerticalOffsetKey

The value for this key is an NSDictionary containing AVVideoCleanAperture*Key keys. AVVideoCleanApertureWidthKey and AVVideoCleanApertureHeightKey define a clean rectangle which is centered on the video frame. To offset this rectangle from center, use AVVideoCleanApertureHorizontalOffsetKey and AVVideoCleanApertureVerticalOffsetKey. A positive value for AVVideoCleanApertureHorizontalOffsetKey moves the clean aperture region to the right, and a positive value for AVVideoCleanApertureVerticalOffsetKey moves the clean aperture region down.

我正在尝试以下操作,但我只在没有偏移的情况下在中心进行裁剪。

NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:outputSize.width], AVVideoCleanApertureWidthKey,
[NSNumber numberWithInteger:outputSize.height], AVVideoCleanApertureHeightKey,
[NSNumber numberWithInteger:0], AVVideoCleanApertureHorizontalOffsetKey,
[NSNumber numberWithInteger:-200], AVVideoCleanApertureVerticalOffsetKey,
nil];

NSMutableDictionary *compressionSettings = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithUnsignedLong:bitrate] forKey:AVVideoAverageBitRateKey];

[compressionSettings setObject:videoCleanApertureSettings forKey:AVVideoCleanApertureKey];

if (self.shouldKeepOnlyKeyFrames) {
[compressionSettings setObject:@1 forKey:AVVideoMaxKeyFrameIntervalKey];
}

if (self.profileLevel) {
[compressionSettings setObject:self.profileLevel forKey:AVVideoProfileLevelKey];
}
[compressionSettings setObject:@NO forKey:AVVideoAllowFrameReorderingKey];
[compressionSettings setObject:@30 forKey:AVVideoExpectedSourceFrameRateKey];



return @{
AVVideoCodecKey : self.codec,
AVVideoScalingModeKey : self.scalingMode,
AVVideoWidthKey : [NSNumber numberWithInteger:outputSize.width],
AVVideoHeightKey : [NSNumber numberWithInteger:outputSize.height],
AVVideoCompressionPropertiesKey : compressionSettings
};

最佳答案

您缺少信息。您的参数应该更像这样。

NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:320], AVVideoCleanApertureWidthKey,
[NSNumber numberWithInt:480], AVVideoCleanApertureHeightKey,
[NSNumber numberWithInt:10], AVVideoCleanApertureHorizontalOffsetKey,
[NSNumber numberWithInt:10], AVVideoCleanApertureVerticalOffsetKey,
nil];


NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:3], AVVideoPixelAspectRatioHorizontalSpacingKey,
[NSNumber numberWithInt:3],AVVideoPixelAspectRatioVerticalSpacingKey,
nil];



NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:960000], AVVideoAverageBitRateKey,
[NSNumber numberWithInt:1],AVVideoMaxKeyFrameIntervalKey,
videoCleanApertureSettings, AVVideoCleanApertureKey,
//videoAspectRatioSettings, AVVideoPixelAspectRatioKey,
//AVVideoProfileLevelH264Main30, AVVideoProfileLevelKey,
nil];





NSString *targetDevice = [[UIDevice currentDevice] model];

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
codecSettings,AVVideoCompressionPropertiesKey,
[NSNumber numberWithInt:320], AVVideoWidthKey,
[NSNumber numberWithInt:480], AVVideoHeightKey,
nil];

关于iOS AVWritter Key 从中心裁剪视频偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38201743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com