ios - 裁剪录制的视频帧
<p><p>我正在尝试裁剪视频帧。我使用 <code>AVFoundation</code> 框架录制了视频。我需要将拍摄的图像和录制的视频裁剪成方形。我已经为 <code>UIImage</code> 工作了,现在我正在尝试裁剪视频。 </p>
<blockquote>
<pre><code>- (UIImage *)squareImageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
// Cropping UIImage is working fine.
CGImageRef imageRef = CGImageCreateWithImageInRect(, CGRectMake(0,0, image.size.width, image.size.width));
UIImage *result = ;
CGImageRelease(imageRef);
return result;
}
</code></pre>
</blockquote>
<p>我尝试裁剪视频,但结果是更改了整个视频帧而不进行裁剪,并且看起来被拉伸(stretch)了。</p>
<blockquote>
<pre><code>_writer = ;
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
, AVVideoWidthKey,
, AVVideoHeightKey,
nil];
_videoInput = ;
;
</code></pre>
</blockquote>
<p>谁能帮我解决这个视频裁剪问题?提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>下面是我用来裁剪视频的代码。我们需要设置 <code>AVVideoCompressionPropertiesKey</code>,其中包含 <code>AVVideoCleanApertureKey</code> 键用于视频设置。</p>
<p>我推荐了:<a href="https://stackoverflow.com/questions/17882871/how-to-crop-video-into-square-ios-with-avassetwriter?rq=1" rel="noreferrer noopener nofollow">How to crop video into square iOS with AVAssetWriter</a> </p>
<blockquote>
<pre><code>NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
, AVVideoCleanApertureWidthKey,
, AVVideoCleanApertureHeightKey,
, AVVideoCleanApertureHorizontalOffsetKey,
, AVVideoCleanApertureVerticalOffsetKey,
nil];
NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
, AVVideoPixelAspectRatioHorizontalSpacingKey,
,AVVideoPixelAspectRatioVerticalSpacingKey,
nil];
NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
, AVVideoAverageBitRateKey,
,AVVideoMaxKeyFrameIntervalKey,
videoCleanApertureSettings, AVVideoCleanApertureKey,
//videoAspectRatioSettings, AVVideoPixelAspectRatioKey,
//AVVideoProfileLevelH264Main30, AVVideoProfileLevelKey,
nil];
NSString *targetDevice = [ model];
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoScalingModeResizeAspectFill,AVVideoScalingModeKey,
AVVideoCodecH264, AVVideoCodecKey,
codecSettings,AVVideoCompressionPropertiesKey,
, AVVideoWidthKey,
, AVVideoHeightKey,
nil];
_videoInput = ;
</code></pre>
</blockquote></p>
<p style="font-size: 20px;">关于ios - 裁剪录制的视频帧,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23786292/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23786292/
</a>
</p>
页:
[1]