Android camera streaming app
I created an Android app to read video data from the camera of an Android device (which has a camera) and stream it to a computer over WiFi.
Reading images from the camera
Android camera2 API was used to read a sequence of images from the camera.
Server
The sequence of images read from the camera is stored as a list in the server class. This class also acts as the server of the TCP connection that connects with the computer. Server class sends images in this list over the TCP connection over WiFi.
Computer
The python code in the computer is acting as the client of the TCP connection and read the images coming through the connection. These images can be saved as a video or a sequence of images if you like. You can also optionally display the live video. Note that there is a lag of the live video when we do both of the above (storage and display) at the same time.
How to use
- Connect both the android device and the computer to the same WiFi network.
- Open the camstrm app on the Android device.
- Note the IP address that is being displayed.
- Start the client python app in the computer.
- Note you have to restart the app every time you make a new connection. Please quit the app completely and start again. Then re-run the client python app.
To get help on the options
python write_vid.py -h
We will get
usage: write_vid.py [-h] [--operation OPERATION] [--camera CAMERA]
[--savetype SAVETYPE] [--savedir SAVEDIR]
camstrm
optional arguments:
-h, --help show this help message and exit
--operation OPERATION
0:video stream with auto focus 1: single image capture 2: focal
stacking video 3: video stream with fixed focus
--camera CAMERA camera ID
--savetype SAVETYPE 0:save as avi video file 1:save as images with
timestamp
--savedir SAVEDIR save directory for the video
--ip IP address of the Android device
E.g: to run in video streaming mode, with camera 0, save the video as an avi video file, in the path given in — savedir argument
python write_vid.py --operation 0 --camera 0 --savetype 0 --savedir /path/to/save/video/file/
To quit : Press the key ‘q’ on the image display window.
or
CRTL + c on the terminal
Please take a look at the code:
Note that this is still in development and there can be bugs. Please make contributions and help make this app better. Thank you.