Reputation: 95
I wrote a client for a livestreaming app using Javascript and Agora.IO, and I would like to get a stream URL such as in RTMP or HLS format which users can paste into an external player like VLC to view the livestreams.
The stream object has a play() method which I can use to play a stream in the web browser, but is there any possibility to generate/get a link for the stream? Thanks for help/hints how to accomplish this! Below is my code so far through which I connect to a livestream with a room_number and an user_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
});
});
Upvotes: 1
Views: 3215
Reputation: 116
Thanks for the detailed guide and reference code. I'm following the above code but unable to Set Live Transcoding.
"03:16:14:369 Agora-SDK [DEBUG]: setLiveTranscoding: {"width":640,"height":360,"videoBitrate":400,"videoFramerate":15,"audioSampleRate":48000,"audioBitrate":48,"audioChannels":1,"videoGop":30,"videoCodecProfile":100,"userCount":1,"userConfigExtraInfo":{},"backgroundColor":0,"images":[{"url":"http://www.com/watermark.png","x":0,"y":0,"width":160,"height":160}],"transcodingUsers":[{"x":0,"y":0,"width":640,"height":360,"zOrder":0,"alpha":1,"uid":3882108012}]}"
I'm getting the above response from "rtc.client.setLiveTranscoding(LiveTranscoding)" and nothing is showing in "RTMP Converter" area of agora console.
Upvotes: 0
Reputation: 2898
Agora.io's Web SDK does not provide any methods to access the stream via RTMP because the Agora Web SDK is based on Web RTC which is a different protocol.
Agora.io's Web SDK does support the ability to push the Agora stream to an RTMP url (provided by services such as Facebook Live, YouTube live, Vimeo live, etc) using the setLiveTranscoding
, startLiveStreaming
, and stopLiveStreaming
methods.
// 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")
Full Guide: https://docs.agora.io/en/Interactive%20Broadcast/cdn_streaming_web?platform=Web
Upvotes: 2