Giter Site home page Giter Site logo

Comments (3)

melchor629 avatar melchor629 commented on June 8, 2024

Hello! This is the first time I see this feature of the flac tool, and I never read about it before. I will try my best to help you.

First, what you want is something you can accomplish using the available APIs (either through streams or using the metadata API level 1 or level 2). I know the metadata APIs are a bit complicated so that's why added the metadata array for the stream encoders (FileEncoder and StreamEncoder). I will focus on this API.

The metadata property in the constructor just tells the encoder to write those flac metadata blocks into the output stream/file. In your example, you are adding several empty metadata blocks to the output file (not sure if libflac sees this and removes them or something).

For that case, the idea is to read the RIFF chunks beforehand, store each chunk in an array of buffers (the whole chunk) and then write them as application metadata with id riff (see this). The only thing I don't know for sure if it just needs to be metadata block for all chunks or one metadata block for each chunk. My guess goes to the one for each.

Imagine that you have a library that reads all RIFF chunks somehow using an async iterator, and puts the raw chunk in a property called raw. The idea would look like this:

// read riff chunks
const pathToTheFile = '...'
const riffChunks = []
for await (const riffChunk of readRiffChunks(pathToTheFile)) {
  const riffApplicationMetadata = new flac.metadata.ApplicationMetadata()
  riffApplicationMetadata.id = 'riff'
  riffApplicationMetadata.data = riffChunk.raw
  riffChunks.push(riffApplicationMetadata)
}

// create encoder with the metadata block
const flacEncoder = new flac.FileEncoder({
  file: output || 'out.flac',
  compressionLevel: 9,
  metadata: riffChunks,
})

Note that I could not test that properly, don't have anything to try this fine. This "code" gives you something like this:
out.flac hex

If you would like to inspect further, I made a quick CodeSandbox https://codesandbox.io/p/sandbox/lively-bash-gw9jnh?file=%2Findex.js%3A76%2C38

I could not find any npm package that I liked to use for this sample (I have to say I just spend 10 minutes looking) so I made the code to read the chunks manually. Is not that complicated I have to say hehe. I hope this helps you find the solution to your issue.

On the other hand, I don't quite like the idea to have this kind of code around, which is not from flac API directly. I see the utility of it but I don't many people using it for their daily use. If you would like to keep this for your project, for me it's fine.

Anyway, I also don't mind to have it anyways if the code does not use any external dependency. Like an utils package inside the library 🤔 I would accept the PR. The only issue is I don't have time to maintain two versions for the library (2.x and 3.x), so it will only go to 3.x, sorry for that tho.

Thanks for raising the issue :)

from node-flac-bindings.

kmturley avatar kmturley commented on June 8, 2024

Thanks for your thoughtful comment and useful advice/examples.

Comparing the two files you generated in your codebox:

exiftool ./test/out.flac -G1
Screenshot 2023-10-22 at 3 47 07 PM

They appear to be different metadata. I will spend some time on this over the next few days and then report back my findings!

from node-flac-bindings.

melchor629 avatar melchor629 commented on June 8, 2024

Hello again! At least something is being read with that tool! That's something hehe

Good luck with the investigations. I am looking forward to your results. If you need some help, I may be able to assist you.

Also, take a look at flac's source code, something I did not think of yesterday to check: https://github.com/xiph/flac/blob/master/src/flac/foreign_metadata.c#L210 Maybe you see something useful in it.

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.