Skip to content

Latest commit

 

History

History
96 lines (74 loc) · 2.79 KB

README.md

File metadata and controls

96 lines (74 loc) · 2.79 KB

video-duration

Total Hits Downloads Version License


video-duration 📺 Get video duration from any URL and video object in Node.js and the browser without ffmpeg/ffprobe.

📦 Installation

Node.js

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);
  });

Browser

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);
  });

Contributing

Contributions are welcome! Feel free to fork the repository and submit pull requests as well.

License

This project is licensed under the MIT license.

Connect with Me

Feel free to reach out to me for any project-related queries or collaborations. I'm always happy to connect and discuss ideas!