get-video-duration
Version:
Get the duration of a video file
72 lines (51 loc) • 2.38 kB
Markdown
[![NPM version][npm-image]][npm-url]

[](https://codeclimate.com/github/caffco/get-video-duration/maintainability)
[](https://codecov.io/gh/caffco/get-video-duration)
[![License][license-image]][license-url]
[![NPM bundle size (minified)][bundle-size-image]][npm-url]
[![Downloads][downloads-image]][downloads-url]
Get the duration of video files/streams with `ffprobe`.
# Supported platforms
Currently this package only supports Linux, Windows 7+, and MacOS 10.9+. **This package does not work in the browser**, iOS or Android.
# Install
```bash
$ npm install --save get-video-duration
```
# Usage
```js
const { getVideoDurationInSeconds } = require('get-video-duration')
// From a local path...
getVideoDurationInSeconds('video.mov').then((duration) => {
console.log(duration)
})
// From a URL...
getVideoDurationInSeconds(
'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
).then((duration) => {
console.log(duration)
})
// From a readable stream...
const fs = require('fs')
const stream = fs.createReadStream('video.mov')
getVideoDurationInSeconds(stream).then((duration) => {
console.log(duration)
})
// If you need to customize the path to ffprobe...
getVideoDurationInSeconds('video.mov', '/path/to/ffprobe').then((duration) => {
console.log(duration)
})
```
This is a limitation of the underlying ffprobe binary, which has glibc statically linked and that prevents DNS resolution. Install `nscd` package through your package manager to solve this issue.
MIT. Based on [get-video-dimensions](https://github.com/mgmtio/get-video-dimensions).
[]: https://img.shields.io/npm/v/get-video-duration.svg
[]: https://npmjs.org/package/get-video-duration
[]: https://img.shields.io/bundlephobia/min/get-video-duration.svg
[]: http://img.shields.io/npm/l/get-video-duration.svg
[]: LICENSE
[]: http://img.shields.io/npm/dm/get-video-duration.svg
[]: https://npmjs.org/package/get-video-duration