Contents

Raspberry Pi Security Cam From Scratch: Sending and Receiving Videos [Part 3]

This post will cover the basic function of the project, sending and receiving videos.

I choose the official API for camera sending usage. My site also have a copy with a table of content that helps you navigate the content. It is a higher level implementation of OpenMAX. There is also a Python library for Pi camera that you can use.

Save Video Locally

Run raspivid --timeout 0 --bitrate 800000 --segment 10000 -v -a 4 -a %Y-%m-%d-%X --output video_%c.h264 in the terminal of Pi.
--timeout 0 : It will run the camera until a manually interruption.
--bitrate 800000 The bitrate is 0.8Mbits/s.
--segment 10000 The video is broken into 10 seconds segment each.
-v You can see all information in the terminal.
-a 4 -a %Y-%m-%d-%X It will make a timestamp caption in the video.
--output video_%c.h264 It will output to a timestamp file name.

There are also many options to customize. You can check out the official documentation for more details.

Receiving Video from Another Machine

Receiving

The above code does the following things

  • Receive data via the port number on the top.
  • Write the data into a file with current time in binary mode. The video duration can be adjusted at the top.
  • Clean old videos in a given interval.

You can check out the raw file and run python pi_cam_server.py to initial the server.

Sending Video

When you run the server code, it will output your local IP address. The local IP address will be used.
You will also copy the port number from the server code. My code is 12345, you can change to other number you like. Note: port number 0 - 1024 are reserved for special usage.
Once the receiving code is running. Run the following commend in the terminal of Pi.
raspivid -t 0 --bitrate 100000 -n -v -o udp://YOUR-ADDRESS:PORT-NUMBER -ih -a 4 -a %Y-%m-%d-%X
The sending commend is the same as the one in saving locally. But the output file is now a UDP connection. Replace YOUR-ADDRESS to your address and your port number, e.g. 192.168.86.22:12345.
There are also many options to customize. You can check out the official documentation for more details.

Note
Argument -ih is needed since we are slicing video in the server side. Without adding headers, only the first video can be play by the media player.