video-duration 📺 Get video duration from any URL and video object in Node.js and the browser without ffmpeg/ffprobe.
You can install the package using npm:
npm i @numairawan/video-duration
Usage in nodeJS
const { videoDuration } = require("@numairawan/video-duration");
// Using a video URL
const videoUrl = "https://example.com/sample.mp4";
videoDuration(videoUrl)
.then(duration => {
console.log(`Video duration: `, duration);
})
.catch(error => {
console.error(error);
});
// Using a local video file (Node.js)
const localVideoPath = "path/to/local/video.mp4";
videoDuration(localVideoPath)
.then(duration => {
console.log(`Video duration: `, duration);
})
.catch(error => {
console.error(error);
});
You can use the package in the browser by including it directly via a CDN. It's lightweight, only 1KB in size.
<script src="https://cdn.jsdelivr.net/npm/@numairawan/video-duration/dist/index.min.js"></script>
Usage in browser
// VideoDuration class
const videoDuration = new VideoDuration();
// Using a video URL
const videoUrl = "https://example.com/sample.mp4";
videoDuration.analyze(videoUrl)
.then(duration => {
console.log(`Video duration: `, duration);
})
.catch(error => {
console.error(error);
});
// Using a file object
// videoFileInput File input
const file = videoFileInput.files[0];
videoDuration.analyze(file)
.then(duration => {
console.log(`Video duration: `, duration);
})
.catch(error => {
console.error(error);
});
Contributions are welcome! Feel free to fork the repository and submit pull requests as well.
This project is licensed under the MIT license.
Feel free to reach out to me for any project-related queries or collaborations. I'm always happy to connect and discuss ideas!