开发者社区> 问答> 正文

使用Web RTS 如何获取视频的实时数据

使用Web RTS服务如何获取当前视频的实时码率/传输速率? 请问有提供对应的API可以使用嘛。 如果没有请问是否有其他方法可以获取视频的实时码率或者传输速率

展开
收起
游客xz6yeal5zv3s2 2023-04-04 16:40:03 419 0
2 条回答
写回答
取消 提交回答
  • 公众号:网络技术联盟站,InfoQ签约作者,阿里云社区签约作者,华为云 云享专家,BOSS直聘 创作王者,腾讯课堂创作领航员,博客+论坛:https://www.wljslmz.cn,工程师导航:https://www.wljslmz.com

    在阿里云视频直播中使用 Web RTS 服务,可以通过调用 Web RTS SDK 中的 API 获取当前视频的实时码率和传输速率。

    Web RTS SDK 提供了多个 API 来获取视频码率和传输速率,其中最常用的是 getVideoStats() 方法,该方法可以返回一个包含视频码率和传输速率等信息的对象。

    2023-04-25 16:22:50
    赞同 展开评论 打赏
  • 坚持这件事孤独又漫长。
    • 可以使用阿里云视频云服务提供的WebRTC SDK中的API来获取实时码率和传输速率。具体来说,可以通过监听 onStatistics 事件来获取视频 track 的实时码率、传输速率等统计信息。示例代码如下:
    var client = AgoraRTC.createClient({mode: 'live', codec: 'h264'});
    // ...
    client.on('stream-published', function(evt){
        console.log('Publish local stream successfully');
    });
    client.on('stream-added', function(evt){
        console.log('New stream added: ' + evt.stream.getId());
        // Subscribe to the remote stream
        client.subscribe(evt.stream, function(err){
            console.log('Failed to subscribe to remote stream with error ' + err);
        });
    });
    client.on('stream-subscribed', function(evt){
        var stream = evt.stream;
        console.log('Subscribe remote stream successfully: ' + stream.getId());
        // Play the remote stream
        stream.play('remote-video');
    
        // Listen to the "onStatistics" event to get the statistics information
        stream.getVideoTrack().on('onStatistics', function(statistics) {
            console.log('Video track statistics:', statistics);
            console.log('Video track bitrate:', statistics.bitrate);
            console.log('Video track framesPerSecond:', statistics.framesPerSecond);
            console.log('Video track packetLossRate:', statistics.packetLossRate);
            // ...
        });
    }); 
    client.init(appId, function(){
        console.log('AgoraRTC client initialized');
        client.join(null, channelName, null, function(uid){
            console.log('User ' + uid + ' join channel successfully');
            // Create a local stream
            var localStream = AgoraRTC.createStream({video: true, audio: false});
            // Publish the local stream
            client.publish(localStream, function(err){
                console.log('Failed to publish local stream with error: ' + err);
            });
            // Play the local stream
            localStream.play('local-video');
        });
    }, function(err){
        console.log('Failed to initialize AgoraRTC client with error: ' + err);
    });
    

    在上面的代码中,我们通过 stream.getVideoTrack() 获取到视频 track,并监听了其 onStatistics 事件。当该事件触发时,我们可以通过 statistics 参数来获取到视频的实时码率、传输速率等统计信息。

    2023-04-13 21:15:44
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
+ 订阅
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载