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

get-media-dimensions

Package Overview
Dependencies
Maintainers
8
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-media-dimensions - npm Package Compare versions

Comparing version 2.0.0-ffprobe.0 to 2.0.0-ffprobe.1

src/ffprobe-path.js

6

package.json
{
"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');

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