In Windows I can open "My Computer" and click on the "Webcam" icon to get a feed from my webcam. I can also take snapshots of that feed.
Can I do the same in Ubuntu? Without installing any extra applications like Photo Booth.
In Windows I can open "My Computer" and click on the "Webcam" icon to get a feed from my webcam. I can also take snapshots of that feed.
Can I do the same in Ubuntu? Without installing any extra applications like Photo Booth.
Since you want an answer "without installing any extra applications like Photobooth," I've tried to give a solution that doesn't depend on very much. Also I'm assuming that your webcam uses "Video4Linux2" and that it is /dev/video0
. If this is a modern webcam and if you only have one, these are pretty good assumptions.
From the command line:
$ gst-launch-0.10 v4l2src device=/dev/video0 ! xvimagesink
Note that "v4l2src" contains a lowercase L and not the number 1. On your system the command may be gst-launch
or something starting with gst-launch
but with a different version number. Tab completion should help you find the exact command name. This tool is in the gstreamer0.10-tools
package on my Ubuntu system, which is a dependency of libgstreamer, which is a dependency of a large number of the apps on my Ubuntu system and is likely present in the default installation.
If you don't mind installing other applications, here is how you can do this in a few other applications. All of them can easily be installed via apt-get
or another package manager of your choosing:
$ vlc v4l2:///dev/video0
Also, you can do this from the VLC GUI by going to File->Open Capture Devicemplayer tv://device=/dev/video01
(from Stefan in the comments)guvcview
was super simple and worked perfectly.
Aug 19, 2019 at 18:53
guvcview
This program is ideal for screencasts, as it can show just the camera on a window and nothing else:
sudo apt-get install guvcview
guvcview
Then just use any screen recorder to make a feed. recordmydesktop
works fine.
Tested on Ubuntu 18.04.
Related questions:
ffplay /dev/video0
is one of the simpler methods, and will work provided you have ffmpeg installed.
To install, use sudo apt install ffmpeg
.
Or you can try mpv command
mpv /dev/video0
/dev/video0
does not exist on my notebook. I guess, I have to activate the webcam first somehow? guvcview does that automatically.
A slightly different syntax worked for me using mplayer:
mplayer -tv device=/dev/video1 tv://
I am using a plugged-in webcam (not the built-in). So I changed /dev/video0
to /dev/video1
. But Stefan's syntax above seemed to default to the built-in because of an argument parsing error. See marked lines in the output:
baxelrod@it6598 ~ $ mplayer tv://device=/dev/video1
MPlayer 1.2.1 (Debian), built with gcc-5.3.1 (C) 2000-2016 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing tv://device=/dev/video1.
The filename option must be an integer: dev/video1 <--
Struct tv, field filename parsing error: dev/video1 <--
TV file format detected.
...
Selected device: Integrated Camera <--
...
When I use the syntax I posted, I don't get the error lines, and I get this instead:
Selected device: UVC Camera (046d:081b)
Preinstalled on Ubuntu: Cheese. Worked for me.
(As Gabriel Staples pointed out in a comment.)
To stream camera over network
cat << EOF > index.html
<html><head><script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script></head>
<body><video id="video"></video>
<script>
var video = document.getElementById('video');
var videoSrc = '/playlist.m3u8';
if (Hls.isSupported()) {
var hls = new Hls();
hls.loadSource(videoSrc);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function() {
video.play();
});
}
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = videoSrc;
video.addEventListener('loadedmetadata', function() {
video.play();
});
}
</script></body></html>
EOF
gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! x264enc ! mpegtsmux ! hlssink max-files=5 &
python3 -m http.server --port 8080
On other side
vlc http://192.168.0.2:8080/playlist.m3u8
or open in browser http://192.168.0.2:8080/index.html
, then right button click on image -> play.