Accessing Your Webcam in HTML5

Hello, do you have a tutorial about how to send that stream to a RTMP server?

Thanks
Jaime

No - that gets too much into the weeds of whatever service you end up using. The closest is this article: https://www.kirupa.com/html5/simple_video_chat_with_webrtc.htm

:grinning:

Hey, This was awesome. I teach Carpentry and in 5 minutes with a little copy and pasting and some pruning I got it to work for my needs. 2 questions, can you select another video device? The default is the webcam on my laptop. I have a GoPro HERO 8 that I want to be able to display onto (into) chrome as a document camera work around. If I can do it, how? I basically need to identify a new source for the video… remember I’m a carpenter so go… s…l…o…w. Cheers, Peter

We’ll have to wait for the full instructions from Kirupa, but the short version is:

Thanks for the quick reply. I have the GoPro desktop utility and it will allow the go pro to be used in Zoom, go to meeting ect. I want to be able to use the camera outside of social media/meeting applications. I could use chrome to “host” the video.

I am not sure where in the HTML5 code to place the enumerateDevices command. I have tried several places but haven’t gotten it to execute. Any advice?

The quicktime app can select a connected IOS device as a Camera. But Chrome (for example) does not see it among the selectable cameras… is there a way to access a connected ios device’s screen like quicktime does for ios screen recording to mac?

No, tethered devices showing up is dependent on whether the device registers itself as a camera the browser can detect. One day, maybe :stuck_out_tongue:

Can I use this to record a video and save it on my server?
If not what could I use?

Just noting here that I (foolishly, perhaps) tried to customize the initial code example by using jQuery, only to have it fail over and over and over. For some reason, you cannot simply select the video element like you normally would in jQuery, even if you try to grab it by ID.

Won’t Work: $("#videoElement");

WILL Work: $("#videoElement")[0];

That is so bizarre! When you console.log the first example, what element is printed to the screen

If I don’t use the array notation [0] and then console.log the result, no video shows in the browser (no errors, either), and Chrome displays this in the console:

Yeah! Based on your console output, the actual element itself is referenced by the 0. That’s so strange but glad you were able to make it work.

Hi. I am using angularjs to build a web application.
I will be accessing the webcam through an IP and port over the lan to video stream and take picture.
I am able to do it through the laptop webcam but stuck up in accessing the webcam through IP and port.
Can you pls guide me how to achive this?

Are you able to access the webcam via the IP to see the picture?

For example, see if you can do something like the following:

<img id="mywebcam" border="0" width="1920" height="1080" src="http://192.168.1.1:8080/video">

Hey…sorry to bother you.

I could get it done. Thanks.

But, I have the need to access the webcam in the network through IP and port.

Can it be done?

That’s my question to you - do you have an IP address that gets you access to the webcam? If the answer is “Yes”, then the HTML/CSS/JS side is doable. If the answer is no, then you’ll need to have an intermediary solution to get you that information.

My answer to your question is yes. I have access an IP address to access the webcam which is in the LAN. I am developing a weighbridge system where the user will be sitting in the control room and the camera is setup in the weighbridge console. The user will instruct the driver to move the truck back and forth to get the right image of the container, the vehicle number and take picture to be recorded throug a UI. Let me know how that can be possible please.
TiA

When you paste the IP address in your browser’s address bar, do you see an image?

Kirupa - this was a lifesaver when testing HTML output for my webcam -
There is also a great test page for all Input / Output Audio / video devices in the WebRTC Samples.

1 Like

What to add in this html code:

<html data-kantu="1"><script src="chrome-extension://ljdobmomdgdljniojadhoplhkpialdid/page/prompt.js"></script><script src="chrome-extension://ljdobmomdgdljniojadhoplhkpialdid/page/runScript.js"></script><head>
<meta charset="utf-8">
<meta content="Display Webcam Stream" name="title">
<title>Display Webcam Stream</title>
<style>
    body {
      margin: 30px;
    }

    h1 {
      font-family: sans-serif;
      color: #666;
    }

    #container {
      width: 500px;
      height: 375px;
      border: 10px #333 solid;
    }

    #videoElement {
      width: 500px;
      height: 375px;
      background-color: #666;
    }
    
    button {
      margin-top: 20px;
      font-size: 12px;
      font-weight: bold;
      padding: 5px;
      background-color: white;
      border: 5px solid black;
    }

    button:hover {
      background-color: yellow;
    }

    button:active {
      background-color: yellowgreen;
    }
  </style>
</head>
<body>
<h1>Stop Webcam Stream</h1>
<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<button id="stop">Stop Video</button>
<script>
    var video = document.querySelector("#videoElement");
    var stopVideo = document.querySelector("#stop");

    if (navigator.mediaDevices.getUserMedia) {
      navigator.mediaDevices.getUserMedia({ video: true })
        .then(function (stream) {
          video.srcObject = stream;
        })
        .catch(function (err0r) {
          console.log("Something went wrong!");
        });
    }

    stopVideo.addEventListener("click", stop, false);

    function stop(e) {
      var stream = video.srcObject;
      var tracks = stream.getTracks();

      for (var i = 0; i < tracks.length; i++) {
        var track = tracks[i];
        track.stop();
      }

      video.srcObject = null;
    }
  </script>

</body></html>

to have another button that reactivates the webcam after having stopped it ?
thanks