The getVideoTracks() method of MediaStream returns an array of video MediaStreamTrack objects in the stream. Learn the MDN ImageCapture camera-track pattern, empty arrays for audio-only streams, filtering with track.kind, stopping the camera while keeping the mic, and comparison with getTracks()—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Track array
03
Filter
kind video
04
Empty
no camera
05
Use case
ImageCapture
06
Status
Baseline widely
Fundamentals
Introduction
A MediaStream can hold both audio and video tracks. When you call getUserMedia({ video: true }), the browser adds at least one camera track. getVideoTracks() gives you only the video ones—handy for stopping the camera, passing a track to ImageCapture, or inspecting screen-share output without touching audio.
MDN: the return value is an array where each entry is a MediaStreamTrack with kind === "video". If there are no video tracks, you get an empty array []. The order of tracks is not guaranteed and may change between calls.
💡
Beginner tip
Use getVideoTracks()[0] when you expect one camera—but always check .length first so you do not call methods on undefined.
Concept
Understanding MediaStream.getVideoTracks()
An instance method that filters the stream’s track set to video tracks only.
Parameters — none.
Return value — array of MediaStreamTrack with kind"video".
Empty array — when the stream has no video tracks (e.g. microphone only).
Order — not defined by the spec; may vary between calls (MDN).
MediaStream.getVideoTracks() is marked Baseline Widely available on MDN (since September 2017). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MediaStream.getVideoTracks()
Returns an array of video MediaStreamTrack objects in the stream.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNo MediaStream.getVideoTracks
Not supported
MediaStream.getVideoTracks()Excellent
Bottom line: Call getVideoTracks() to list, stop, or pass camera tracks to other APIs.
Wrap Up
Conclusion
MediaStream.getVideoTracks() returns every video track in a stream as an array. Use it to stop or disable the camera, count video inputs, or pass a track to ImageCapture—MDN’s example uses getVideoTracks()[0] for photo capabilities.