GithubHelp home page GithubHelp logo

caffco / get-audio-duration Goto Github PK

View Code? Open in Web Editor NEW
68.0 5.0 10.0 10.54 MB

Returns duration of an audio file via ffprobe

License: MIT License

TypeScript 96.51% Shell 3.49%
typescript audio ffprobe audio-duration javascript

get-audio-duration's Introduction

get-audio-duration

NPM version Build Status Maintainability Test Coverage License NPM bundle size (minified) Downloads

Get the duration of audio files with ffprobe.

Supported platforms

Currently this package only supports Linux, Windows 7+, and MacOS 10.9+. This package does not work in the browser, iOS or Android.

Install

$ npm install --save get-audio-duration

Usage

const { getAudioDurationInSeconds } = require('get-audio-duration')

getAudioDurationInSeconds('audio.flac').then((duration) => {
  console.log(duration)
})

// If you need to customize the path to ffprobe...

getAudioDurationInSeconds('audio.flac', '/path/to/ffprobe').then((duration) => {
  console.log(duration)
})

get-audio-duration's People

Contributors

dependabot[bot] avatar sasjafor avatar sumolari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

get-audio-duration's Issues

Get HH::MM:SS output

Hello

It would be really helpful if you could get the output with a HH:MM:SS format.

Since getAudioDurationInSeconds returns the seconds of a given file something like the following code example could be added to get the formatted output:

const duration = seconds => new Date(seconds * 1000).toISOString().split('T').pop().split('.').shift()

This way you can get something like this:

{
    "seconds": 29,
    "duration": "00:00:29"
}
{
    "seconds": 210.528812,
    "duration": "00:03:30"
}
{
    "seconds": 255.242449,
    "duration": "00:04:15"
}

Thank you.

Could not find ffprobe executable on AWS Lambda

I'm getting this error message on AWS lambda (node 14) running [email protected]:

  "errorMessage": "Could not find ffprobe executable, tried \"/var/task/node_modules/@ffprobe-installer/linux-x64/ffprobe\" and \"/var/task/node_modules/@ffprobe-installer/ffprobe/node_modules/@ffprobe-installer/linux-x64/ffprobe\"",

I'm not even to the point of calling the method and passing it a custom path to ffprobe - this error occurs when requiring the module:

const { getAudioDurationInSeconds } = require('get-audio-duration');

It's coming from @ffprobe-installer/ffprobe, and I guess my question is... when one plans on using a custom path to ffprobe, should @ffprobe-installer/ffprobe even be a factor?

ERROR Error: Could not find ffprobe executable, tried "/var/task/node_modules/@ffprobe-installer/linux-x64/ffprobe" and "/var/task/node_modules/@ffprobe-installer/ffprobe/node_modules/@ffprobe-installer/linux-x64/ffprobe"

ERROR Error: Could not find ffprobe executable, tried "/var/task/node_modules/@ffprobe-installer/linux-x64/ffprobe" and "/var/task/node_modules/@ffprobe-installer/ffprobe/node_modules/@ffprobe-installer/linux-x64/ffprobe"

help

code:

const duration = await getAudioDurationInSeconds(musicPath, ffprobe.path)

Streams fail: No duration found!

I just tried the example from README.md:

import getAudioDurationInSeconds from "get-audio-duration";
import fs from "fs";

const stream = fs.createReadStream('audio.ogg')
getAudioDurationInSeconds(stream).then((duration) => {
  console.log(duration)
})

and it returns an error:

/path/to/project/node_modules/get-audio-duration/dist/commonjs/index.js:33
            op = body.call(thisArg, _);
                      ^
