VladislavPetyukevich / audio-visualizer

MIT License
26 stars 4 forks source link

spectrum doesn't show up #7

Open iAmKeyvan72 opened 3 years ago

iAmKeyvan72 commented 3 years ago

Hi, i've just copied your code with my mp3 and background. output.mp4 is a video with my background and my mp3 song but spectrum doesn't show up! did i do anything wrong? here is my code (actually your code):

const renderAudioVisualizer =
  require('nodejs-audio-visualizer').renderAudioVisualizer;

const createMusicVisualizer = async (background, mp3) => {
  const config = {
    image: {
      path: background, // Supports PNG and JPG images
    },
    audio: {
      path: mp3, // Supports MP3 and WAV audio
    },
    outVideo: {
      path: './final/out.mp4',
      fps: 25, // Default value: 60
      spectrum: {
        // Audio spectrum configuration. Optional.
        width: 300, // Default value: 40% of background image width
        height: 300, // Default value: 10% of background image height
        color: '#cccc99', // Default value: inverted color of background image
      },
    },
    tweaks: {
      // Optional
      ffmpeg_cfr: '30', // Default value: 23
      ffmpeg_preset: 'medium', // Default value: medium
      frame_processing_delay: 1000, // Delay between processing frames in milliseconds
    },
  };

  const onProgress = (progressPercent) => {
    // not necessary callback
    console.log(`progress: ${progressPercent} %`);
  };

  let counter = 0;
  const shouldStop = () => {
    // not necessary callback
    if (counter > 5) {
      return true;
    }
    counter++;
    return false;
  };

  renderAudioVisualizer(config, onProgress, shouldStop).then((exitCode) => {
    console.log(`exited with code: ${exitCode}`);
  });
};

module.exports = { createMusicVisualizer };

and another question: can i move and rotate the spectrum? i need it to be in some position in the middle of video.

marc-schieferdecker commented 3 years ago

You have to remove:

let counter = 0;
  const shouldStop = () => {
    // not necessary callback
    if (counter > 5) {
      return true;
    }
    counter++;
    return false;
  };

from the js.

Also edit :

renderAudioVisualizer(config, onProgress).then((exitCode) => {
    console.log(`exited with code: ${exitCode}`);
  });
VladislavPetyukevich commented 3 years ago

Try solution from @marc-schieferdecker (thank you for the attention btw). Also the possibility of changing spectrum rotation and position is planned for the future

iAmKeyvan72 commented 3 years ago

@marc-schieferdecker Thank you! your solution fixed it. @VladislavPetyukevich I'm looking forward to your awesome job and i wish you could make it more customisable. Thank you.