This Node.js project generates a video by combining:
- A waveform animation based on a
.wavaudio file - A static logo centered on the screen
- A custom background and animated waveform line
- Frame-by-frame rendering with
canvas - Video generation using
ffmpeg
The output is a .mp4 video with frame-accurate synchronization to the audio.
.
├── config.js # Constants like paths, frame rate, dimensions
├── functions
│ ├── renderer.js # Generate individual frames
│ ├── utils.js # File system utilities (ensure, cleanup)
│ ├── videoBuilder.js # Compiles frames and audio into a video
│ └── waveform.js # Extracts waveform data
├── main.js # Main script
├── media
│ ├── audio.wav # Input audio file
│ └── logo.png # Static logo to overlay
└── output
└── final.mp4 # Rendered videonpm install
node main.jsA final.mp4 file will be created in the root directory.
- Adjust animation speed and resolution by modifying
config.js:- FRAME_RATE
- WIDTH / HEIGTH
- Waveform appearance:
- WAVE_COLOR
- scaleX / scaleY in
renderer.js/drawFrame()
.audioCodec("aac"): Encodes audio using Advanced Audio Codec (aac).videoCodec("libx264): Encodes video using H.264 codec"libx265": for higher resolutions (4K)
.outputOptions([...]):"pix_fmt ...": Ensure pixel format is compatible with most video palyers"yuv420p": Standard 8-bit per channel, with 4:2:0 chroma subsampling."yuv422p": Higher color fidelity (4:2:2)"yuv444p": No chroma subsampling, best color fidelity
"-shortest": Ensure video stops when audio ends
- Canvas
- wav
- fluent-ffmpeg
- ffmpeg-static
- fs (built in)
Manually install (if neededd):
npm install canvas wav fluent-ffmpeg ffmpeg-static