Giter Site home page Giter Site logo

Comments (26)

zhushenwudi avatar zhushenwudi commented on June 8, 2024 2

It has been tested on the windows platform, and there is no conversion problem. However, there is still an interrupt problem at present. It may be my code problem. I will try another way to write it later

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024 2

i love you boy! I'm crazy for you~

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

By the way, both MAC and Windows convert the same file directory structure

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024
const decoder = new FileDecoder({
          file: musicPath,
      })
      decoder.once('data', (chunk) => {
          const encoder = new wav.Writer({
              channels: decoder.getChannels(),
              bitDepth: decoder.getBitsPerSample(),
              sampleRate: decoder.getSampleRate(),
          })

          encoder.write(chunk)

          decoder
              .pipe(encoder)
              .pipe(fs.createWriteStream(musicPath.replace(".flac", ".wav")))
              .on('error', (e) => {
                  return reject(e.message)
              })
      })

      decoder.on('end', () => {
          return resolve(path.parse(musicPath).name)
      })

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

I think I know what the problem is. Files can be accessed in the main process through Node, but not in the UI process

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

Hi, sorry for late response.

The FileDecoder and FileEncoder classes uses C APIs to read and write files. Maybe in Windows, those APIs are not available (or they do not work as expected) on the UI process of Electron.

A bit surprised to see that you managed to get the UI process to load the package. Some time ago I wanted to use my library in an experiment with Electron and I had to write all code in the node process. Nevertheless, happy to see at least it is working somehow in Electron.

Back to the issue, I would suggest to use const inputStream = fs.createReadStream(musicPath) and pipe it to a StreamDecoder. If you can read files using node APIs on Windows, then this trick may work for you:

      // note: write this from memory, maybe there is something wrong :/
      const inputStream = fs.createReadStream(musicPath)
      const decoder = new StreamDecoder()
      inputStream.pipe(decoder)
      decoder.once('data', (chunk) => {
          const encoder = new wav.Writer({
              channels: decoder.getChannels(),
              bitDepth: decoder.getBitsPerSample(),
              sampleRate: decoder.getSampleRate(),
          })

          encoder.write(chunk)

          decoder
              .pipe(encoder)
              .pipe(fs.createWriteStream(musicPath.replace(".flac", ".wav")))
              .on('error', (e) => {
                  return reject(e.message)
              })
      })

      decoder.on('end', () => {
          return resolve(path.parse(musicPath).name)
      })

Hope it helps :)

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

3Q, i will try it recently, and report my result

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

Hello, I tried streamdecoder on Windows and it can be converted. But so far I've found that when I recursively convert a lot of songs. Conversion callbacks do not return 100%. So if you do this recursively it will terminate. In addition FileDecoder after many tests does not exist this problem.

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024
function flacToWav(musicPath: string, isWindows: boolean) {
    return new Promise(function (resolve, _) {
        console.log(musicPath)
        let decoder: any
        if (isWindows) {
            const inputStream = fs.createReadStream(musicPath)
            decoder = new StreamDecoder({})
            inputStream.pipe(decoder)
        } else {
            decoder = new FileDecoder({
                file: musicPath,
            })
        }

        decoder.once('data', (chunk: any) => {
            const encoder = new wav.Writer({
                channels: decoder.getChannels(),
                bitDepth: decoder.getBitsPerSample(),
                sampleRate: decoder.getSampleRate(),
            })

            encoder.write(chunk)

            decoder
                .pipe(encoder)
                .pipe(fs.createWriteStream(musicPath.replace(".flac", ".wav")))
                .on('error', (e: any) => {
                    console.log(e)
                    return Promise.resolve({musicPath: musicPath, reason: "convert fail"})
                })
        })

        decoder.on('end', () => {
            const name = path.parse(musicPath).name
            console.log("convert over: " + name)
            return resolve({musicPath: musicPath, reason: undefined})
        })
    })
}

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

I'm not sure how it can get stuck with a lot of conversions... Are they run one by one, or all at the same time?

Also notice that in your code, when it fails in the on error, you don't call to the resolve method. You will know it failed because of the console.log but the code will get stuck because the Promise of flacToWav is not resolved (nor rejected).

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

yes, they are one by one.
I don't see any printout for the error, which means console.log is not executing
you can see my code through github, and url is

https://github.com/zhushenwudi/LoveLiveMusicPlayer/blob/dev/src/main/util.ts

If you have any ideas, you can write some pseudo-code for reference

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

Oh no errors then. Okey so. When it gets stuck, it does with any specific flac file? Maybe the issue is the StreamDecoder has something wrong handling that file (or a set of files).

Also, you can try to "debug" a bit the code using the DEBUG=flac:* environment variable. But not sure if you will get anything if the code runs on the Chromium process of Electron. This flag tells another library called debug to print messages to the console. If you manage to find the files that makes get stuck or fail, and run your code in a simple node script with the variable, we may find the issue.

Hope it helps you to find something.

Edit: I see that the conversion code runs on the main process (the node one). The DEBUG trick may work then, on the console should appear a lot of debug text (and a lot I mean A LOT).

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

Okay, let me try it, reply late

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

