29

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.

  • 6
    mplayer tv://device=/dev/video – Stefan Oct 20 '10 at 7:13
  • @Stefan: can you? that's too simple! – phunehehe Oct 20 '10 at 8:47
  • "Without installing any extra applications". That's a pretty weird and severe constraint. I would just install something like cheese. – Wim Coenen Oct 20 '10 at 9:43
  • @phunene, well it works for me.... sometimes – Stefan Oct 20 '10 at 13:40
  • @phunehehe: Yes, we can ;-) – echox Oct 20 '10 at 17:36
28

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.

Other Applications

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: $ vlc v4l2:///dev/video0 Also, you can do this from the VLC GUI by going to File->Open Capture Device
  • mplayer: mplayer tv://device=/dev/video01 (from Stefan in the comments)
  • Cheese: This is a photobooth-like app that is very simple to use.
| improve this answer | |
  • VLC is so flexible – Andrew Nov 28 '18 at 4:45
  • 1
    Note that Cheese is super easy to use and comes pre-installed with Ubuntu I believe, which is nice. One can just search for it in the programs menu and launch it from there. – Gabriel Staples Jan 30 '19 at 18:11
  • Neither gst-launch nor vlc work for me, getting various errors. Answer below using guvcview was super simple and worked perfectly. – Apollys supports Monica Aug 19 '19 at 18:53
19

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:

| improve this answer | |
  • 1
    Yeah, pretty cool. I'd like to get rid of the title bar too, though... or rename it. Nice pic BTW, very "zen". – Stefan Reich May 2 '19 at 14:11
  • @StefanReich yes, hiding the title bar would be good. Looks like GNOME does not allow it though: unix.stackexchange.com/questions/420452/… :-( Forgot why I was so happy that day! Life is generally good though, we should be happier. – Ciro Santilli 郝海东冠状病六四事件法轮功 May 2 '19 at 14:19
  • 1
    Very nice, easy, smooth, works perfectly. Should be top answer! – Apollys supports Monica Aug 19 '19 at 18:52
  • 1
    @YanKingYin I'm not sure about this, let me know if you find out something, and also consider opening a separate question. – Ciro Santilli 郝海东冠状病六四事件法轮功 Nov 12 at 14:57
  • 1
    @CiroSantilli郝海东冠状病六四事件法轮功 I just bought a new HD web cam which is supported by Linux (did a web search to find a list of them). Looks like there isn't much I could do with the old one, on Linux. So I just donated it to the sharing shelf in the neighborhood. – Yan King Yin yesterday
7

Or you can try mpv command

mpv /dev/video0
| improve this answer | |
  • /dev/video0 does not exist on my notebook. I guess, I have to activate the webcam first somehow? guvcview does that automatically. – mxmlnkn Mar 20 at 8:30
  • You need to make sure that your webcam is working. I do not know your webcam model and the used Linux distribution so I cannot give you a detail suggestion. – hungptit Mar 20 at 14:19
7

ffplay /dev/video0 is one of the simpler methods, and will work provided you have ffmpeg installed.

To install, use sudo apt install ffmpeg.

| improve this answer | |
2

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)
| improve this answer | |
0

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.

| improve this answer | |
0

Preinstalled on Ubuntu: Cheese. Worked for me.

(As Gabriel Staples pointed out in a comment.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.