javascript - agora.io web sdk - 获取外部播放器的流链接

标签 javascript agora.io

我使用 Javascript 和 Agora.IO 为直播应用程序编写了一个客户端,我想获取一个流 URL,例如 RTMP 或 HLS 格式,用户可以将其粘贴到 VLC 等外部播放器中以查看直播。

流对象有一个 play() 方法,我可以用它在网络浏览器中播放流,但是是否有可能生成/获取流的链接?感谢您的帮助/提示如何完成此任务!下面是我到目前为止使用 room_numberuser_id 连接到直播的代码。

var client = AgoraRTC.createClient({
  mode: "live",
  codec: "h264"
});

client.init('my_app_ID', function() {
  console.log("AgoraRTC client initialized");

}, function(err) {
  console.log("AgoraRTC client init failed", err);
});
client.join(null, room_number + "", user_id, function(user_id) {
  console.log(user_id);
});

client.on("stream-added", function(t) {
  var stream = t.stream;

  client.subscribe(stream, {
    video: !0,
    audio: !0
  });

  client.on("stream-subscribed", function(e) {
    var t = e.stream;
    t.play('agora_remote'); // plays the stream into a DIV element
  });
});

最佳答案

Agora.io 的 Web SDK 不提供任何通过 RTMP 访问流的方法,因为 Agora Web SDK 基于 Web RTC,这是不同的协议(protocol)。

Agora.io 的 Web SDK 支持使用 setLiveTranscoding 将 Agora 流推送到 RTMP url(由 Facebook Live、YouTube live、Vimeo live 等服务提供),startLiveStreamingstopLiveStreaming 方法。

// CDN transcoding settings.
var LiveTranscoding = {
            // Width of the video (px). The default value is 640.
            width: 640,
            // Height of the video (px). The default value is 360.
            height: 360,
            // Bitrate of the video (Kbps). The default value is 400.
            videoBitrate: 400,
            // Frame rate of the video (fps). The default value is 15. Agora adjusts all values over 30 to 30.
            videoFramerate: 15,
            audioSampleRate: AgoraRTC.AUDIO_SAMPLE_RATE_48000,
            audioBitrate: 48,
            audioChannels: 1,
            videoGop: 30,
            // Video codec profile. Choose to set as Baseline (66), Main (77), or High (100). If you set this parameter to other values, Agora adjusts it to the default value of 100.
            videoCodecProfile: AgoraRTC.VIDEO_CODEC_PROFILE_HIGH,
            userCount: 1,
            userConfigExtraInfo: {},
            backgroundColor: 0x000000,
            // Sets the output layout for each user.
            transcodingUsers: [{
                    x: 0,
                    y: 0,
                    width: 640,
                    height: 360,
                    zOrder: 0,
                    alpha: 1.0,
                   // The uid must be identical to the uid used in Client.join.
                    uid: 1232,
                  }],
          };

client.setLiveTranscoding(LiveTranscoding);

// Adds a URL to which the host pushes a stream. Set the transcodingEnabled parameter as true to enable the transcoding service. Once transcoding is enabled, you need to set the live transcoding configurations by calling the setLiveTranscoding method. We do not recommend transcoding in the case of a single host.
client.startLiveStreaming("your RTMP URL", true)


// Removes a URL to which the host pushes a stream.
client.stopLiveStreaming("your RTMP URL")

完整指南:https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_web?platform=Web

关于javascript - agora.io web sdk - 获取外部播放器的流链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58472472/

相关文章:

javascript - 在 Jest 中排序的单元测试用例

flutter - SELinux Denial,同时进行视频通话和转录

android - Agora 视频通话布局

java - Agora.io 视频聊天创建 Activity

javascript - 带动画 CSS 的图像 + 提交按钮悬停

javascript - Node.js:请求页面并允许页面在抓取之前构建

audio - Agora 和 WebRTC(Web 实时通信)有什么区别?

javascript - 我使用 agoraIO web app sdk 创建了应用程序但无法加入视频通话

javascript - 如何将 javascript 函数绑定(bind)到 DOM 上动态添加的元素?

javascript - fadein() 在 fadeout() 之后不起作用