zoukankan      html  css  js  c++  java
  • WebRTC视频采集中的约束有哪些和具体的使用方法

    约束

    • width : 宽度约束

    • height :高度约束

    • aspectRatio: 比率

    • frameRate: 帧率

    • facingMode : 摄像头控制

      • user:前置摄像头
      • environment :后摄像头
      • left : 前置左摄像头
      • right:前置右摄像头
    • resizeMode: 采集的画面需不需要裁剪

    实战案例

    vim index.html

    <html>
      <head>
        <title>WebRTC 获取视频和音频</title>
      </head>
      <body>
        <div>
        <label>audio Source:</label>  
    		<select id="audioSource"> </select>
        </div>
       <div>
        <label>audio Output:</label>  
    		<select id="audioOutput"> </select>
        </div>
       <div>
        <label>video Source:</label>  
    		<select id="videoSource"> </select>
        </div>
    		
          
        <video autoplay playsinline id="player"></video>
        <script src="http://webrtc.github.io/adapter/adapter-latest.js"></script>
        <script src="./js/client.js"></script>
      </body>
    </html>
    

    vim client.js

    "use strict"
    
    // 获取设备
    var audioSource = document.querySelector("select#audioSource");
    var audioOutput = document.querySelector("select#audioOutput");
    var videoSource = document.querySelector("select#videoSource");
    
    // 查找视频播放的标签
    var videoplay = document.querySelector("video#player");
    
    if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia){
      console.log("获取音视频方法不存在");
    }else{
      
      //---------------- 主要进行约束的地方- -----------------
      var constraints = {
        video : {
          // 宽度在300 - 640之间进行自适应
          width : {
          	min: 300,
            max: 640,
          },
          height: 480,
          frameRate: 15
          facingMode: enviroment // 设置为前置摄像头
          
        },
        audio : false
      };
      
      navigator.mediaDevices.getUserMedia(constraints)
      	.then(gotMediaStream).then(gotDevices)
      	.catch(handleError);
    }
    
    function gotMediaStream(stream){
      // 复制流到video标签
      videoplay.srcObject = stream;
      // 获取流成功之后还可以继续操作
      return navigator.mediaDevices.enumerateDevices();
      
      
    }
    function handleError(err){
      console.log("错误啦:", err)
    }
    
    
    function gotDevices(deviceInfos){
      deviceInfos.forEach(function(deviceinfo){
        var option = document.createElement("option");
        option.text = deviceinfo.label;
        option.value = deviceinfo.deviceId;
        
        
        // 音频输入
        if(deviceinfo.kind === "audioinput"){
          audioSource.appendChild(option);
          
        // 音频输出
        }else if(deviceinfo.kind === "audiooutput"){
           audioOutput.appendChild(option);
          
        // 视频输入
        }else if(deviceinfo.kind === "videoinput"){
           videoSource.appendChild(option);
        }
      })
    }
    
  • 相关阅读:
    使用BackgroundWorker组件进行异步操作编程《转》
    C#多线程控制进度条之长任务操作《转》
    模态进度条窗体实现<转>
    dev xtraReports使用《转》
    客户端IP
    WebService获取服务端硬件信息和客户端IP,MAC,浏览器信息,所在城市《转》
    c#多线程 Invoke方法的使用<转>
    C# windowform进度条《转》
    XtraReports 打印控件的简单使用《转》
    hdu Marriage Match II
  • 原文地址:https://www.cnblogs.com/fandx/p/12142320.html
Copyright © 2011-2022 走看看