WebRTC getusermedia constraints peer js

822 views
Skip to first unread message

Dedode winweb

unread,
Mar 27, 2015, 7:54:02 PM3/27/15
to discuss...@googlegroups.com
  WebRTC Camera constraints   I am trying to set the getusermedia video constraints like setting min/max frame-rates and resolutions etc... in my peer.js webrtc application which is a simple peer to peer chat application. I have being trying to integrate it into my application but it seems to break it.Any help would be greatly appreciated other online tutorials look different to my app set up. Down at function 1 is where I have been trying to set the constraints it just doesn't show the video anymore. is this the correct place?.
    
 Also will these constraints work on a video-file playing instead of the webcam?. I am using the Google chrome flags that plays a video  file instead of a camera.
    Many thanks for people taking the time to look at this for me, as I am a WebRTC newbie.




     navigator.getWebcam = (navigator.getUserMedia ||
                    navigator.webkitGetUserMedia ||
                    navigator.mozGetUserMedia ||
                    navigator.msGetUserMedia);
                
                // PeerJS object ** FOR PRODUCTION, GET YOUR OWN KEY at http://peerjs.com/peerserver **
                var peer = new Peer({
                    key: 'XXXXXXXXXXXXXXXX',
                    debug: 3,
                    config: {
                        'iceServers': [{
                            url: 'stun:stun.l.google.com:19302'
                        }, {
                            url: 'stun:stun1.l.google.com:19302'
                        }, {
                            url: 'turn:numb.viagenie.ca',
                            username: "XXXXXXXXXXXXXXXXXXXXXXXXX",
                            credential: "XXXXXXXXXXXXXXXXX"
                        }]
                    }
                });
                
                    // On open, set the peer id so when peer is on we display our peer id as text 
                    peer.on('open', function(){
                    $('#my-id').text(peer.id);
                    });
                    
                    peer.on('call', function(call) {
                    // Answer automatically for demo
                    call.answer(window.localStream);
                    step3(call);
                    });
                    
                    // Click handlers setup
                    $(function() {
                    $('#make-call').click(function() {
                    //Initiate a call!
                    var call = peer.call($('#callto-id').val(), window.localStream);
                    step3(call);
                    });
                    $('end-call').click(function() {
                    window.existingCall.close();
                    step2();
                    });
                    
                    // Retry if getUserMedia fails
                    $('#step1-retry').click(function() {
                    $('#step1-error').hide();
                    step();
                    });
                    
                    // Get things started
                    step1();
                    });
                    
                    
                    
                    
                    
                    
                   // this is where I am setting the constraints and it is breaking it  
                    function step1() {
                    //Get audio/video stream
                    navigator.getWebcam(
        var constraints = {
                       audio: false,
                       video: {
                           mandatory : {
                                 maxWidth: 280,
                                 minHeight: 420 
                           }
                       }
            };}, function(stream){
                    // Display the video stream in the video object
                    $('#my-video').prop('src', URL.createObjectURL(stream));
                   
                   
               
                
               
                // Displays error  
                window.localStream = stream;
                step2();
                }, function(){ $('#step1-error').show(); });
                }
                
                function step2() { //Adjust the UI
                $('#step1', '#step3').hide();
                $('#step2').show();
                }
                
                function step3(call) {
                // Hang up on an existing call if present
                if (window.existingCall) {
                window.existingCall.close();
                }
                
                // Wait for stream on the call, then setup peer video
                call.on('stream', function(stream) {
                $('#their-video').prop('src', URL.createObjectURL(stream));
                });
                $('#step1', '#step2').hide();
                $('#step3').show();
                }
            
             

Harald Alvestrand

unread,
Mar 29, 2015, 4:06:16 AM3/29/15
to discuss...@googlegroups.com
With these constraints:

                    video: {
                           mandatory : {
                                 maxWidth: 280,
                                 minHeight: 420 
                           }
                       }

you are asking for a video that is no wider than 280 pixels, and it has to be at least 420 pixels wide.

That's a very tall and skinny video. Are you sure that's what you want?

(I'm not sure we actually support any format that's this tall and skinny....)


--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dedode winweb

unread,
Mar 30, 2015, 8:02:59 AM3/30/15
to discuss...@googlegroups.com
Hey Harald many thanks for the time you have taken to help me out . Yeah sorry my  resolution is wrong,  I was also wondering how to implement the constraints into my javascript the JavaScript I wrote there in my example was wrong and was breaking. This was my original code before I broke it cheers


 function step1() {
//Get audio/video stream

navigator.getWebcam({audio: true, video: true}, function(stream){

Dedode winweb

unread,
Mar 30, 2015, 8:07:31 AM3/30/15
to discuss...@googlegroups.com
Hey Harald many thanks for the time you have taken to help me out . Yeah sorry my  resolution is wrong,  I was also wondering how to implement the constraints into my javascript the JavaScript I wrote there in my example was wrong and was breaking. This was my original code before I broke it cheers


 function step1() {
//Get audio/video stream

navigator.getWebcam({audio: true, video: true}, function(stream){

    // Display the video stream in the video object
    $('#my-video').prop('src', URL.createObjectURL(stream));




                        // Displays error  
                        window.localStream = stream;
                        step2();
                    }, function(){ $('#step1-error').show(); });
                }
On Friday, 27 March 2015 23:54:02 UTC, Dedode winweb wrote:

Vikas

unread,
Mar 30, 2015, 1:50:33 PM3/30/15
to discuss...@googlegroups.com
Hi,

You can check the code for constraints demo. 

Vikas

Dedode winweb

unread,
Mar 30, 2015, 3:22:08 PM3/30/15
to discuss...@googlegroups.com
Cheers Vikas 
                      Had a look at that, trying to work out how to adjust that to my peerjs application. I guess my main question is will these constraints work on a video-file playing instead of the webcam? ie  with use-file-for-fake-video-capture=/path/to/video.y4m. I am using the Google chrome flags that plays a video  file instead of a camera and is there any constraints that will change/effect the video, 
by setting min/max frame-rates and resolutions etc... Also can you set the bitrate in webrtc through these constraints ?

Many thanks

On Friday, 27 March 2015 23:54:02 UTC, Dedode winweb wrote:

Vikas

unread,
Mar 30, 2015, 5:47:44 PM3/30/15
to discuss...@googlegroups.com
Hi,

Yes the constraints should work for file as well. As long as the constraints (resolution and framerate) provided via GetUserMedia are less than the resolution/framerate for the file. You need these flags --use-fake-device-for-media-stream --use-file-for-fake-video-capture=bla.y4mAs a side note, only YUV420 formats are supported. 

Regarding bitrate, you can modify the b=AS attribute in sdp. 

/Vikas

Dedode winweb

unread,
Mar 31, 2015, 8:51:58 AM3/31/15
to discuss...@googlegroups.com
Cheers Vikas I have the flags working perfect so it plays the video instead of the camera , my main problem is getting  the constraints to work in my application.. So for example lets say as soon as I launch my application even before I make a call to the other peer these constraints should take effect on my camera/video file  ? 
Cheers 


On Friday, 27 March 2015 23:54:02 UTC, Dedode winweb wrote:

Dedode winweb

unread,
Mar 31, 2015, 8:16:59 PM3/31/15
to discuss...@googlegroups.com
Cheers guys finally got the constraints working :) thanks everybody for your help 


On Friday, 27 March 2015 23:54:02 UTC, Dedode winweb wrote:
Reply all
Reply to author
Forward
0 new messages