Controlling volume and muting
Use volume and muted to control sound from both <Video> and <Audio>.
Setting the volume
Pass a number between 0 and 1 to volume. The default is 1; 0 silences the media.
- Video
- Audio
MyComposition.tsximport {Video } from '@remotion/media'; import {staticFile } from 'remotion'; export constMyComposition = () => { return <Video src ={staticFile ('video.mp4')}volume ={0.5} />; };
MyComposition.tsximport {Audio } from '@remotion/media'; import {staticFile } from 'remotion'; export constMyComposition = () => { return <Audio src ={staticFile ('audio.mp3')}volume ={0.5} />; };
Changing volume over time
Use useCurrentFrame() and interpolate() to animate volume.
This example fades the sound in over 1 second:
- Video
- Audio
MyComposition.tsximport {Video } from '@remotion/media'; import {interpolate ,staticFile ,useCurrentFrame ,useVideoConfig } from 'remotion'; export constMyComposition = () => { constframe =useCurrentFrame (); const {fps } =useVideoConfig (); constvolume =interpolate (frame , [0,fps ], [0, 1], {extrapolateLeft : 'clamp',extrapolateRight : 'clamp', }); return <Video src ={staticFile ('video.mp4')}volume ={volume } />; };
MyComposition.tsximport {Audio } from '@remotion/media'; import {interpolate ,staticFile ,useCurrentFrame ,useVideoConfig } from 'remotion'; export constMyComposition = () => { constframe =useCurrentFrame (); const {fps } =useVideoConfig (); constvolume =interpolate (frame , [0,fps ], [0, 1], {extrapolateLeft : 'clamp',extrapolateRight : 'clamp', }); return <Audio src ={staticFile ('audio.mp3')}volume ={volume } />; };
Clamping keeps the volume between 0 and 1 outside the fade. To fade out, use [1, 0] as the output range and choose the frames where the fade should start and end.
With Studio interactivity enabled, the Studio recognizes these keyframes, lets you edit them, and draws the volume curve in the timeline.
Select an audio or video timeline row and press V to select its volume property. v4.0.530
Muting
Pass muted to silence a clip. For videos, the picture continues playing.
You can change muted over time. This example mutes sound from 2 seconds up to, but not including, 4 seconds:
- Video
- Audio
MyComposition.tsximport {Video } from '@remotion/media'; import {staticFile ,useCurrentFrame ,useVideoConfig } from 'remotion'; export constMyComposition = () => { constframe =useCurrentFrame (); const {fps } =useVideoConfig (); return <Video src ={staticFile ('video.mp4')}muted ={frame >= 2 *fps &&frame < 4 *fps } />; };
MyComposition.tsximport {Audio } from '@remotion/media'; import {staticFile ,useCurrentFrame ,useVideoConfig } from 'remotion'; export constMyComposition = () => { constframe =useCurrentFrame (); const {fps } =useVideoConfig (); return <Audio src ={staticFile ('audio.mp3')}muted ={frame >= 2 *fps &&frame < 4 *fps } />; };
The muted prop is also supported by <OffthreadVideo>, <Html5Video> and <Html5Audio>.