Giter Site home page Giter Site logo

Is there any way to load waveform from JSON data generated on a server for larger files of around 2GB or more? about wfplayer HOT 5 CLOSED

zhw2590582 avatar zhw2590582 commented on September 20, 2024
Is there any way to load waveform from JSON data generated on a server for larger files of around 2GB or more?

from wfplayer.

Comments (5)

salmanAhmad143 avatar salmanAhmad143 commented on September 20, 2024 1

@zhw2590582 I am doing the same and trying to load pcm file using wf.load() like above you have mentioned-

`fetch('http://localhost:3000/images/standard-captions.pcm')

.then((res) => res.arrayBuffer())
.then((buffer) => {
    this.wf.load({
        sampleRate: 44100,
        getChannelData() {
            return new Float32Array(buffer);
        },
    });
});`

But it showing me error that -

"The load target is not a string. If you are loading a mediaElement, make sure the mediaElement.src is not empty."

I think this is due to this:

`load(target) {

   if (target instanceof HTMLVideoElement || target instanceof HTMLAudioElement) {
        this.options.mediaElement = target;
        target = target.src;
    }
    errorHandle(
        **typeof target === 'string' && target.trim(),**
        `The load target is not a string. If you are loading a mediaElement, make sure the mediaElement.src is not empty.`,
    );
    this.loader.load(target);
    this.emit('load');
    return this;
}`

Please suggest where i am doing wrong?

Thanks

from wfplayer.

zhw2590582 avatar zhw2590582 commented on September 20, 2024

Yes, actually wf.load method can be loaded AudioBuffer,Or you can parse the PCM data for audio on the server, such as using web-audio-api,Then the front-end loads PCM data through Ajax and simulates it as AudioBuffer, In one of my personal projects, that's how it works:

Node.js:

const fs = require('fs');
const { AudioContext } = require('web-audio-api');
const context = new AudioContext();

context.decodeAudioData(fs.readFileSync('/path/to/audio.mp3'), (audiobuffer) => {
    // choose your channel
    const channelData = audiobuffer.getChannelData(0);
    fs.writeFileSync('/path/to/audio.pcm', channelData);
});

browser:

fetch('/path/to/audio.pcm')
    .then((res) => res.arrayBuffer())
    .then((buffer) => {
        wf.load({
            sampleRate: 44100,
            getChannelData() {
                return new Float32Array(buffer);
            },
        });
    });

from wfplayer.

zhw2590582 avatar zhw2590582 commented on September 20, 2024

I forgot to release the latest version, you now try to install the latest version: [email protected]

from wfplayer.

salmanAhmad143 avatar salmanAhmad143 commented on September 20, 2024

Hi @zhw2590582 ,

Thanks for your reply. I have updated [email protected] version at my end and now the error not showing but the wave not been generating. Only a thin line is drawing in the timeline area. If i am increasing sampleRate value then length of line has been increasing but still wave not generating. See below-

timeline

This is buffer array that i am passing in load() function-

arrayBuffer

I am creating .pcm from .mp4 file using ffmpeg. Please suggest what i am making wrong?

Thanks,

from wfplayer.

zhw2590582 avatar zhw2590582 commented on September 20, 2024

In fact, WFPlayer does not yet support PCM files generated by ffmpeg, I found that the PCM data generated by ffmpeg and the PCM data generated by AudioContext are very different. I have not found a compatible method, so I suggest you use web-audio-api to generate PCM data. Another point is that the sampleRate option must be the same as the audio sampleRate, otherwise the rendering will be abnormal.

const fs = require('fs');
const { AudioContext } = require('web-audio-api');
const context = new AudioContext();

context.decodeAudioData(fs.readFileSync('/path/to/audio.mp3'), (audiobuffer) => {
    console.log(audiobuffer.sampleRate)
    // choose your channel
    const channelData = audiobuffer.getChannelData(0);
    fs.writeFileSync('/path/to/audio.pcm', channelData);
});

from wfplayer.

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.