ArtskydJ / node-sox-stream

:mega: A stream-friendly wrapper around SoX
53 stars 14 forks source link

Problem with MP3 files in OSX #15

Open prajankya opened 5 years ago

prajankya commented 5 years ago

I tried to give input file as MP3, which gives a odd error as

sox FAIL formats: can't determine type of file

After debuging and also checking through the issues noted at #14, I found out that sox will understand MIME type from extensions for MP3 file only.

when I try to do

soxi ./test.mp3

I get a valid response, but when I do

soxi ./test

(obviously I renamed the file to without an extension)

thats the same error I get, i.e.

sox FAIL formats: can't determine type of file

I have tested it with various mp3 files, even files from online sources as sample mp3 for sound testing. Tested many other formats as well, but the problem seems to come only for MP3, which leads

Now the problem after looking at the source code is, as all is done through streams, it is very hard to get extension unless the input is from fs.createWriteStream or fs.createReadStream as noted in here(stackoverflow).

For my use case, I have solved it by adding an extension to the the function call for createTempFile() as static, but Please look into this, as it is a undocumented bug.

ArtskydJ commented 5 years ago

The issue is that if you pipe in a stream, sox-steam and sox both will not know what type of file is being piped.

soxi ./test.mp3 # works; sox looks at the file ext
soxi ./test     # does not work

cat ./test.mp3 | soxi - # my guess is that this will not work
cat ./test | soxi       # my guess is that this will not work either

cat ./test.mp3 | soxi - --type=mp3 # my guess is that this will work
cat ./test | soxi - --type=mp3     # my guess is that this will also work

If my guesses are correct, then this is an issue with sox not detecting file types.

prajankya commented 5 years ago

Hey, thanx, I totally overlooked the documentation and forgot I could give ext in input.

Currently using like this,

sox({
    input: {
      type: fileName.split(".").pop()
    },
    output: {
    // Other things
    }
})

So this library is working perfectly fine, only catch is if the user want to give MP3 then he has to give type in input or for generic use case something similar to my code as shown above. Please correct me if I am wrong.

I think we can close this issue.

Also I would suggest that you should document it in README about the same(MP3 support with input.type doesn't work)

Thanks. Have a great day.

ithustle commented 5 years ago

Install libsox