Error: No duration found!
    at /path/to/project/node_modules/get-audio-duration/src/index.ts:57:9
    at step (/path/to/project/node_modules/get-audio-duration/dist/commonjs/index.js:33:23)
    at Object.next (/path/to/project/node_modules/get-audio-duration/dist/commonjs/index.js:14:53)
    at fulfilled (/path/to/project/node_modules/get-audio-duration/dist/commonjs/index.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

If I pass the same file as a parameter, it works great:

getAudioDurationInSeconds("audio.ogg").then((duration) => {
  console.log(duration)
})
// Output: 0.95102

(Unfortunately, I cannot be content with the files method as I don't have files.)

Similar issue: #113

Version information

I tried this with both my standard ffprobe installation, passing the path to it in the second parameter, and with the version that @ffprobe-installer/ffprobe fetches - no difference.

My ffprobe: ffprobe version 4.4.2-0ubuntu0.22.04.1
@ffprobe-installer/ffprobe: ffprobe version N-58069-gc253b180cb-static https://johnvansickle.com/ffmpeg/

remote audio file

We use Google Cloud Storage and it would be nice if it was possible to fetch the audio duration of the file from there?

MP3 support?

I have no idea if this module has some MP3 support but I just got an error:

No duration found!

On the browser side the audio length for the same file is reported correctly from a "new Audio()" object.

No duration found when utilizing s3 readStream

I am able to pull my s3 audio files down and then find the audio duration using local path. I wanted to use a readStream instead, to avoid the local writing. When using the stream I get a no duration found error, even though the same file previously had a duration if I write it locally.

Should I be able to use an s3 readStream?
If so, will it look something like getAudioDurationInSeconds(s3.getObject().createReadStream()) ?

Update: I get the same error when utilizing fs.createReadStream(localPath).

issue on server

Error: Command failed with exit code 1: /app/node_modules/.pnpm/@[email protected]/node_modules/@ffprobe-installer/linux-x64/ffprobe -v error -select_streams a:0 -show_format -show_streams https://cdn.test.kr/music/Til Until.mp3

it works well locally but when i build it in docker (server) it crashes with that error what can i do?

[Error] Version 4.0.0 is not working with nodejs stream

OS: Ubuntu 20
Node: 18.16.0

I tried const duration = await getAudioDurationInSeconds(fileStream) and got the error

Command failed with exit code 1:
/home/jonarc/projects/tutorials/music-server/node_modules/@ffprobe-installer/linux-x64/ffprobe
-v error -select_streams a:0 -show_format 
-show_streams [object Object]\n[object Object]: No such file or directory"

latest version v3.1.1 but npm has v3.1.0 already

could you please update it to the latest version v3.1.1 into npm also? its v3.1.0 already.

https://www.npmjs.com/package/get-audio-duration

to fix the following issue at v3.1.0 please update the package at npmjs.com to v3.1.1.

Could not find ffprobe executable, tried \"/var/task/src/events/linux-x64/ffprobe\" and \"/var/task/src/lambda/node_modules/@ffprobe-installer/linux-x64/ffprobe\"","stack":["Error: Could not find ffprobe executable, tried \"/var/task/src/events/linux-x64/ffprobe\" and \"/var/task/src/lambda/node_modules/@ffprobe-installer/linux-x64/ffprobe\""," at node_modules/@ffprobe-installer/ffprobe/index.js

Not working with react-native !

I installed it in my react-native project but it is throwing multiple errors.
Did anyone use it with react-native and react-native-fs?

React-native-0.72.3

Could not find ffprobe executable

I had no problems before, but recently I get this error, dropping my application on OSX:

/Users/neverlandbudapest/test/node_modules/node-ffprobe-installer/index.js:43
	throw new Error('Could not find ffprobe executable, tried "' + npm3Binary + '" and "' + npm2Binary + '"');
	      ^

Error: Could not find ffprobe executable, tried "/usr/local/node_modules/@ffprobe-installer/darwin-x64/ffprobe" and "/usr/local/bin/node_modules/@ffprobe-installer/darwin-x64/ffprobe"
    at Object.<anonymous> (/Users/neverlandbudapest/test/node_modules/node-ffprobe-installer/index.js:43:8)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/neverlandbudapest/test/node_modules/get-audio-duration/dist/commonjs/index.js:45:15)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

The executable is there, in the /Users/neverlandbudapest/test/node_modules/@ffprobe-installer/darwin-x64 folder.

.. could this be fixed?

Streaming method does not work with wav files

const { getAudioDurationInSeconds } = require('get-audio-duration')
const fs = require('fs')

filepath = './scratch_file/assets_audios_10000.wav'

path_method();
stream_method();

function stream_method() {
    console.log("GET AUDIO BY STREAM");
    stream = fs.createReadStream(filepath);
    // duration = getAudioDurationInSeconds(stream)
    getAudioDurationInSeconds(stream).then((duration) => {
        console.log(duration);
    });
}

function path_method() {
    console.log("GET AUDIO FILE BY PATH");
    // duration = getAudioDurationInSeconds(filepath)
    getAudioDurationInSeconds(filepath).then((duration) => {
        console.log(duration);
    });
}

The sample code is above, put an audio file to some path,
method using path returned duration successfully,
but the method using stream tells (node:74393) UnhandledPromiseRejectionWarning: Error: No duration found!

Error: Could not find ffprobe executable after Convert .exe using pkg

Error: Could not find ffprobe executable, tried "C:\snapshot\node audio player\node_modules@ffprobe-installer\win32-x64\ffprobe.exe" and "C:\snapshot\node audio player\node_modules@ffprobe-installer\ffprobe\node_modules@ffprobe-installer\win32-x64\ffprobe.exe"
at Object. (C:\snapshot\node audio player\node_modules@ffprobe-installer\ffprobe\index.js:39:8)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:834:12)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (C:\snapshot\node audio player\server.js)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)

Node.js v18.5.0

Doesn't work inside a binary made with pkg

I use pkg to make binaries for my code, when running directly from the code runs without any problem but inside a the binaries I get the folllowing for every file I try to use get-audio-duration:
(node:26060) UnhandledPromiseRejectionWarning: Error: Command failed with ENOENT: C:\snapshot\LocalMediaTwitchBot\node_modules\ffprobe-static\bin\win32\x64\ffprobe.exe -v error -select_streams a:0 -show_format -show_streams D:\ARCHIVOS\VIDEOS\MUSICA\ClariS\[ADF] ClariS - Hitorigoto (1280x720 x264 Hi10p AAC) (Sub español - Spanish sub).mkv spawn C:\snapshot\LocalMediaTwitchBot\node_modules\ffprobe-static\bin\win32\x64\ffprobe.exe ENOENT The system cannot find the path specified. at notFoundError (C:\snapshot\LocalMediaTwitchBot\node_modules\cross-spawn\lib\enoent.js:6:26) at verifyENOENT (C:\snapshot\LocalMediaTwitchBot\node_modules\cross-spawn\lib\enoent.js:40:16) at ChildProcess.emit (C:\snapshot\LocalMediaTwitchBot\node_modules\cross-spawn\lib\enoent.js:27:25) at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12) (Use localmediatwitchbot-win --trace-warnings ... to show where the warning was created)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.