# WebRTC 视频参数设置
| 属性 | 含义 | 说明 | 
|---|---|---|
| width | 视频的宽度 | - | 
| height | 视频的高度 | - | 
| aspectRatio | 比例 | 宽高有两种比例 :一种是 4:3((1.33333333333)),另一种是 16:9((1.7777777778));一般情况下只需要设置宽和高 | 
| frameRate | 帧率 | 设置帧率来控制码流;帧率越低画质越差,帧率越高画质越高;一般 30 帧到 60 帧,画质就很平滑 | 
| facingMode | 镜像模式 | 用来控制摄像头显示,有四种模式:user 前置摄像头,environment 后置摄像头,left 前置左侧摄像头,right 前置右侧摄像头 | 
| resizeMode | 大小模式 | 采集的画面要不要裁剪 | 
示例:
const constraints = {
  width: 1920,
  height: 1080,
  aspectRatio: 1.777777778,
};
 1
2
3
4
5
2
3
4
5
{
  "audio": true,
  "video": {
    "mandatory": {
      "minWidth": 320,
      "maxWidth": 1280,
      "minHeight": 180,
      "maxHeight": 720,
      "minFrameRate": 30
    }
  }
}
 1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
const constraints = {
  width: { min: 640, ideal: 1920, max: 1920 },
  height: { min: 400, ideal: 1080 },
  aspectRatio: 1.777777778,
  frameRate: { max: 30 },
  facingMode: { exact: 'user' },
};
 1
2
3
4
5
6
7
2
3
4
5
6
7
| Width | Height | Aspect Ratio | 
|---|---|---|
| 1280 | 720 | 16:9 | 
| 960 | 720 | 4:3 | 
| 640 | 360 | 16:9 | 
| 640 | 480 | 4:3 | 
| 320 | 240 | 4:3 | 
| 320 | 180 | 16:9 | 
参考:
https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings
https://webrtchacks.com/how-to-figure-out-webrtc-camera-resolutions/