Turn audio into a shareable video. forked from nypublicradio/audiogram

duration.js 678B

123456789101112131415161718192021222324252627282930313233343536
  1. var probe = require("node-ffprobe");
  2. module.exports = function(filename, cb){
  3. probe(filename, function(err, probeData) {
  4. if (err) {
  5. return cb(err);
  6. }
  7. var duration = getDuration(probeData);
  8. if (!duration || duration === "N/A" || !(duration > 0)) {
  9. return cb("Couldn't probe audio duration.");
  10. }
  11. return cb(null, duration);
  12. });
  13. };
  14. function getDuration(probeData) {
  15. if (probeData.format && probeData.format.duration) {
  16. return probeData.format.duration;
  17. }
  18. if (Array.isArray(probeData.streams) && probeData.streams.length && probeData.streams[0].duration) {
  19. return probeData.streams[0].duration;
  20. }
  21. return null;
  22. }