sjkummer / janus-gateway-js

Janus-gateway WebRTC client for Node.js and the browser.
MIT License
175 stars 56 forks source link

Video resolution #131

Closed smyrgeorge closed 3 years ago

smyrgeorge commented 3 years ago

Hello!

Is there any way to set the video resolution? I'm trying to create a video room plugin.

According to the documentation, in order to set the video resolution we need to do something as follows:

...

function publishOwnFeed(useAudio) {
    // Publish our stream
    $('#publish').attr('disabled', true).unbind('click');
    sfutest.createOffer(
        {
            // Add data:true here if you want to publish datachannels as well
      media: { audioRecv: false, videoRecv: false, audioSend: useAudio, videoSend: true, video: "hires"},

....

The above piece of code is from janus videoroomtest.js file. Note the video: "hires". In this case everything worked fine, the resolution of the video was 1280x720.

I tried to create something similar:

...

VideoRoomPlugin.prototype.processLocalVideo = function (info: JoinInfo) {
  let options = {audio: true, video: true}
  return new Promise(resolve => {
    this.getUserMedia(options)
      .then(stream => {
        this.createPeerConnection()
        stream.getTracks().forEach((track: MediaStreamTrack) => this.addTrack(track, stream))
      })
      .then(() => this.createOffer({media: {video: 'hires'}}))
      .then(jsep => this.configure(options, jsep))

...

But it didn't work, the resolution was the default (640x480) Any help?

sjkummer commented 3 years ago

Choosing a specific resolution in WebRTC can be done by setting constraints when calling getUserMedia() locally, see: https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints#properties_of_video_tracks

When using this library, the WebRTC stuff in encapuslated. You can try something as follows. I did not test this code (sorry for that). If you can share a complete repo / example its easier to reporduce / test / fix.

var constraints = {
    video: {
        height: {
            ideal: 1080
        },
        width: {
            ideal: 1920
        }
    }
};

this.createPeerConnection({
    constraints
})