# libqrv

> Library For QR Encoding Information in an Video Stream

Latest version **0.1.0** (published 2019-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install libqrv
pnpm add libqrv
yarn add libqrv
bun add libqrv
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-11-12 |
| First published | 2019-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 (+4 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Robert Keizer |
| Maintainers | robertkeizer |

## Links

- npm: https://www.npmjs.com/package/libqrv
- Repository: https://github.com/robertkeizer/libqrv
- Homepage: https://github.com/robertkeizer/libqrv#readme
- Issues: https://github.com/robertkeizer/libqrv/issues
- npm.io page: https://npm.io/package/libqrv

## Dependencies (6)

- [joi](https://npm.io/package/joi.md) ^14.3.1
- [tmp](https://npm.io/package/tmp.md) ^0.1.0
- [uuid](https://npm.io/package/uuid.md) ^3.3.3
- [async](https://npm.io/package/async.md) ^3.1.0
- [qrcode](https://npm.io/package/qrcode.md) ^1.4.4
- [fluent-ffmpeg](https://npm.io/package/fluent-ffmpeg.md) ^2.1.2

## Recent versions

- 0.1.0 (latest) — 2019-11-12

## README

## libqrv

`libqrv` is a node module that is used to encode data into video streams. Specifically it does this by transforming data into QR codes, and stitching the multiple frames together into a single video file.

**Example**

By running the [yarn.lock](https://github.com/robertkeizer/libqrv/blob/master/examples/yarn.lock) file in the examples directory through `convertFile`, the video below is produced.

[![yarn.lock example qr code video](examples/yarn.lock-libqrv.png)](https://www.youtube.com/watch?v=la1eIuuQZ7M)

## Installation

```
$ yarn install libqrv
```

## Basic Usage

### convertFile
`convertFile( existingFile [, newFilePath] , cb )`

Converts a file into a mp4 video stream of QR codes that contain the `base64` encoded data. If `newFilePath` is not specified `.mp4` is added to the file path passed in.

```js
const { convertFile } = require( "libqrv" );

convertFile( "./some/file.txt", "./another/location/output.mp4", ( err ) => {

	// err is null unless there is an error
	if( err ){
		return console.log( "Couldn't convert the file.. " + err );
	}

	// "./another/location/output.mp4" exists
} );
```

```js
const { convertFile } = require( "libqrv" );

convertFile( "./some/file.txt", ( err ) => {

	if( err ){
		return console.log( "Couldn't convert the file.. " + err );
	}

	// if err is not null, and no newFIlePath has been specified
	// existingFile + ".mp4" is assumed.

	// "./some/file.txt.mp4" exists
	
} );
```


## Directly Using the Library

The LibQRV library itself provides some customization. There are a lot of opportunities that exist to expose more configuration, and functionality.

**Usage**
```js
const { LibQRV } = require( "libqrv" );

const config = {
	debug: true
};

new LibQRV( config, ( err, libqrv ) => {

	// libqrv can be used here

	libqrv.on( "readableStreamComplete", ( details ) => {
		/*
		details = {
			filename: "yarn.lock",
			outputPath: "/var/folders/qr/z123...../T/tmp-..../yarn.lock.mp4"
		}
		*/


		// Let's ensure that we clean up any resources
		libqrv.destroy( ( err ) => {
			if( err ){
				console.log( "Couldn't clean up resources: " + err );
				return;
			}
			console.log( "Cleaned up resources. Goodbye." );
		} );
	} );

	libqrv.queueReadableStream( fs.createReadStream( "./yarn.lock" ), ( err ) => {
		if( err ){
			console.log( "Couldn't queue readable stream: " + err );
			return;
		}

		// Readable stream has been queued.

		// When complete "readableStreamComplete" will be emitted.
	} );
} );
```

**Default Options**
```
{
  "debug": false,
  "outputDirectory": "/tmp/tmp-34.........", // geneated by tmp
  "qr": {
    "width": 240,
    "scale": 1,
    "margin": 0,
    "errorCorrectionLevel": "low"
  },
  "video": {
    "output": {
      "framerate": 25
    },
    "input": {
      "framerate": 1
    }
  }
}
```

**Options to constructor**

| Option Name | Default Value | Description |
| ------------------ | ------------- | ----------- |
| `outputDirectory` | Dynamically Generated ( uses `tmp` ) | The directory where the output `.mp4` will be placed. |
| `debug` | `false` | Whether or not to emit `debug` events |
| `qr` | See QR Options | Configuration that relates to QR Code generation |
| `video` | See Video Options | Configuration that relates to the video generation |

**QR Options**

| Option Name | Default Value | Description |
| ------------------ | ------------- | ----------- |
| `width` | `240` | The width of the QR code frame that is generated |
| `scale` | `1` | The number of pixels that are used per "block" to make up the QR code |
| `margin` | `0` | The amount of blank space that is kept around the QR code. Synonymous with HTML `padding` |
| `errorCorrectionLevel` | `"low"` | How much error correction is used in the QR code. |

**Video Options**

| Option Name | Default Value | Description |
| ------------------ | ------------- | ----------- |
| `input.framerate` | `1` | The framerate relating to the QR code images. Per second |
| `output.framerate` | `25` | The output `.mp4` video framerate. Per second |


**Constructor**
LibQRV uses a configuration object that is passed into the constructor. Additionally, the constructor takes a callback that is called with `cb( err, instance )` where `err` should be `null`, and `instance` is the newly created instance of `LibQRV`. 

## Help Wanted

If you find this module or repository useful, please consider making a pull request to it.

### Running tests
```
$ yarn run test

yarn run v1.3.2
$ ./node_modules/mocha/bin/mocha -t 60000


  Base
    ✓ LibQRV is a function
    Validations
      ✓ Fails if an invalid config is passed in
    Basic operation
      ✓ Constructor returns sane object in callback
      ✓ Emits a 'readableStreamComplete' event when finished encoding a readable stream. (8492ms)
    convertFile operation
      ✓ Works when we specify a filename (10250ms)
      ✓ Works when we don't specify a filename (8534ms)


  6 passing (27s)

✨  Done in 28.27s.
```

## License
MIT

---
_Source: https://npm.io/package/libqrv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
