Audio
Play sound files with the Audio element, synthesise sound with onFrame, and measure the loudness of the mix.
npx kinetograph audio analyze src/index.tsxnpx kinetograph audio analyze html/index.htmlAdd a voice, a music track or sound effects to a video, and check how loud it is. Tell your agent where the files are and how loud each should sit.
Put public/audio/bed.mp3 under the whole video at 30% volume, fading in over the first second. Then run audio analyze and tell me the loudness.
In code
Audio plays a sound file, and onFrame synthesises sound at a frame. Both are mixed into one stereo track at 48 kHz.
Play a file
import { Audio, Sequence, staticFile } from 'remotion';
<Sequence from={30} durationInFrames={60}>
<Audio src={staticFile('audio/line-1.wav')} volume={0.85} />
</Sequence>Use staticFile for a file in public/. A clip starts where its Sequence starts.
Audio takes volume (a number, or a function of the frame), trimBefore, trimAfter, playbackRate, loop, muted and toneFrequency. To fade in over the first second, pass volume={(frame) => interpolate(frame, [0, 30], [0, 1], { extrapolateRight: 'clamp' })}. Video plays the sound of its file too, with the same props.
The sounds in @remotion/sfx (whip, ding and others) play with <Audio src={whip} />. The first render downloads each one into ~/.cache/kinetograph/sfx, and after that it works offline.
Synthesise sound
onFrame runs a function at a frame. The function gets a Web Audio context and the time to play at:
import { onFrame } from '@kinetographdev/audio';
onFrame(4, (ctx, t) => {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.frequency.setValueAtTime(1800, t);
osc.frequency.exponentialRampToValueAtTime(900, t + 0.05);
gain.gain.setValueAtTime(0.25, t);
gain.gain.exponentialRampToValueAtTime(0.001, t + 0.06);
osc.connect(gain).connect(ctx.destination);
osc.start(t);
osc.stop(t + 0.07);
});- Call
onFrameat the top level of the module, not inside a component. - Schedule against
t(seconds from the start of the rendered range), notctx.currentTime. - For noise, use
randomwith a named seed, such asrandom('whoosh-' + i), so the sound is the same every render.
Render
render mixes every Audio clip and every onFrame callback into one stereo track. .mp4 and .mov use AAC, .webm uses Opus, and .gif has no sound. Set the codec and bit rate with --audio-codec and --audio-bitrate: see the CLI reference.
Check the loudness
npx kinetograph audio analyze examples/rajz-cards/index.tsx --scenes 0..60,60..125npx kinetograph audio analyze html/index.html --scenes 0..60,60..125It prints the integrated loudness (LUFS), the true peak, the number of clipped samples and the silences. --scenes also measures each frame range on its own, and --json prints an object. For gaps, see What works.
Suggested prompt
/kinetograph-markupLay the music under the whole video at 40% volume, fade it in over the first second, and run audio analyze.
What works
- Drawn natively:
AudioandVideo(also from@remotion/media),toneFrequency,@remotion/media-utils, Web Audio synthesis withonFrame, and the loudness check. visualizeAudioanduseWindowedAudioDatagive the values of Remotion 4.0.542.- Not supported:
@remotion/webcodecsencode and decode, and the box tree and sample callbacks of@remotion/media-parser, throwUnsupportedApiError. - See What works.