redotvideo / revideo

Create Videos with Code
https://re.video
MIT License
2.41k stars 77 forks source link

volumes don't work #311

Open mhpsy opened 6 days ago

mhpsy commented 6 days ago

I've modified the audio and video volumes in my code, but when I render the final output, the volumes remain at their default settings. Could someone explain why this might be happening and how I can effectively adjust the volumes in my Revideo project? Thank you in advance for your assistance!

this is a very simple code!

  const startAudioRef = yield* addAudio(view, '/daolang/start.wav', {
    play: false
  });

  const videoRef = createRef<Video>();
  const bgRef = createRef<Img>();

  yield view.add(
    <>
      <Rect size={['100%', '100%']} fill={'#000'} />
      <Img ref={bgRef} src={'/bg1.png'} size={['100%', '100%']} opacity={0} />
      <Video ref={videoRef} src={'/daolang/dl_ych.mp4'} size={{ width: 1920, height: 1080 }} play={true} loop time={0.1} />
    </>,
  );

  yield* waitFor(6);

  // this setVolume 0.2,but render is not ok
  videoRef().setVolume(0.2);

  startAudioRef().play();

and show addAudio function

export function* addAudio(
    view: View2D,
    audioUrl: string,
    options?: {
        play?: boolean
        volume?: number
    }
) {
    const audioRef = createRef<Audio>();
    const play = options?.play ?? true;
    const volume = options?.volume ?? 1;

    yield view.add(
        <Audio
            src={audioUrl}
            ref={audioRef}
            play={play}
            volume={volume}
        />
    );

    return audioRef;
}
justusmattern27 commented 6 days ago

you're right - setVolume is curently not supported during exports. A workaround would be to just create a new video tag, make it start at second 6, and adjust its volume prop. But I agree that this should 100% be fixed