【问题标题】:Ant Media Server rotates video 90 degreeAnt Media Server 将视频旋转 90 度
【发布时间】:2020-10-14 16:42:55
【问题描述】:

我在使用来自 iOS 的 Ant Media Server WebRTC 流式传输时遇到问题。当我在 iOS 中发布具有纵向模式的流时,它可以在 HLS 播放器上旋转 90 度查看。旋转的视频也被发送到 RTMP 端点。我该如何解决这个问题?

【问题讨论】:

    标签: ant-media-server


    【解决方案1】:

    如果视频作为画布发送,则可以解决此问题。 首先将webRTCAdaptor初始化中的localVideoId注释掉。

            webRTCAdaptor = new WebRTCAdaptor({
                websocket_url : websocketURL,
                mediaConstraints : mediaConstraints,
                peerconnection_config : pc_config,
                sdp_constraints : sdpConstraints,
                localStream: localStream,
                //localVideoId : "localVideo",
                debug:true,
                bandwidth:900,
    

    然后在 ID 为 localVideo 的视频上方添加一个 canvas,并确保它是隐藏的。

                <div class="col-sm-12 form-group">
                <canvas id="canvas" hidden></canvas>
                <video id="localVideo" autoplay muted controls playsinline></video>
            </div>
    

    然后删除脚本末尾的initWebRTCAdaptor(false, autoRepublishEnabled);,并替换为以下代码段:

        var canvas = document.getElementById('canvas');
        var vid = document.getElementById('localVideo');
        var ctx = canvas.getContext('2d');
        function draw() {
        if (canvas.getContext) {
            if(vid.videoHeight!==0){
            canvas.height=vid.videoHeight;
            canvas.width=vid.videoWidth;
            }
            ctx.drawImage(vid,0,0,vid.videoWidth,vid.videoHeight);
         }
       }
    
       //update canvas for every 25ms
    
       setInterval(function() { draw(); }, 50);
    
       //capture stream from canvas
    
       var localStream = canvas.captureStream(25);
    
    
       navigator.mediaDevices.getUserMedia({video: true, audio:true}).then(function 
       (stream) {
            var video = document.querySelector('video#localVideo');
            video.srcObject = stream;
            video.onloadedmetadata = function(e) {
            video.play();
            };
            localStream.addTrack(stream.getAudioTracks()[0]);
                //initialize the WebRTCAdaptor
            initWebRTCAdaptor(false, autoRepublishEnabled);
        });
    

    这将获取视频并作为画布发送。

    【讨论】:

    • 这在电池方面是否有效?我最担心的问题之一是电池,因为大多数用户使用手机进行流式传输或观看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-18
    • 2017-02-02
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多