9

我创建了一个录制视频并将其上传到服务器的应用程序,但是以非常高分辨率录制的视频,我想降低其分辨率,我在互联网上了解了 AVCaptureSessionPreset640x480,但我不知道如何使用它。

4

5 回答 5

18

sessionPreset您可以使用该属性更改分辨率。会话预设的默认值AVCaptureSessionPresetHigh适用于高质量的视频和音频输出。

您可以设置会话预设,如:

[self.yourSession setSessionPreset:AVCaptureSessionPresetLow];

会话预设

一个常数值,指示输出的质量级别或比特率。@property(nonatomic, copy) NSString *sessionPreset 讨论

您可以使用此属性自定义输出的质量级别或比特率。有关 sessionPreset 的可能值,请参阅“视频输入预设”。默认值为 AVCaptureSessionPresetHigh。

您可以在会话运行时设置此值。

您只能在以下情况下设置预设canSetSessionPreset:为该预设返回 YES。可用性

Available in iOS 4.0 and later.

在 AVCaptureSession.h 中声明

会话预设的可能值为:

视频输入预设

sessionPreset 使用属性定义捕获设置预设的常量。

NSString *const AVCaptureSessionPresetPhoto;

NSString *const AVCaptureSessionPresetHigh;

NSString *const AVCaptureSessionPresetMedium;

NSString *const AVCaptureSessionPresetLow;

NSString *const AVCaptureSessionPreset352x288;

NSString *const AVCaptureSessionPreset640x480;

NSString *const AVCaptureSessionPreset1280x720;

NSString *const AVCaptureSessionPreset1920x1080;

NSString *const AVCaptureSessionPresetiFrame960x540;

NSString *const AVCaptureSessionPresetiFrame1280x720;

常量细节:

AVCaptureSessionPresetPhoto

Specifies capture settings suitable for high resolution photo quality output.

Available in iOS 4.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPresetHigh

Specifies capture settings suitable for high quality video and audio output.

Available in iOS 4.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPresetMedium

Specifies capture settings suitable for output video and audio bitrates suitable for sharing over WiFi.

Available in iOS 4.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPresetLow

Specifies capture settings suitable for output video and audio bitrates suitable for sharing over 3G.

Available in iOS 4.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPreset352x288

Specifies capture settings suitable for CIF quality (352x288 pixel) video output.

Available in iOS 5.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPreset640x480

Specifies capture settings suitable for VGA quality (640x480 pixel) video output.

Available in iOS 4.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPreset1280x720

Specifies capture settings suitable for 720p quality (1280x720 pixel) video output.

Available in iOS 4.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPreset1920x1080

Specifies capture settings suitable for 1080p quality (1920x1080 pixel) video output.

Available in iOS 5.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPresetiFrame960x540

Specifies capture settings to achieve 960x540 quality iFrame H.264 video at about 30 Mbits/sec with AAC audio.

QuickTime movies captured in iFrame format are optimal for editing applications.

Available in iOS 5.0 and later.

Declared in AVCaptureSession.h.

AVCaptureSessionPresetiFrame1280x720

Specifies capture settings to achieve 1280x720 quality iFrame H.264 video at about 40 Mbits/sec with AAC audio.

QuickTime movies captured in iFrame format are optimal for editing applications.

Available in iOS 5.0 and later.

Declared in AVCaptureSession.h.

请参考:AVCaptureSession

于 2012-11-02T08:21:48.910 回答
13
if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset640x480]) {
    [self.captureSession setSessionPreset:AVCaptureSessionPreset640x480];
}
于 2012-11-02T08:21:15.270 回答
1

2019斯威夫特 5

var session : AVCaptureSession?


self.session!.sessionPreset = AVCaptureSession.Preset.medium;
于 2019-05-25T06:26:09.140 回答
0

对于 Swift 2.2 和 3.0:

captureSession.sessionPreset = AVCaptureSessionPreset640x480

不幸的是,这没有设置为枚举,因此它目前缺乏类型安全性,因为 sessionPreset 是一个String.

于 2016-10-18T00:47:20.037 回答
0

使用其中之一很重要:

NSString *const AVCaptureSessionPresetHigh;
NSString *const AVCaptureSessionPresetMedium;
NSString *const AVCaptureSessionPresetLow;

这样您就不会遇到不支持您的特定规格的手机。除非你每次都写代码来检查。

于 2018-09-06T03:49:38.277 回答