Ok I know how to get the duration of a video in ffmpeg using this command
ffmpeg -i ./output/sample.mp4 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//
I run this command through a function in node but this outputs the duration onto the console, how do I get it onto node.js where I need it?
asked Jan 12, 2018 at 3:09
Ricky
7873 gold badges10 silver badges24 bronze badges
-
What does your nodejs code look like ?TGrif– TGrif2018年01月12日 14:42:50 +00:00Commented Jan 12, 2018 at 14:42
-
I have a package that runs console commands for me. It looks like this let getDuration = () => { cmd.run('ffmpeg -i ./output/trying.mp4 2>&1 | grep Duration | cut -d \' \' -f 4 | sed s/,//')}Ricky– Ricky2018年01月12日 19:12:30 +00:00Commented Jan 12, 2018 at 19:12
2 Answers 2
There is a way to read console output stream, but I would prefer to use fluent-ffmpeg: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg
It is a npm module for nodejs.
From here you can call ffprobe (a tool shipped with ffmpeg and better than ffmpeg to get informations about a video), like this:
var ffmpeg = require('fluent-ffmpeg');
ffmpeg.ffprobe('./input.mp4', function(err, metadata) {
//console.dir(metadata); // all metadata
console.log(metadata.format.duration);
});
answered Jan 27, 2018 at 8:28
Business Tomcat
1,06110 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
var ffmpeg = require('ffmpeg');
app.get('/getVideoDuration', (req, res) => {
fs.unlink('public/output.mp4')
try {
new ffmpeg('public/input.mov', function (err, video) {
if (!err) {
console.log(video.metadata.duration.seconds, "video")
res.send({
'msg': "Success",
'duration': video.metadata.duration.seconds
})
}
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
})
answered Nov 28, 2019 at 9:43
Shashwat Gupta
5,31845 silver badges33 bronze badges
Comments
lang-js