Google+ Followers

Tuesday, June 25, 2013

26. Streaming Live Video from the RasPiCam to the PC

This is the next step in using the RasPiCam - live video streaming.  I got the instructions from the following link:

Download and install on the PC, the open source (free) programs Netcat and MPlayer.  Netcat is "a computer networking service for reading from and writing to network connections using TCP or UDP" and MPlayer is a media player which can play most movie formats. This download can be conveniently done via the dropbox link by Matthew Manning of Raspberry π IV Beginners:

The files in this zip file can then be unzipped and extracted into a folder whose name should be noted for later access.  I put mine into my C:\Documents and Settings\User\mplayer and netcat\ folder.  As we shall see soon, this location is convenient.

Now we want to download and install these two programs on the Raspberry Pi:

sudo apt-get install mplayer netcat

Now we need to set up a Windows PC to receive a signal.  On the PC (running MS Windows), click 

Start -> All Programs -> Accessories -> Command Prompt

At this point, you can find out what the PC's IP address is by entering ipconfig in the Command Prompt program.  You will need this soon to tell the Pi where to send the video data.

Within the Command Prompt (terminal program) window, go to the directory, where nc and mplayer are (my Command Prompt program goes automatically to C:\Documents and Settings\User\, so I just have to enter cd mplayer and netcat to change directory to the mplayer and netcat directory to get the prompt (>) in the right directory.  

Now enter:

nc -l -p 5001 | mplayer -fps 31 -cache 1024 - 

which commands Netcat to set up a listener (with the -l) on port 5001, and the pipe (|) pipes the data it 'hears' to the MPlayer program, to play at 31 frames per second, with a memory cache size of 1MB. 

On the Pi, to send the video data, enter 

raspivid -t 9999999 -o - | nc 5001 

to run the raspivid program for a long-ish time (9999.999 seconds, or approximately 2¾ hours), the pipe (|) pipes the output of this part of the command to the program nc (Netcat) for transmission to which is the IP address of my PC, found above using the ipconfig command, on port 5001.

When this is done, a tab at the bottom of the PC desktop for MPlayer, opens up and clicking on this opens a full-screen real-time video of whatever the RasPiCam is pointing at.

Here is a screenshot of some video I got from my house window:

The quality's not great, but hey - once again - it's magic.  I could keep an eye on my cruiser (if I had one)!!  Country fans - enjoy the music.

1 comment:

  1. You can use "-t 0" instead "-t 9999999" for infinite recording.