high quality stereo audio from server

richard-vd

New Member
My source is an RTSP stream with stereo AAC audio. I want to achieve high quality stereo audio encoding in the direction of server to browser. The AAC and Opus bitrates are configurable in flashphoner.properties, but it's still mono. How can I set the Opus and AAC encoders to stereo?

And it is possible to disable audio transcoding for MSE and HLS if the source already is AAC?
 

Max

Administrator
Staff member
Good day.
My source is an RTSP stream with stereo AAC audio. I want to achieve high quality stereo audio encoding in the direction of server to browser. The AAC and Opus bitrates are configurable in flashphoner.properties, but it's still mono. How can I set the Opus and AAC encoders to stereo?
This is a known issue, we already work on it in ticket WCS-2755. We'll let you know in this topic when fix it.
And it is possible to disable audio transcoding for MSE and HLS if the source already is AAC?
In latest versions HLS audio should not be transcoded if stream is published with 2 channels AAC audio with samplerates above 32 kHz (24 kHz and below are not supported). This can be set up using custom SDP file /usr/local/FlashphonerWebCallServer/conf/hls.sdp
Code:
v=0
o=- 1988962254 1988962254 IN IP4 0.0.0.0
c=IN IP4 0.0.0.0
t=0 0
a=sdplang:en
m=video 0 RTP/AVP 112
a=rtpmap:112 H264/90000
a=fmtp:112 packetization-mode=1; profile-level-id=420020
a=recvonly
m=audio 0 RTP/AVP 108 102 103
a=rtpmap:108 mpeg4-generic/48000/2
a=rtpmap:102 mpeg4-generic/32000/2
a=rtpmap:103 mpeg4-generic/44100/2
a=recvonly
Please also check if stream transcoding is disabled for HLS (by default HLS stream is transcoded to 480p)
Code:
hls_player_width=0
hls_player_height=0
MSE supports now only mono AAC with samplerate 48 kHz. We raised the ticket WCS-2810 to implement custom SDP for MSE playback.
 

Max

Administrator
Staff member
Good day.
Since build 5.2.758 it is possible to set up SDP for MSE playback. So you can create mse.sdp file with the following content
Code:
v=0
o=- 1988962254 1988962254 IN IP4 0.0.0.0
c=IN IP4 0.0.0.0
t=0 0
a=sdplang:en
m=video 0 RTP/AVP 112
a=rtpmap:112 H264/90000
a=fmtp:112 packetization-mode=1; profile-level-id=420020
a=recvonly
m=audio 0 RTP/AVP 108 103 96 97 98 99 100 102 104
a=rtpmap:108 mpeg4-generic/48000/2
a=rtpmap:96 mpeg4-generic/8000/2
a=rtpmap:97 mpeg4-generic/11025/2
a=rtpmap:98 mpeg4-generic/12000/2
a=rtpmap:99 mpeg4-generic/16000/2
a=rtpmap:100 mpeg4-generic/22050/2
a=rtpmap:104 mpeg4-generic/24000/2
a=rtpmap:102 mpeg4-generic/32000/2
a=rtpmap:103 mpeg4-generic/44100/2
a=recvonly
to play MSE with stereo sound and prevent excessive audio transcoding on server.
 

Max

Administrator
Staff member
Good day.
We fixed the issue with AAC to Opus transcoding while capturing RTSP with stereo audion and playing it as WebRTC in build 5.2.764. Please update and check.
 

richard-vd

New Member
I updated to 5.2.784 and set up the custom SDP files for MSE and HLS as per your postings. I can confirm audio is now stereo and the quality is great when streaming to MSE and HLS from my RTSP source.

However, over WebRTC (using Opus) audio is still mono. How do I set the Opus encoder to output stereo audio?
 

richard-vd

New Member
It makes no difference whether or opus_formats=stereo=1 exists in flashphoner.properties. Safari and Chrome are always mono and Firefox is always stereo.
 

Max

Administrator
Staff member
We raised the internal ticket WCS-2917. Please keep this link working.
 

Max

Administrator
Staff member
Good day.
We've done some investigations. Unfortunately, this is a Chrome known bug: Chrome can publish stereo via WebRTC, but cannot play (it allways plaing as downmix to mono). This affects all the Chromium-based browsers, and Safari too, because it's based on Webkit which relates to Chromium too.
So the only workaround is to play HLS or MSE in browser for stereo sound.
We will add this to docs. You can stop your RTSP stream.
 

richard-vd

New Member
Thanks for pointing me to that thread! In comment #16 and #25 a workaround is described and demoed:
ossu@webrtc.org said:
We've found a workaround by doing some more SDP munging: the stereo=1 parameter needs to be added to both the local and the remote SDP during negotiation, rather than just the remote (IIRC) as it used to.
So I went ahead to implement this workaround in flashphoner.js around line 14507:
JavaScript:
//create offer and set local sdp

connection.createOffer(constraints).then(function (offer) {
  
  // workaround for stereo audio in Chrome and Safari
  offer.sdp = offer.sdp.replace('minptime=10', 'minptime=10;stereo=1');
  // end of workaround

  connection.setLocalDescription(offer).then(function () {
    var o = {};
    o.sdp = util.stripCodecs(offer.sdp, options.stripCodecs);
    o.hasAudio = hasAudio;
    o.hasVideo = hasVideo;
    resolve(o);
  });
});
Now stereo audio in Chrome and Safari using WebRTC works!
 

Max

Administrator
Staff member
Good day.
We added a tweak to play stereo in Chrome browser in Web SDK build 0.5.28.2753.151 using this constraint
Code:
constraints.audio.stereo=true
for example
JavaScript:
session.createStream({
    name: streamName,
    display: remoteVideo,
    constraints: {
        audio: {
            stereo: true
        }
    }
    ...
}).play();
 
Top