Hello, after two days of testing, I found that there is no format conversion problem in debug mode. Hundreds of songs can be successfully converted one by one. On the other hand, there are still no callbacks when not in Debug mode

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

end of debug message

2022-06-24T14:10:37.069Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.070Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.070Z flac:decoder:stream Processing data
2022-06-24T14:10:37.070Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.071Z flac:decoder:stream Processing data
2022-06-24T14:10:37.071Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.071Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.072Z flac:decoder:stream Processing data
2022-06-24T14:10:37.072Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.073Z flac:decoder:stream Processing data
2022-06-24T14:10:37.073Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.073Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.073Z flac:decoder:stream Processing data
2022-06-24T14:10:37.074Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.074Z flac:decoder:stream Processing data
2022-06-24T14:10:37.074Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.076Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.077Z flac:decoder:stream Processing data
2022-06-24T14:10:37.078Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.079Z flac:decoder:stream Processing data
2022-06-24T14:10:37.080Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.084Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.085Z flac:decoder:stream Processing data
2022-06-24T14:10:37.085Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.085Z flac:decoder:stream Processing data
2022-06-24T14:10:37.086Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.086Z flac:decoder:stream Processing data
2022-06-24T14:10:37.086Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.087Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.087Z flac:decoder:stream Processing data
2022-06-24T14:10:37.087Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.088Z flac:decoder:stream Processing data
2022-06-24T14:10:37.088Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.089Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.089Z flac:decoder:stream Processing data
2022-06-24T14:10:37.089Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.089Z flac:decoder:stream Processing data
2022-06-24T14:10:37.090Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.090Z flac:decoder:stream Processing data
2022-06-24T14:10:37.090Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.091Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.091Z flac:decoder:stream Received 13186 bytes to process
2022-06-24T14:10:37.091Z flac:decoder:stream Processing data
2022-06-24T14:10:37.092Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.092Z flac:decoder:stream Processing data
2022-06-24T14:10:37.092Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.093Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.093Z flac:decoder:stream Processing final chunks of data
2022-06-24T14:10:37.094Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.095Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.095Z flac:decoder:stream Read 8192 bytes from stored chunks to be decoded
2022-06-24T14:10:37.096Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.096Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.097Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.097Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.098Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.099Z flac:decoder:stream Read 4994 bytes from stored chunks to be decoded
2022-06-24T14:10:37.099Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.100Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.100Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.100Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.101Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.101Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.102Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.102Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.102Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.103Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.103Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.104Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.104Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.104Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.105Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.105Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.106Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.106Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.106Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.107Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.107Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.108Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.108Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.108Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.109Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.109Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.111Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.111Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.111Z flac:decoder:stream Received 4096 samples (16384 bytes) of decoded data
2022-06-24T14:10:37.112Z flac:decoder:stream Received 3156 samples (12624 bytes) of decoded data
2022-06-24T14:10:37.112Z flac:decoder:stream Flushing decoder

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

Hello! Now I have some time to investigate more. I found that in FLAC documentation, the function I use to initialize the FLAC Decoder in FileDecoder, on Windows, it does not support paths with non-ascii characters. An example:

image

The first uses a path with non ascii characters (รฑ and รง), the second one does not use any of these. I will investigate if I can workaround this limitation on Windows for the version you have (and if I succeed I'll publish a version for it).

For the other issue with StreamDecoder and no callbacks being called, I'm trying to replicate somehow the issue with the code of your project (adapted for a smaller usage) on Windows. But for now, I always get all files converted fine and without DEBUG enabled.

For now, I will focus on the Unicode path support on Windows which should be better for your use case. I'll report back soon.

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

that's fine, thanks.

After I let my code run by my friend, streamdecoder does have an interrupt. But it doesn't matter if filedecoder can be done well

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

H!, good to hear that it works (in other machine tho) :)

From my side, I found that the official FLAC library fixed this issue with Windows and non-ascii characters in paths, so I'm preparing the v2.7.1 release with the updated flac library updated.

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

that's very good!!
There is another question, please take a look at it~

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

Published 2.7.1! Try to use FileDecoder now on Windows and tell me if it is working now.

I'm looking the other question, and left an answer there. I will update the other one soon...

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

Thank you. I will test it in the local environment and give feedback. Another problem will bother you~ ^_^

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

Good news at last! Happy to see now it is working (more or less), at least the paths are no an issue on Windows :)

If you think this is solved, feel free to close the issue. But if you prefer to wait until you check the "interrupt problem", for me, it is fine ๐Ÿ‘

Thanks for your patience and the help provided for resolving the issue.

from node-flac-bindings.

zhushenwudi avatar zhushenwudi commented on June 8, 2024

Another question, is there a 32-bit windows node file?

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

Currently I do not provide 32 bit binaries of the compiled package, but I could try to create them. I'm not very expert on the Windows side but I surely will investigate it.

I planned to add support for Apple M1/M2 chips, so Windows 32-bit is something I can look at as well.

Will add an answer soon (hopefully today).

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

So I managed to compile the code for windows 32-bit (not for Apple new chips, but nobody asked for them so...).

I uploaded the precompiled binaries for the 2.7.1 version :)

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

I'm supper happy to see all your problems are fixed :D

Thanks for raising the issues, they improved the library!

If there is anything else I can help you with related to the library, don't hesitate to raise a new issue. I'm closing this issue, but feel free to reopen if I'm missing something else.

from node-flac-bindings.

Related Issues (20)

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.