Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ Note that this example produces a raw H264 video. Wrapping it in a video contain
- [`Flip`](#flip)
- [`Codec`](#codec)
- [`SensorMode`](#sensormode)
- [`ExposureMode`](#exposuremode)
- [`AwbMode`](#awbmode)

## `StillCamera`
A class for taking still images. Equivalent to running the `raspistill` command.
Expand All @@ -239,6 +241,13 @@ const stillCamera = new StillCamera({
- [`rotation: Rotation`](#rotation) - *Default: `Rotation.Rotate0`*
- [`flip: Flip`](#flip) - *Default: `Flip.None`*
- `delay: number` - *Default: 1 ms*
- `shutter: number` - *Default: Auto calculated based on framerate (1000000µs/fps). Number is in microseconds*
- `iso: number` - *Default: Auto*
- `exposureCompensation: number` - *Default: `0`*
- [`exposureMode: ExposureMode`](#exposuremode) - *Default: Auto*
- [`awbMode: AwbMode`](#awbmode) - *Default: Auto*
- `analogGain: number` - *Default: 0*
- `digitalGain: number` - *Default: 0*

### `StillCamera.takeImage(): Promise<Buffer>`

Expand Down Expand Up @@ -271,6 +280,13 @@ const streamCamera = new StreamCamera({
- `fps: number` - *Default: 30 fps*
- [`codec: Codec`](#codec) - *Default: `Codec.H264`*
- [`sensorMode: SensorMode`](#sensormode) - *Default: `SensorMode.AutoSelect`*
- `shutter: number` - *Default: Auto calculated based on framerate (1000000µs/fps). Number is in microseconds*
- `iso: number` - *Default: Auto*
- `exposureCompensation: number` - *Default: `0`*
- [`exposureMode: ExposureMode`](#exposuremode) - *Default: Auto*
- [`awbMode: AwbMode`](#awbmode) - *Default: Auto*
- `analogGain: number` - *Default: 0*
- `digitalGain: number` - *Default: 0*

### `startCapture(): Promise<void>`
Begins the camera stream. Returns a `Promise` that is resolved when the capture has started.
Expand Down Expand Up @@ -345,6 +361,44 @@ Image flip options.
import { Flip } from "pi-camera-connect";
```

## `ExposureMode`
Exposure mode options.
- `ExposureMode.Off`
- `ExposureMode.Auto`
- `ExposureMode.Night`
- `ExposureMode.NightPreview`
- `ExposureMode.Backlight`
- `ExposureMode.Spotlight`
- `ExposureMode.Sports`
- `ExposureMode.Snow`
- `ExposureMode.Beach`
- `ExposureMode.VeryLong`
- `ExposureMode.FixedFps`
- `ExposureMode.AntiShake`
- `ExposureMode.Fireworks`

```javascript
import { ExposureMode } from "pi-camera-connect";
```

## `AwbMode`
White balance mode options.
- `AwbMode.Off`
- `AwbMode.Auto`
- `AwbMode.Sun`
- `AwbMode.Cloud`
- `AwbMode.Shade`
- `AwbMode.Tungsten`
- `AwbMode.Fluorescent`
- `AwbMode.Incandescent`
- `AwbMode.Flash`
- `AwbMode.Horizon`
- `AwbMode.GreyWorld`

```javascript
import { AwbMode } from "pi-camera-connect";
```

## `Codec`
Stream codec options.
- `Codec.H264`
Expand Down
30 changes: 30 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ export enum Flip {
Vertical = 'vertical',
Both = 'both',
}

export enum ExposureMode {
Off = 'off',
Auto = 'auto',
Night = 'night',
NightPreview = 'nightpreview',
Backlight = 'backlight',
Spotlight = 'spotlight',
Sports = 'sports',
Snow = 'snow',
Beach = 'beach',
VeryLong = 'verylong',
FixedFps = 'fixedfps',
AntiShake = 'antishake',
Fireworks = 'fireworks'
}

export enum AwbMode {
Off = 'off',
Auto = 'auto',
Sun = 'sun',
Cloud = 'cloud',
Shade = 'shade',
Tungsten = 'tungsten',
Fluorescent = 'fluorescent',
Incandescent = 'incandescent',
Flash = 'flash',
Horizon = 'horizon',
GreyWorld = 'greyworld'
}
81 changes: 81 additions & 0 deletions src/lib/shared-args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { StillOptions } from "./still-camera";
import { StreamOptions } from "./stream-camera";
import { Flip } from '..';

/**
* Get the command line arguments for `raspistill` or `raspivid` that are common among both
*
* These are: `--width`, `--height`, `--rotation`, `--hflip`, `--vflip`, `--shutter`,
* `--ISO`, `--exposure`, `--ev`, and `--awb`
* @param options Camera options
*/
export function getSharedArgs(options: StillOptions | StreamOptions): string[] {
return [

/**
* Width
*/
...(options.width ? ['--width', options.width.toString()] : []),

/**
* Height
*/
...(options.height ? ['--height', options.height.toString()] : []),

/**
* Rotation
*/
...(options.rotation ? ['--rotation', options.rotation.toString()] : []),

/**
* Horizontal flip
*/
...(options.flip &&
(options.flip === Flip.Horizontal || options.flip === Flip.Both)
? ['--hflip']
: []),

/**
* Vertical flip
*/
...(options.flip &&
(options.flip === Flip.Vertical || options.flip === Flip.Both)
? ['--vflip']
: []),

/**
* Shutter Speed
*/
...(options.shutter ? ["--shutter", options.shutter.toString()] : []),

/**
* ISO
*/
...(options.iso ? ['--ISO', options.iso.toString()] : []),

/**
* EV Compensation
*/
...(options.exposureCompensation ? ['--ev', options.exposureCompensation.toString()] : []),

/**
* Exposure Mode
*/
...(options.exposureMode ? ['--exposure', options.exposureMode.toString()] : []),

/**
* Auto White Balance Mode
*/
...(options.awbMode ? ['--awb', options.awbMode.toString()] : []),

/**
* Analog Gain
*/
...(options.analogGain ? ['--analoggain', options.analogGain.toString()] : []),

/**
* Digital Gain
*/
...(options.digitalGain ? ['--digitalgain', options.digitalGain.toString()] : [])
];
}
40 changes: 11 additions & 29 deletions src/lib/still-camera.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import * as si from 'systeminformation';
import { Flip, Rotation } from '..';
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
import { spawnPromise } from '../util';
import { getSharedArgs } from './shared-args';

export interface StillOptions {
width?: number;
height?: number;
rotation?: Rotation;
flip?: Flip;
delay?: number;
shutter?: number;
iso?: number;
exposureCompensation?: number;
exposureMode?: ExposureMode;
awbMode?: AwbMode;
analogGain?: number;
digitalGain?: number;
}

export default class StillCamera {
Expand Down Expand Up @@ -42,35 +50,9 @@ export default class StillCamera {
try {
return await spawnPromise('raspistill', [
/**
* Width
* Add the command-line arguments that are common to both `raspivid` and `raspistill`
*/
...(this.options.width ? ['--width', this.options.width.toString()] : []),

/**
* Height
*/
...(this.options.height ? ['--height', this.options.height.toString()] : []),

/**
* Rotation
*/
...(this.options.rotation ? ['--rotation', this.options.rotation.toString()] : []),

/**
* Horizontal flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both)
? ['--hflip']
: []),

/**
* Vertical flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Vertical || this.options.flip === Flip.Both)
? ['--vflip']
: []),
...getSharedArgs(this.options),

/**
* Capture delay (ms)
Expand Down
40 changes: 11 additions & 29 deletions src/lib/stream-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import { EventEmitter } from 'events';
import * as stream from 'stream';
import * as si from 'systeminformation';
import { Flip, Rotation } from '..';
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
import { getSharedArgs } from './shared-args';

export enum Codec {
H264 = 'H264',
Expand All @@ -29,6 +30,13 @@ export interface StreamOptions {
fps?: number;
codec?: Codec;
sensorMode?: SensorMode;
shutter?: number;
iso?: number;
exposureCompensation?: number;
exposureMode?: ExposureMode;
awbMode?: AwbMode;
analogGain?: number;
digitalGain?: number;
}

declare interface StreamCamera {
Expand Down Expand Up @@ -79,35 +87,9 @@ class StreamCamera extends EventEmitter {
try {
const args: Array<string> = [
/**
* Width
* Add the command-line arguments that are common to both `raspivid` and `raspistill`
*/
...(this.options.width ? ['--width', this.options.width.toString()] : []),

/**
* Height
*/
...(this.options.height ? ['--height', this.options.height.toString()] : []),

/**
* Rotation
*/
...(this.options.rotation ? ['--rotation', this.options.rotation.toString()] : []),

/**
* Horizontal flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both)
? ['--hflip']
: []),

/**
* Vertical flip
*/
...(this.options.flip &&
(this.options.flip === Flip.Vertical || this.options.flip === Flip.Both)
? ['--vflip']
: []),
...getSharedArgs(this.options),

/**
* Bit rate
Expand Down