Skip to content

Commit

Permalink
Merge feat_live_view
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Aug 29, 2018
2 parents 9f3b8c9 + 2efa1cb commit 89f3a5d
Show file tree
Hide file tree
Showing 20 changed files with 430 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ test/spec/*.js.map

/.nyc_output/
/test/integration/app/spec/swagger.json
/examples/*.jpeg
/examples/*.jpeg
.tmp
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ If you have any questions, create an [issue](https://github.com/Romakita/tsed/bl
Clone your fork of the repository

```bash
$ git clone https://github.com/YOUR_USERNAME/ts-express-decorators.git
$ git clone https://github.com/YOUR_USERNAME/ts-gphoto2-driver.git
```

Or if you have access to this repository:

```bash
$ git checkout https://github.com/TypedProject/ts-gphoto2-driver.git
```

Install npm dependencies

```bash
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ A Node.js wrapper for libgphoto2 written in TypeScript. Useful for remote contro

- Camera autodetection,
- Take a picture/movie capture,
- Take a preview (not a live preview mode),
- Take a preview,
- Retrieve camera list,
- Select camera,
- Take a liveview from camera and get binary or base64 of each frame, or write it to file,
- Display info about your camera (summary, about, manual).

## Prerequisite
Expand Down Expand Up @@ -70,6 +71,24 @@ if (cameraList.size) {
cameraList.close();
```

## CameraFile

A lot of different API's of this library returns a CameraFile object.

This object does not contain the image, it is just a pointer to the file in camera's RAM.

You have several options to get your image:

1) Use `.save(filename)` of `.saveAsync(filename)` methods, that will save the image to your filesystem.
2) Use `.getDataAndSizeAsync('binary' | 'base64')` method, which returns following object:

```typescript
{
data: data, // Buffer for binary format and string for base64.
size: size
}
```

## Examples

Some example are available in the examples directory, when you have cloned or downloaded the complete project from github.
Expand Down
28 changes: 28 additions & 0 deletions examples/camera-liveview-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This example illustrates the usecase, where you need to capture liveview from the camera
// and then save it to .mjpg file. The file will be updated in live mode.

const { Camera } = require('../src');
// If you launch this example not from library folder, change the previous two lines to:
// const { Camera } = require('@typedproject/gphoto2-driver');
const path = require('path');
const camera = new Camera();

const NUMBER_OF_SECONDS_TO_WRITE = 10;
const PATH_TO_SAVE = path.join(__dirname, '../.tmp/live.mjpg'); // Make sure that this folder exists

camera.initialize();

const liveview = camera.liveview({
output: "file",
fps: 24, // Number of frames per second. Default is 24.
filePath: PATH_TO_SAVE,
});

liveview.start();

setTimeout(() => {

liveview.stop();

camera.closeQuietly();
}, NUMBER_OF_SECONDS_TO_WRITE * 1000);
50 changes: 50 additions & 0 deletions examples/camera-liveview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This example illustrates the usecase, where you need to capture liveview from the camera
// and get live output of each frame as binary (Buffer) or base64

// To check if liveview works with your camera, you can just use
// node examples/camera-liveview.js | xxd | grep ffd9
// if you see a lot of ffd9 (not in the first column) - then it works

const { Camera } = require('../src');
// If you launch this example not from library folder, change the previous two lines to:
// const { Camera } = require('@typedproject/gphoto2-driver');
const camera = new Camera();

const NUMBER_OF_SECONDS_TO_LISTEN = 10;
const NUMBER_OF_SECONDS_TO_WAIT = 10;
const OUTPUT = "binary";
// change these lines to see base64 output
// const OUTPUT = "base64";

camera.initialize();

const liveview = camera.liveview({
output: OUTPUT,
fps: 24, // Number of frames per second. Default is 24.
});

liveview.on("data", (data, size) => {
process.stdout.write(data); // We can not use console.log for binary, becayse it puts \n after each line
});

liveview.start();

setTimeout(() => {

liveview.stop();

}, NUMBER_OF_SECONDS_TO_LISTEN * 1000);

setTimeout(() => {
// Here we wait for NUMBER_OF_SECONDS_TO_WAIT + NUMBER_OF_SECONDS_TO_LISTEN and then
// launch liveview one more time
// The output should be caught by original liveview.on("data") event handler
liveview.start();

setTimeout(() => {

liveview.stop();

camera.closeQuietly(); // Do not forget to close camera
}, NUMBER_OF_SECONDS_TO_LISTEN * 1000);
}, (NUMBER_OF_SECONDS_TO_WAIT + NUMBER_OF_SECONDS_TO_LISTEN) * 1000)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"prettier": "prettier '{src,test}/**/*.ts' --write"
},
"dependencies": {
"ffi-napi": "2.4.3",
"ffi-napi": "^2.4.3",
"ref": "^1.3.3",
"ref-array": "^1.2.0",
"ref-struct": "^1.1.0",
Expand Down Expand Up @@ -74,4 +74,4 @@
"release": {
"branch": "production"
}
}
}
2 changes: 1 addition & 1 deletion src/components/AbilitiesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {PortInfoList} from "./PortInfoList";

export class AbilitiesList extends PointerWrapper<PointerAbilitiesList> {
constructor() {
super("gp_abilities_list", RefAbilitiesList);
super({method: "gp_abilities_list", refType: RefAbilitiesList});
}

get size(): number {
Expand Down
Loading

0 comments on commit 89f3a5d

Please sign in to comment.