我希望最后有一个方法可以将 VP9 或 H.264 设置为 SDP 中的首选视频编解码器。
所以我正在我的 SDP 中寻找 m 行:
m=video 9 UDP/TLS/RTP/SAVPF 96 98 100 102 127 97 99 101 125
我的 SDP 的控制台日志:
在这种情况下,我将获取并使用 VP8 (96) 作为视频编解码器,而不是 VP9 (98)。所以我想检查 98/VP9 是否可能/可用,并想将其设置在开始/第一个位置以实际使用它。
到目前为止我得到了什么:
if(sdpOrigin == 'local') {
let lines = sdp.split('\n').map(l => l.trim());
lines.forEach(function(line) {
if (line.indexOf('m=video') === 0) {
let parts = line.substr(28); // Should be avoided!
let vp9_order = parts.indexOf("98");
let array = parts.split(/\s+/);
console.log("array", array); // 96 98 100 102 127 97 99 101 125
if (vp9_order > 0) {
array.splice(vp9_order, 1);
array.unshift("98");
}
console.log("array-new", array); // 98 96 100 102 127 97 99 101 125
// How do I update my SDP now with the new codec order?
}
})
}
在我看来,这种方法很糟糕,因为我得到了想要的 m 行,但我在位置“28”处做了修复子字符串,因此如果之前发生更改,它会中断。
最后,我的 SDP 中应该有以下“m 行”:
m=video 9 UDP/TLS/RTP/SAVPF 98 96 100 102 127 97 99 101 125
有人可以帮我吗?
您应该首先按空格分割该行,然后将其分成适当的字段SDP规范 https://www.rfc-editor.org/rfc/rfc4566:
let fields = line.split(/\s+/);
if (fields[0] === 'm=video') {
let [ type, port, proto, ...formats] = fields;
let vp9_order = formats.indexOf("98");
if (vp9_order > 0) {
formats.splice(vp9_order, 1); // remove from existing position
formats.unshift("98"); // and prepend
}
line = [ type, port, proto, ...formats].join(' ');
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)