Views
No views yet
1GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/HKUSTAudio/VidMuse
2cd VidMuseVidMuse libraryconda create -n VidMuse python=3.9
conda activate VidMuse
pip install git+https://github.com/ZeyueT/VidMuse.git1sudo apt-get install ffmpeg
2# Or if you are using Anaconda or Miniconda
3conda install "ffmpeg<5" -c conda-forge1from video_processor import VideoProcessor, merge_video_audio
2from audiocraft.models import VidMuse
3import scipy
4
5# Path to the video
6video_path = 'sample.mp4'
7# Initialize the video processor
8processor = VideoProcessor()
9# Process the video to obtain tensors and duration
10local_video_tensor, global_video_tensor, duration = processor.process(video_path)
11
12progress = True
13USE_DIFFUSION = False
14
15# Load the pre-trained VidMuse model
16MODEL = VidMuse.get_pretrained('HKUSTAudio/VidMuse')
17# Set generation parameters for the model based on video duration
18MODEL.set_generation_params(duration=duration)
19
20try:
21 # Generate outputs using the model
22 outputs = MODEL.generate([local_video_tensor, global_video_tensor], progress=progress, return_tokens=USE_DIFFUSION)
23except RuntimeError as e:
24 print(e)
25
26# Detach outputs from the computation graph and convert to CPU float tensor
27outputs = outputs.detach().cpu().float()
28
29
30sampling_rate = 32000
31output_wav_path = "vidmuse_sample.wav"
32# Write the output audio data to a WAV file
33scipy.io.wavfile.write(output_wav_path, rate=sampling_rate, data=outputs[0, 0].numpy())
34
35output_video_path = "vidmuse_sample.mp4"
36# Merge the original video with the generated music
37merge_video_audio(video_path, output_wav_path, output_video_path)@article{tian2024vidmuse,
title={Vidmuse: A simple video-to-music generation framework with long-short-term modeling},
author={Tian, Zeyue and Liu, Zhaoyang and Yuan, Ruibin and Pan, Jiahao and Liu, Qifeng and Tan, Xu and Chen, Qifeng and Xue, Wei and Guo, Yike},
journal={arXiv preprint arXiv:2406.04321},
year={2024}
}