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

probe.js 945B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 = getProperty(probeData, "duration"),
  8. channels = getProperty(probeData, "channels");
  9. if (!duration || duration === "N/A" || !(duration > 0)) {
  10. return cb("Couldn't probe audio duration.");
  11. }
  12. if (typeof channels !== "number" || channels < 1 || channels > 2) {
  13. return cb("Couldn't detect mono/stereo channels");
  14. }
  15. return cb(null, {
  16. duration: duration,
  17. channels: channels
  18. });
  19. });
  20. };
  21. function getProperty(probeData, property) {
  22. if (probeData.format && probeData.format[property]) {
  23. return probeData.format[property];
  24. }
  25. if (Array.isArray(probeData.streams) && probeData.streams.length && probeData.streams[0][property]) {
  26. return probeData.streams[0][property];
  27. }
  28. return null;
  29. }