Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bpp

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bpp - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

48

index.js

@@ -9,7 +9,34 @@ /*jshint node:true */

/**
* Module dependencies.
*/
const ffmpeg = require("fluent-ffmpeg");
ffmpeg.setFfprobePath(process.env.FFPROBE || '/usr/bin/ffprobe');
ffmpeg.setFfmpegPath(process.env.FFMPEG || '/usr/bin/ffmpeg');
const fs = require('fs');
/**
* Helper function to wrap a synchronous call to
* the 'which' module that returns `null' when an
* error is throw, otherwise the resulting path.
*
* @param {String} path
* @return {String|null}
*/
const which = (path) => {
try { return require('which').sync(path); }
catch(err) { return null; }
};
/**
* Set ffprobe and ffmpeg paths are resolved from environment
* variables or found in path. The ffprobe and ffmpeg command
* paths default to `/usr/bin/ffprobe' and `/usr/bin/ffmpeg'
* respectively if not resolved.
*/
ffmpeg.setFfprobePath(process.env.FFPROBE || which('ffprobe') || '/usr/bin/ffprobe');
ffmpeg.setFfmpegPath(process.env.FFMPEG || which('ffmpeg') || '/usr/bin/ffmpeg');
/**
* Calculates the bpp, or bits-per-pixel for a video at a given file path.

@@ -20,3 +47,3 @@ * The calculate() function calls the given callback() function with the

* results.
*
*
* @param {String} filePath - The file path for a video to calculate the bpp

@@ -27,7 +54,12 @@ * @param {Function} [callback] - The callback function called with results

*/
exports.calculate = (videoFile, cb) => new Promise((resolve, reject) => {
// propagate `ENOENT' errors to done function
try { fs.statSync(videoFile); }
catch (err) { return done(err); }
// propagate ffprobe errors to done function
try { ffmpeg.ffprobe(videoFile, onprobe); }
catch (err) { return cb(err); }
catch (err) { return done(err); }
// handle a given callback and promise resolution

@@ -39,7 +71,7 @@ function done(err, results) {

}
if (err) { reject(err); }
else { resolve(results); }
}
// handle ffprobe errors or results

@@ -46,0 +78,0 @@ function onprobe(err, metadata) {

11

package.json
{
"name": "bpp",
"version": "1.0.1",
"version": "1.0.2",
"description": "Calculate a video stream's {bits / (pixel * frame)} measurement.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test"
},

@@ -12,5 +12,8 @@ "author": "Andrew Grathwohl",

"dependencies": {
"fluent-ffmpeg": "^2.1.0"
"fluent-ffmpeg": "^2.1.0",
"which": "^1.2.10"
},
"devDependencies": {},
"devDependencies": {
"tape": "^4.6.0"
},
"repository": {

@@ -17,0 +20,0 @@ "type": "git",

@@ -1,13 +0,53 @@

/* jshint node:true */
/* jshint esversion:6 */
'use strict';
const b = require("../");
const assert = require('assert');
const path = require('path');
const test = require('tape');
const bpp = require('../');
const a = b.calculate('./test.mp4', function(err, c) {
setTimeout(function () {
console.log("Actual: " + c);
}, 1000);
const VALID_FILE_PATH = path.resolve(__dirname, './test.mp4');
const INVALID_FILE_PATH = VALID_FILE_PATH + 'foo';
test('Invalid file (callback)', (t) => {
t.plan(1)
bpp.calculate(INVALID_FILE_PATH, (err, results) => {
assert(err);
t.pass(err.message || err);
});
});
console.log("Expected: ~0.013");
test('Invalid file (Promise)', (t) => {
t.plan(1);
bpp.calculate(INVALID_FILE_PATH)
.then(() => t.fail())
.catch((err) => {
assert(err);
t.pass(err.message || err);
});
});
test('Valid file (callback)', (t) => {
t.plan(1)
bpp.calculate(VALID_FILE_PATH, (err, results) => {
assert(null == err);
assert(results)
t.pass();
});
});
test('Valid file (Promise)', (t) => {
t.plan(1);
bpp.calculate(VALID_FILE_PATH)
.then((results) => {
assert(results)
t.pass('.then(results)')
})
.catch((err) => {
assert(err);
t.fail(err.message || err);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc