04 January, 2010

Mplayer + FFMpeg + /dev/video

I've recently published posts for capturing video from a QuickCam Express using FFMpeg. I also posted how to play live video with MPlayer. That covers storing video or playing live video. Playing or storing video with a camera source seems mutually exclusive.

That said, what if you want to store and play live video simultaneously?

Playing live video while storing the incoming video is do-able using these tools and a first-in-first-out (FIFO).

The trick is to recognize that FFMpeg can support converting a single input file into multiple output files. For instance, you can convert a source video file into two output files as follows:


$ ffmpeg -i source.avi /tmp/output.avi /tmp/output.mpg


This command will take the source file source.avi and generate twin output files /tmp/output.avi and /tmp/output.mpg converting them simultaneously.

Similarly, you can use a video device /dev/video rather than an input video file and generate twin output files by using a similar command:


$ ffmpeg -r 15 -s 352x288 -f video4linux -i /dev/video0 /tmp/output.avi /tmp/output.mpg


While cool and closer, attempting to play the file will eventually reach the file end and terminate. Instead, by using a FIFO as an output file and using this FIFO as the input to Mplayer you've accomplished your goal.


$ mkfifo /tmp/vidPipe
$ ffmpeg -y -f video4linux -r 15 -s 352x288 -i /dev/video0 -f avi -vcodec msmpeg4 /tmp/vidPipe /tmp/output.avi


In another terminal window play the fifo with Mplayer using the following command:

$ mplayer /tmp/vidPipe


I love it when a plan comes together.

03 January, 2010

Playing QuickCam Video Stream with Mplayer

I've been toying with developing a Tk UI for multiple video sources, something like a video surveillance or situational awareness console.

I've made some notable progress embedding mplayer into multiple UI frames using precollected video source files and next needed to integration a 'live' video stream. That required determining the 'secret sauce' of arguments to get mplayer to recognize my QuickCam Express webcam....don't laugh, I've had it for years.

For those of you that are interested, the secret sauce is:

$ mplayer -fps 20 -tv driver=v4l:width=352:height=288:device=/dev/video0:outfmt=bgr24 tv://


Cheers.