功能概览
录制侧的「画幅」与「分辨率」是两套耦合参数:
TAVRecorderAspectRatio 决定画面的宽高比,TAVRecorderResolution 只声明分辨率等级,最终输出尺寸由画幅与分辨率共同决定。预览画面与最终成片共用同一份 TAVRecorderConfig,因此配置只在一处生效,不存在“预览 9:16、导出 3:4”的隐式转换。相关接口类
接口类名 | 描述 |
TAVRecorder | 录制入口, prepareWithRecorderConfig:displayContainerView: 时读取配置。 |
TAVRecorderConfig | 画幅、分辨率、帧率、码率配置。 |
TAVRecorderDefinitions | TAVRecorderAspectRatio / TAVRecorderResolution / TAVRecorderPrepareResult 等枚举定义。 |
ITAVCameraManager | 运行时的画幅切换与相机参数调整。 |
画幅与分辨率
画幅
枚举值 | 值 | 比例 |
TAVRecorderAspectRatioFull | 0 | 9:16(默认) |
TAVRecorderAspectRatio_3_4 | 1 | 3:4 |
TAVRecorderAspectRatio_1_1 | 2 | 1:1 |
分辨率
枚举值 | 值 | 说明 |
TAVRecorderResolution_480 | 0 | 480 等级。 |
TAVRecorderResolution_540 | 1 | 540 等级。 |
TAVRecorderResolution_720 | 2 | 720 等级。 |
TAVRecorderResolution_1080 | 3 | 1080 等级。 |
配置示例
TAVRecorderConfig *config = [[TAVRecorderConfig alloc] init];config.aspectRatio = TAVRecorderAspectRatioFull; // 9:16config.resolution = TAVRecorderResolution_720;config.fps = 30;config.devicePosition = AVCaptureDevicePositionFront;config.bitrate = 0; // 0 表示自动TAVRecorderPrepareResult result = [recorder prepareWithRecorderConfig:configdisplayContainerView:self.previewContainerView];if (result == TAVRecorderPrepareResultSuccess) {[recorder startPreview];}
配置默认值
配置项 | 默认值 |
devicePosition | AVCaptureDevicePositionFront(前置) |
fps | 30 |
resolution | TAVRecorderResolution_1080 |
aspectRatio | TAVRecorderAspectRatioFull(9:16) |
bitrate | 0(自动,按 width × height × fps × 0.22 动态计算) |
码率
bitrate 单位为 bps:传
0:SDK 按 width × height × fps × 0.22 动态计算,适配大多数场景。传大于
0 的值:使用固定码率,适合对体积或画质有明确要求的业务。动态切换画幅
录制过程中不可切换画幅;可在非录制状态下调用以下接口,切换会立即更新相机裁剪区域,并在下次开始录制时使用新的视频尺寸:
// 方式一:通过录制器[recorder setAspectRatio:TAVRecorderAspectRatio_1_1];// 方式二:通过相机管理器[[recorder getCameraManager] setAspectRatio:TAVRecorderAspectRatio_1_1];
常见问题
现象 | 原因与处理 |
预览比例与成片不一致。 | 预览容器与录制输出共用同一份 TAVRecorderConfig.aspectRatio;不要在 prepare 之后再改配置对象。需要换比例请在非录制状态下调用 setAspectRatio:。 |
画面清晰度不足。 | 提高 resolution 等级或显式设置更大的 bitrate。 |
输出体积过大。 | 显式设置较小的 bitrate,或降低 resolution。 |