plutocam 0.1.0
communicate with a lewei camera module
License: Apache License, Version 2.0
Requires Python: >=3.7

plutocam
=========

Python package to communicate with a Pluto's camera module. 

# Pluto Camera Live Stream Setup Guide

## Prerequisites

Before setting up the Pluto camera live stream, ensure you have the following prerequisites installed on your system:

- [Python](https://www.python.org/downloads/) (if not installed already)
- [FFmpeg](https://ffmpeg.org/download.html) (for your operating system)

## Installation Steps

### Step 1: Download FFmpeg

Download FFmpeg from one of the following sources:
- [Official FFmpeg Website](https://ffmpeg.org/download.html)
- [FFmpeg Builds on GitHub](https://github.com/BtbN/FFmpeg-Builds/releases)

### Step 2: Install FFmpeg

Follow the installation instructions based on your operating system:
- **Windows:** [FFmpeg Installation Guide for Windows](https://phoenixnap.com/kb/ffmpeg-windows)
- **Linux:** [Install FFmpeg on Ubuntu](https://phoenixnap.com/kb/install-ffmpeg-ubuntu)
- **Mac:** [FFmpeg Installation Guide for Mac](https://phoenixnap.com/kb/ffmpeg-mac)

### Step 3: Install Python

If Python is not installed on your system, download and install it from the [official Python website](https://www.python.org/downloads/).

### Step 4: Install pylwdrone

Install the `plutocam` library using pip:
```bash
pip install plutocam
```

## Streaming Setup
### Step 5: Connect to Pluto Camera
Ensure you are connected to the Pluto camera before proceeding.

### Step 6: Start the Stream
Open a terminal and run the following command:

```bash
plutocam stream start --out-file - | ffplay -i -fflags nobuffer -flags low_delay -probesize 32 -sync ext -
```
This command initiates the live stream from the Pluto camera using pylwdrone and FFmpeg.

### Additional Resources
For more information refer [pluto projects with Python](https://github.com/DronaAviation/PLUTO_PYTHON_WRAPPER).

## Now, you are ready to enjoy live streaming from your Pluto camera!

## Example Command-line Usage

#### Stream live video
```
$ plutocam stream start --out-file - | ffplay -i -fflags nobuffer -flags low_delay -probesize 32 -sync ext -
```

#### Record live video then replay later
```
$ plutocam rec start
$ plutocam rec stop
$ plutocam rec list
index  start              duration  path
[  0]  20200604_04:01:27        95  /mnt/Video/20200604-040126.mp4
[  1]  20200604_04:10:40        20  /mnt/Video/20200604-041040.mp4
success
$ plutocam rec play 0 --out-file - | ffplay -i -
```

## Example Module Usage

#### Creating the object
```
>>> import plutocam
>>> drone = plutocam.LWDrone()
```

#### Stream live video
```
>>> for frame in drone.start_video_stream():
>>>     sys.stdout.buffer.write(frame.frame_bytes)
```

#### Get a file
```
>>> with open('video.mp4', 'wb') as fp:
>>>     drone.get_file('/mnt/Video/20200604-041040.mp4', fp)
```

#### Take a picture
```
>>> with open('picture.jpg', 'wb') as fp:
>>>     fp.write(drone.take_picture().data)
```

#### Start and stop recording
```
>>> drone.set_record_plan()
>>> drone.set_record_plan(RecordPlan(active=False))
```