How to use Mplayer to display your webcam

Today I was searching for some Mplayer manual and accidentally I have found a post about using Mplayer as webcam application to show webcam stream or something like that. It was really interesting for me although at first I thought that it would not work but when I tried, did realize that I was wrong and it is possible. In this post I will write about how to use Mplayer to display your webcam stream and in addition, I will explain about how to capture the stream of your webcam in command line without using any GUI tools or application.

Firstly, for using Mplayer to show webcam stream you should use some parameters that use for online streams and TVs in Mplayer. In fact, online streams and TVs are all stream, additionally, webcam output is could be considered stream or to be exact the output of webcam is stream as well. As a result, the command that is used to open your webcam stream and show it in Mplayer is like this.

$ mplayer tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:fps=30:outfmt=yuy2

The above command is quite straightforward and easy but I explain its parameters.

  • tv:// -tv: prepares Mplayer to open stream (TV).
  • driver=v4l2: loads Video4Linux2 driver to use for Mplayer, it is also possible to use v4l1 instead.
  • width,height: set video resolution.
  • device: points to your webcam. Here is /dev/video0 but it is possible yours to be different like /dev/video1.
  • fps: sets frame per second to show, so if this number will be increased then will give better quality.
  • outfmt: sets output format.

Now, if you want to capture the output of your webcam as video, you should use Ffmpeg, or Avconv.

In order to use Ffmpeg to capture video stream of your webcam use below command,

$ ffmpeg -f video4linux2 -s 800x600 -i /dev/video0 MyVideo.mpg 

Above command just capture video and does not capturer audio alongside video, for capturing audio you should add your audio driver as well such as below example,

$ ffmpeg -f alsa -f video4linux2 -s 800x600 -i /dev/video0 MyVideo.mpg 

For capturing webcam stream with Avconv just change ffmpeg word to avconv since Avconv application is successor of Ffmpeg therefore, all Ffmpeg commands work. See example,

$ avconv -f alsa -f video4linux2 -s 800x600 -i /dev/video0 MyVideo.mpg 

For more information please visit following links,
Record audio and video from webcam using ffmpeg
Capture video and audio from webcam using avconv
How to capture a webcam input
Viewing a V4L2 webcam with mplayer

send your idea and information to kasra.madadipouya@geeksweb.eu.org

Leave a Reply