7

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
2
  • What does your nodejs code look like ? Commented 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/,//')} Commented Jan 12, 2018 at 19:12

2 Answers 2

21

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
Sign up to request clarification or add additional context in comments.

Comments

1
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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.