Published Book on Amazon
![]() |
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1 |
![]() |
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2 |
출판된 한글판 도서
![]() |
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상) |
![]() |
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하) |
Original Book Contents
22.1.6 Viewing Video on an External Computer
Here we talk about how to view video taken in Raspberry Pi on an external computer through a network.
There are a number of ways to view video over the network, but here we explain the way to use <Netcat> program.
22.1.6.1 Basic framework to Transmit/Receive Video Data
Here, we want to use the following framework for video transmission and reception.
|
Briefly explainning, the data taken in Raspberry Pi camera is passed to <Netcat> program, and the <Netcat> program will transfer the data to the specified computer over the network. Then, the <Netcat> program on the remote computer receives the data and passes it to <Mplayer> program. The <Mplayer> program receives the video data and plays it.
To do this, <Netcat> program and <Mplayer> program must be installed on the remoter computer or another programs that has the same role as these programs must be installed on the remoter computer.
22.1.6.2 <Netcat> Program – Transmit/Receive Video via Network
<Netcat> program is a tool that system administrators use a lot, and it has many features. <Netcat> command can be used to send and receive data between specific computers on the network.
● Transmitting Data on the network
On a computer that sends data on the network, it executes command in the following format.
[Command Format]
nc [option] <receiver IP address> <port> |
[Command Overview]
■ This command sends data to the specified destination IP address.
■ User privilege -- Normal user.
[Detail Description]
■ Data transmission and reception are processed using a specific port. The default port used is "5001".
[Main option]
-h, --help | Show help. |
-l | It runs in listen mode. Naturally, the target host is not specified. |
-p | It is used to specify the port and usually used with the -l option. |
● Receiving data from the network
On a computer that receives data from the network, it executes command in the following format.
[Command Format]
nc [option] -p <port> |
[Command Overview]
■ This command receives data coming from the specified port through the network.
■ User privilege -- Normal user.
[Detail Description]
■ Data transmission and reception are processed using a specific port. The default port used is "5001".
[Main option]
-h, --help | Show help. |
-l | It runs in listen mode. Naturally, the target host is not specified. |
-p | It is used to specify the port and usually used with the -l option. |
22.1.6.3 Sending Video Data Using "raspivid" Command
Raspberry Pi does not require a installation because <Netcat> program is installed by default.
In order to transmit the video stream taken by camera in Raspberry Pi to a remoter computer, execute the following command in Terminal program.
[Command Format]
raspivid -t 999999 -o - | nc <receiver IP address> 5001 |
This command first shoots a video continuously on a Raspberry Pi camera with "raspivid" command. The time is set to "999999" because the movie should be shot continuously without stopping. When you shoot a movie, you can specify various other options as needed.
Next, the captured video is sent to standard output without saving it as a file, and then goes through "pipe" and is sent to the <Netcat> program. <Netcat> program sends it to the receiving computer through port "5001" on the remoter.
At this time, in order to designate the remoter computer as the receiver, the IP address of the receiver must be specified.
22.1.6.4 Receiving/Playing a Video on Linux
Here we will use <Netcat> program and <Mplayer> program to receive and play a video stream over a network on a computer whose operating system is Linux. If the particular programs are not installed on the computer, install the program as follows.
<Netcat> program can be installed in the following manner.
sudo apt-get install netcat |
<Mplayer> program can be installed in the following way.
sudo apt-get install mplayer |
Once the program installation is complete, reboot the system and verify that it is working properly.
Run the following command to receive and play a video file transmitted from Raspberry Pi computer on a Linux computer.
nc -l -p 5001 | mplayer -fps 31 -cache 1024 - |
In the above, <Netcat> program is first activated by "nc" command, and receives the video stream coming in through port "5001" and passes it through "pipe" to <Mplayer> program. <Mplayer> program then plays the video using the video stream it receives.
The following is the example screen that a Linux computer actually receives and plays video data through the network.
|
22.1.6.5 Receiving/Playing Video on MS Window
Here, we will use <Netcat> program and <Mplayer> program to play a video stream over the network on a computer running Microsoft Windows. If the particular programs are not installed on the computer, download the program from the following and install it.
■ download MPlayer -- http://mplayerwin.sourceforge.net/
■ download Netcat -- http://joncraton.org/media/files/nc111nt.zip
-- http://packetstormsecurity.com/files/download/31140/nc.exe
When the program installation is completed, execute the following command in the Shell program to receive and play the video transmitted from the remote.
[Path]\nc.exe -l -p 5001 | [Path]\mplayer.exe -fps 31 -cache 1024 - |
If you execute the above command, the video file will be played as follows.
For reference, to get IP address on MS Windows computer, use "ipconfig" command in Shell as follows.
ipconfig |
22.1.6.6 Receiving/Playing Video on Mac
On a Mac computer, you need to install <Mplayer> program. The program can be installed via "port" command as follows.
sudo port selfupdate |
sudo port install mplayer |
For more information on installing the program, please refer to the following resources:
When the program installation is completed, execute the following command in Shell program to receive and play the video transmitted from the remote.
nc -l -p 5001 | mplayer -fps 31 -cache 1024 - |
If you execute the above command, the video file will be played as follows.
|