# lambda-video

> Run FFMPEG on AWS Lambda.

Latest version **1.0.11** (published 2018-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install lambda-video
pnpm add lambda-video
yarn add lambda-video
bun add lambda-video
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2018-06-18 |
| First published | 2018-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 61.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | kamlesh.likhare |
| Maintainers | kammu1502 |

## Links

- npm: https://www.npmjs.com/package/lambda-video
- npm.io page: https://npm.io/package/lambda-video

## Recent versions

- 1.0.11 (latest) — 2018-06-18
- 1.0.10 — 2018-06-18
- 1.0.9 — 2018-06-18
- 1.0.8 — 2018-06-14
- 1.0.7 — 2018-06-14
- 1.0.6 — 2018-06-14
- 1.0.5 — 2018-06-14
- 1.0.4 — 2018-06-14
- 1.0.3 — 2018-06-14
- 1.0.2 — 2018-06-14
- 1.0.1 — 2018-06-14
- 1.0.0 — 2018-06-11

## README

# FFMPEG for AWS Lambda

Run FFMPEG on AWS Lambda.

## What

`lambda-video` is static binary of [ffmpeg](https://johnvansickle.com/ffmpeg/) utility, built for AWS Lambda. It supports all `ffmpeg` commands.

## Why

`lambda-video` allows you to manipulate video files using ffmpeg command in AWS Lambda.


## Inspiration
It is completely based on lambda-audio package, we have gone through the package made some minor changes & make it workable for Video manipulation
## How

### Installation

You can install this package from NPM by running following command:

```shell
npm install lambda-video --save
```

### Usage

After you require node module in your code by adding:

```javascript
const lambdaVideo = require('lambda-video')
```

See below for the examples.

#### ffmpeg command

Let's say that you want to extract audio from video & need sample rate 8000, with shell you will do like this:

```shell
ffmpeg -i video.mp4 -vn -ar 8000 -ac 2 -ab 192k -f mp3 audio.mp3
```

With `lambda-video` you can do that by passing the command as a string, just without `ffmpeg`	part, like this:

```javascript
lambdaVideo.ffmpeg('-i video.mp4 -vn -ar 8000 -ac 2 -ab 192k -f mp3 audio.mp3')
  .then(response => {
    // Do something when the file was converted
  })
  .catch(errorResponse => {
    console.log('Error from the ffmpeg command:', errorResponse)
  })
```

Or by passing the arguments as an array:

Keep in mind that AWS Lambda is read only and that the output path needs to be in /tmp folder.

### Deployment

same as`lambda-audio`, `lambda-video` is working perfectly with [Claudia.js](https://claudiajs.com) library.

With Claudia.js, simply save `lambda-video` as a dependency and then you can deploy your AWS Lambda function using standard `claudia create` command.

## example  : If any .mp4 upload on bucket, the lambda function should be called to extract audio from video

    var AWS = require('aws-sdk');
    var fs = require("fs");
    var mktemp = require("mktemp");
    const path = require('path');
    const lambdaVideo = require('lambda-video');

    exports.handler = function(event, context) {
      if(event.Records) {
        var bucketName = event.Records[0].s3.bucket.name;
        var fileName = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));

        var params = {
          Bucket: bucketName,
          Key: fileName
        };
      
        var s3 = new AWS.S3();
        s3.getObject(params, function(err, data) {
          var basename = path.parse(fileName).name,temp_file;
          temp_file = mktemp.createFileSync("/tmp/video.mp4");
          fs.writeFileSync(temp_file, data.Body);

          //Command to create 3 audio files of 10 sec with 8000hz
            var  command = '-i /tmp/video.mp4 -vn -ar 8000 -ac 2 -ab 192k -f mp3 /tmp/testaudio.mp3';
          lambdaVideo.ffmpeg(command)
            .then(response => {
              fs.readFile('/tmp/audio.mp3', function(err, data){
              s3.putObject({
                    Bucket: 'YOUR-OUTPUT-BUCKET',
                    Key: basename+'audio.mp3',
                    Body: data
                  }, function(err, data) {

                    if (err) {
                        console.log(err)
                    } else {
                      fs.unlinkSync('/tmp/video.mp4');
                      fs.unlinkSync('/tmp/testaudio.mp3');
                      console.log("Successfully uploaded data to myBucket/myKey");
                    }
                })
            })
            }).catch(errorResponse => {
              console.log('Error from the ffmpeg command:', errorResponse)
          })
        });
      }
    };
## <a>Show Your Support</a>
  We are new in this field & we are trying to build our own organisation.We willing to provide such solutions & packages to the world.Your contribution can help us to build new team & solutions. You can donate through paypal from link below 
  
  <a href="https://www.paypal.me/KamleshLikhare/" target="_blank" style="text-decoration:underline"> DONATE NOW </a>
  
  Thanks

## Notes
- You should increase Max Timeout in aws lambda (default is 3, you can make it 30, for large file you may increase further), otherwise it will give timeout error

## Thanks
https://www.npmjs.com/package/lambda-audio

## Keyword
  lambda-FFMPEG, FFMPEG, AWS Lambda video manipulation

## License

GNU GENERAL PUBLIC LICENSE, Version 2 -- see [LICENSE](LICENSE)

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