Is there any way to calculate the video duration in a millisecond from content-length?
request
.get("http://myvideourl.com/filename.mp4")
.on("response", response => {
const content_length = response.headers.content-length;// "content-length": "1986943971"
res.json({
stream_duration: "",
thumb: thumb,
size: content_length,
});
});
Note : Video Format is MP4 , res is express object, request is a httpclient library in NodeJS
You can use this npm module It will help you to get the video length even from an url
const { getVideoDurationInSeconds } = require('get-video-duration');
getVideoDurationInSeconds('http://myvideourl.com/filename.mp4').then((duration) => {
console.log(duration)
})
Of course you can then convert it into milliseconds. (x1000).