以与预览图层匹配的大小导出AVCaptureSession视频 [英] Exporting AVCaptureSession video in a size that matches the preview layer

查看:158
本文介绍了以与预览图层匹配的大小导出AVCaptureSession视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用会话预设 AVCaptureSessionPreset640x480 使用 AVCaptureSession 录制视频。我在非标准尺寸(300 x 300)中使用 AVCaptureVideoPreviewLayer ,在录制时将重力设置为纵横填充。它的设置如下:

I'm recording video using AVCaptureSession with the session preset AVCaptureSessionPreset640x480. I'm using an AVCaptureVideoPreviewLayer in a non-standard size (300 x 300) with the gravity set to aspect fill while recording. It's setup like this:

self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
_previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
_previewLayer.frame = _previewView.bounds; // 300 x 300
[_previewView.layer addSublayer:_previewLayer];

录制视频后,我想以快速格式将其写入文件。在播放过程中,我再次以300 x 300非标准尺寸的图层播放视频。由于这些视频最终将通过网络连接传输,因此保留完整的640x480视频似乎很浪费。

After recording the video, I want to write it to a file in quicktime format. During playback, I'm once again playing the video in a 300 x 300 non-standard size layer. Because these videos will ultimately be transferred over a network connection, it seems wasteful to keep the full 640x480 video.

导出视频以匹配我的300 x的最佳方式是什么? 300预览图层?我是一个AVFoundation菜鸟,所以如果我以错误的方式解决这个问题,请告诉我。我只是希望录制期间在预览图层中显示的录制视频与在磁盘上导出的视频相匹配。

What's the best way to export a video to match my 300 x 300 preview layer? I'm an AVFoundation noob, so if I'm going about this the wrong way please let me know. I just want the recorded video displayed in the preview layer during recording to match the video that is exported on disk.

推荐答案

视频分辨率和视频大小是两回事。分辨率代表清晰度,更高分辨率意味着更高清晰度然而,视频大小是显示视频的界限。根据视频的视频分辨率和宽高比,视频会在观看者中显示时拉伸或缩小。

Video Resolution and Video Size are two different things. Resolution stands for clarity, higher resolution means higher clarity. Whereas, Video size is the bounds in which to display the video. Depending on the video resolution and aspect ratio of the video, the video will stretch or shrink, when seen in the viewer.

现在已经解释了事实,你可以在这里找到你的答案:

Now as the facts have been explained, You can find Your answer here:

如何使用AVFoundation裁剪视频

按此顺序执行步骤:



  1. 将视频录制到磁盘。

  2. 从磁盘保存到资产库。

  3. 从磁盘删除。

  4. 执行上述链接中提到的步骤。

  1. Record Video to disk.
  2. Save from Disk to asset library.
  3. Delete from disk.
  4. Perform the steps mentioned in the above link.


注意:在录制视频并将视频写入资产库后执行步骤, saveComposition 已保存的资产。

NOTE: Perform the steps after recording and writing your video to asset library, saveComposition being the saved asset.

并在此步骤中提供您的尺寸: videoComposition.renderSize = CGSizeMake(320,240); as videoCompositio n.renderSize = CGSizeMake(300,300);

and provide your size in this step:videoComposition.renderSize = CGSizeMake(320, 240); as videoComposition.renderSize = CGSizeMake(300, 300);

以及建议。由于将文件写入磁盘,然后写入库,然后再次返回磁盘是一种冗长的操作。尝试使用 dispatch_queue operationBlock

And an advice. Since writing the file to disk, then to library, then again back to disk is kind of a lengthy operation. Try doing it all asynchronously using a dispatch_queue or operationBlock

干杯,玩得开心。

这篇关于以与预览图层匹配的大小导出AVCaptureSession视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