get-media-dimensions
Advanced tools
Comparing version 2.0.0-ffprobe.0 to 2.0.0-ffprobe.1
{ | ||
"name": "get-media-dimensions", | ||
"version": "2.0.0-ffprobe.0", | ||
"version": "2.0.0-ffprobe.1", | ||
"description": "get video, image or audio dimensions", | ||
@@ -24,3 +24,2 @@ "main": "src/index.js", | ||
"got": "^11.1.4", | ||
"ow": "^0.18.0", | ||
"sharp": "^0.25.3" | ||
@@ -55,3 +54,6 @@ }, | ||
] | ||
}, | ||
"optionalDependencies": { | ||
"ffprobe-static": "^3.0.0" | ||
} | ||
} |
@@ -19,8 +19,6 @@ # get-media-dimensions | ||
| Parameter | Type | Description | | ||
| :-------------------- | :----- | :------------------------------------------------ | | ||
| `urlOrFilename` | string | either a remote url or a local filename. | | ||
| `type` | string | the type of media (`audio`, `image`, or `video`). | | ||
| `options` | object | options | | ||
| `options.ffprobePath` | string | location of ffprobe binary (for audio and video) | | ||
| Parameter | Type | Description | | ||
| :-------------- | :----- | :------------------------------------------------ | | ||
| `urlOrFilename` | string | either a remote url or a local filename. | | ||
| `type` | string | the type of media (`audio`, `image`, or `video`). | | ||
@@ -32,8 +30,7 @@ #### Examples | ||
> ```js | ||
> ffprobePath = '/path/to/ffprobe'; | ||
> const getMediaDimensions = require('get-media-dimensions'); | ||
> | ||
> // get video dimensions = { width, height, duration } | ||
> const dimensions = await getMediaDimensions('./video.mp4', { ffprobePath }); | ||
> const dimensions = await getMediaDimensions('https://somewhere.com/video.mp4', { ffprobePath }); | ||
> const dimensions = await getMediaDimensions('./video.mp4'); | ||
> const dimensions = await getMediaDimensions('https://somewhere.com/video.mp4'); | ||
> ``` | ||
@@ -53,4 +50,4 @@ | ||
> // get audio dimensions = { duration } | ||
> const dimensions = await getMediaDimensions('./audio.mp3', 'audio', { ffprobePath }); | ||
> const dimensions = await getMediaDimensions('https://somewhere.com/audio.mp3', 'audio', { ffprobePath }); | ||
> const dimensions = await getMediaDimensions('./audio.mp3', 'audio'); | ||
> const dimensions = await getMediaDimensions('https://somewhere.com/audio.mp3', 'audio'); | ||
> ``` | ||
@@ -57,0 +54,0 @@ |
const ffprobe = require('ffprobe-client'); | ||
const ffprobePath = require('./ffprobe-path'); | ||
@@ -9,4 +10,4 @@ /** | ||
*/ | ||
async function getAudioDimensions (urlOrFilename, options) { | ||
const metadata = await ffprobe(urlOrFilename, { path: options.ffprobePath }); | ||
async function getAudioDimensions (urlOrFilename) { | ||
const metadata = await ffprobe(urlOrFilename, { path: ffprobePath }); | ||
const stream = metadata.streams.find(s => s.codec_type === 'audio'); | ||
@@ -13,0 +14,0 @@ if (!stream) throw new Error('audio stream not found'); |
const getAudioDimensions = require('./audio'); | ||
const getImageDimensions = require('./image'); | ||
const getVideoDimensions = require('./video'); | ||
const ow = require('ow'); | ||
@@ -42,16 +41,9 @@ const functions = { | ||
* @param {string} type the type of media (`audio`, `image`, or `video`). | ||
* @param {object} options | ||
* @param {string} options.ffprobePath Path to ffprobe. | ||
* @return {object} | ||
*/ | ||
async function getMediaDimensions (urlOrFilename, type, options = {}) { | ||
if (['audio', 'video'].includes(type)) { | ||
ow(options, ow.object.partialShape({ | ||
ffprobePath: ow.string.nonEmpty | ||
})); | ||
} | ||
async function getMediaDimensions (urlOrFilename, type) { | ||
if (!functions[type]) throw new Error(`unknown type ${type}`); | ||
return functions[type](urlOrFilename, options); | ||
return functions[type](urlOrFilename); | ||
} | ||
module.exports = getMediaDimensions; |
const ffprobe = require('ffprobe-client'); | ||
const ffprobePath = require('./ffprobe-path'); | ||
@@ -21,4 +22,4 @@ /** | ||
*/ | ||
async function getVideoDimensions (urlOrFilename, options) { | ||
const metadata = await ffprobe(urlOrFilename, { path: options.ffprobePath }); | ||
async function getVideoDimensions (urlOrFilename) { | ||
const metadata = await ffprobe(urlOrFilename, { path: ffprobePath }); | ||
const stream = metadata.streams.find(s => s.codec_type === 'video'); | ||
@@ -25,0 +26,0 @@ if (!stream) throw new Error('video stream not found'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8
0
10210
84
+ Addedffprobe-static@3.1.0(transitive)
- Removedow@^0.18.0
- Removedow@0.18.0(transitive)
- Removedtype-fest@0.17.0(transitive)