4

I'm interested in webRTC's ability to P2P livestream an mp3 audio from user's machine. Only example, that I found is this: https://webrtc-mp3-stream.herokuapp.com/ from this article http://servicelab.org/2013/07/24/streaming-audio-between-browsers-with-webrtc-and-webaudio/

But, as you can see, the audio quality on receiving side is pretty poor (45kb\sec), is there any way to get a full quality MP3 streaming + ability to manipulate this stream's data (like adjusting frequencies with equalizer) on the each user's sides?

If impossible through webRTC, is there any other flash-plugin or pluginless options for this?

Edit: also I stumbled upon this 'shoutcast kinda' guys http://unltd.fm/ , declaring, that they are using webRTC to deliver top quality radio broadcasting including streaming mp3. If they are, then how?

halfer
  • 19,824
  • 17
  • 99
  • 186
Max Yari
  • 3,617
  • 5
  • 32
  • 56
  • Well, I would assume that you can stream from a server that transcodes from mp3 to OPUS and then once you get the stream on the client side, you can do all the manipulation you want with the Audio API. – Benjamin Trent Feb 18 '15 at 00:47
  • But if we are talking bout peer2peer i.e no server involved here? – Max Yari Feb 18 '15 at 21:39
  • 1
    WebRTC does not directly support MP3 streaming at all. The mp3 would have to be transcoded to PCMA/U or Opus at some point by somebody before being sent over the peerconnection. The only other thing I could think of would be some sort of dataconnection and sending over the mp3 in data chunks and re-compiling them on the other side to play, but I am not sure that is possible. – Benjamin Trent Feb 18 '15 at 21:45
  • I suggest you to change the title slightly to "Full quality MP3 streaming via webRTC" (add a space) to make it better for search. – igorpavlov Feb 20 '15 at 02:59

3 Answers3

3

WebRTC supports 2 audio codecs: OPUS (max bitrate 510kbit/s) and G711. You stick with OPUS, it is modern and more promising, introduced in 2012.

Main files in webrtc-mp3-stream are outdated by 2 years (Jul 18, 2013). I couldn't find OPUS preference in the code, so possibly demo runs via G711.

The webrtc-mp3-stream demo does the encoding job (MP3 as a media source), then it transmits the data over UPD/TCP via WebRTC. I do not think you need to decode it to MP3 on receiver side, this would be an overkill. Just try to enable OPUS to make the code of webrtc-mp3-stream more up-to-date.

Please refer to Is there a way to choose codecs in WebRTC PeerConnection? to enable OPUS to see the difference.

Community
  • 1
  • 1
igorpavlov
  • 3,576
  • 6
  • 29
  • 56
  • Opus sounds intresting (those guys on unltd was reffering to it too) for the moment I can't afford spend a day digging in that webrtc-mp3-stream example, changing codecs ant testing all the possibilities, that I need, it seems like a right way to go, therefore, as bounty can't wait another week, i'm accepting your answer, bounty is yours, thank You. – Max Yari Feb 21 '15 at 13:51
  • Oh wait, I can accept the answer and not award a bounty, oh then, if You don't mind, I will wait a few another days, who knows, maybe some another interesting replies will appear, if not, then bounty is yours) – Max Yari Feb 21 '15 at 13:53
  • btw. is there any reason for the moment, that can make impossible feeding this OPUS stream to web audio api on the both sides, and manipulatin them via one? – Max Yari Feb 21 '15 at 14:06
  • I am not sure I fully understand you, could you please tell us what do you mean under "feeding this OPUS stream to web audio api on the both sides , and manipulating them via one" ? – igorpavlov Feb 21 '15 at 14:11
  • Maybe my English betray me, or I did not understand something about audio api, but I mean using web audio api to play initial audio file on one side and same api to play recieved OPUS stream on another side + ability to manipulate audio data with api, particularly making graphical equalizer e.t.c – Max Yari Feb 21 '15 at 18:12
  • Yes, you can play MP3 within Audio API on sender side, play it on receivers' side, manipulate within Web Audio API to build graphs on both sides etc. Just consider clients' resources, WebRTC itself and audio processing in general can be CPU eating. – igorpavlov Feb 21 '15 at 18:17
  • Thx for your help, we was together with those 50 points for so long, but now it's time for them to go, I hope you will treat them well. – Max Yari Feb 22 '15 at 11:49
  • I'm the author of the WebRTC mp3 stream demo mentioned in the question. The code is already quite old but still works. Checking the SDP in the console I can see the stream is setup using OPUS (48Khz) when using a recent Chrome version. – Eelco May 07 '15 at 18:59
  • Sorry, was G711 for me during tests. Used latest Chrome (on the date of answer was written) – igorpavlov May 16 '15 at 17:31
2

I'm the founder of unltd.fm.

igorpavlov is right but I can't comment answer. We also use OPUS (Stereo / 48Khz) codec over WebRTC. Decoding mp3 ( or any other audio format ) using webaudio then encoding it in OPUS is the way to go. You "just" need to force SDP negotiations to use OPUS.

You should have send us an email you would have saved your 50 points ;)

  • For some reason i did not thought about it, but its really pleasant to see your direct reply, thanks) Those 50 points was tired of sitting in one place. All this WebRTC movement is pretty fascinating, audio streaming is already fully possible, and it seems that full size p2p video streaming is on the way. Ahh future...sadly we have no hoverboards yet. – Max Yari Mar 01 '15 at 23:28
1

You can increase the quality of a stream by setting the SDP to be stereo and increase the maxaveragebitrate:

let answer = await peer.conn.createAnswer(offerOptions);
answer.sdp = answer.sdp.replace('useinbandfec=1', 'useinbandfec=1; stereo=1; maxaveragebitrate=510000');
await peer.conn.setLocalDescription(answer);

This should output a SDP string which looks like this:

a=fmtp:111 minptime=10;useinbandfec=1; stereo=1; maxaveragebitrate=510000

This gives a potential maximum bitrate of 520kb/s for stereo, which is 260kps per channel. Actual bitrate depends on the speed of your network and strength of your signal.

You can read more about the other available SDP attributes at: https://www.rfc-editor.org/rfc/rfc7587

Community
  • 1
  • 1
Kim T
  • 5,770
  • 1
  • 52
  • 79