FoleyCrafter
repository·main·Indexed 20 days ago
https://github.com/open-mmlab/foleycrafterA video-to-audio generation framework that produces semantically relevant and synchronized sound effects for videos. It features a temporal adapter for audio-visual synchronization, support for positive and negative text prompts to guide generation, and a Gradio-based web interface. The framework includes the FoleyController.foley API for controlling parameters such as visual content scale, temporal align scale, and sampling methods.
What's inside FoleyCrafter
- FoleyCrafter is a video-to-audio generation framework designed to produce realistic sound effects that are semantically relevant and synchronized with video content. It aims to enhance the audiovisual experience for cinema and gaming by bringing silent videos to life with lifelike sounds.
Install FoleyCrafter via Conda
mainTo set up the FoleyCrafter environment, use the provided
environment.yamlfile to create a new Conda environment and then activate it. You must also install and initializegit-lfsto ensure checkpoints can be downloaded correctly.# install conda environment conda env create -f requirements/environment.yaml conda activate foleycrafter # install GIT LFS for checkpoints download conda install git-lfs git lfs installControl Audio Generation with Prompts
mainYou can guide the audio generation process using text prompts.
- Positive Prompt: Use
--promptto specify desired sounds (e.g.,'seagulls'). - Negative Prompt: Use
--npromptto specify sounds you want to exclude (e.g.,'river flows'). - Seed: Use
--seedto ensure reproducibility.
# Example: Generating audio with a specific prompt python inference.py \ --input=input/PromptControl/case1/ \ --seed=10201304011203481429 \ --prompt='noisy, people talking' \ --save_dir=output/PromptControl/case1_prompt/ # Example: Generating audio while excluding specific sounds python inference.py \ --input=input/PromptControl/case3/ \ --seed=10041042941301238011 \ --nprompt='river flows' \ --save_dir=output/PromptControl/case3_nprompt/- Positive Prompt: Use
Download FoleyCrafter Checkpoints
mainCheckpoints are automatically downloaded when running
inference.py. However, you can download them manually usinggit clone.Manual Download Steps:
- Clone the Auffusion text-to-audio base model into
checkpoints/auffusion. - Clone the FoleyCrafter model into the
checkpoints/directory.
Required Directory Structure: Ensure your
checkpointsfolder follows this structure:└── checkpoints ├── semantic │ ├── semantic_adapter.bin ├── vocoder │ ├── vocoder.pt │ ├── config.json ├── temporal_adapter.ckpt └── timestamp_detector.pth.tar# Download the text-to-audio base model (Auffusion) git clone https://huggingface.co/auffusion/auffusion-full-no-adapter checkpoints/auffusion # Download FoleyCrafter git clone https://huggingface.co/ymzhang319/FoleyCrafter checkpoints/- Clone the Auffusion text-to-audio base model into
Configure FoleyCrafter generation parameters
mainWhen using the FoleyCrafter interface, two key scales control the generation quality:
- Visual Content Scale (
ip_adapter_scale): Determines the level of semantic alignment between the visual content of the video and the generated audio. - Temporal Align Scale (
temporal_scale): Determines how strongly the audio synchronizes with temporal visual cues. If the input video has strong temporal movements (e.g., a hammer hitting a nail), increasing this scale helps the audio match those moments.
- Visual Content Scale (
Run the FoleyCrafter Gradio Demo
mainFoleyCrafter provides a Gradio-based web interface for generating synchronized audio from silent videos. You can launch the server using the
app.pyentrypoint with several CLI arguments to configure the server and model paths.CLI Arguments:
--config: Path to the configuration file (default:example/config/base.yaml).--server-name: The hostname to bind the server to (default:0.0.0.0).--port: The port number to listen on (default:7860).--share: Boolean flag to enable a public Gradio share link.--save-path: Directory where generated samples are stored (default:samples).--ckpt: Directory containing model checkpoints (default:checkpoints/).
python app.py --config example/config/base.yaml --port 7860Perform Video-to-Audio Generation
mainUse
inference.pyto generate audio from input videos. By default, this performs standard video-to-audio generation.python inference.py --save_dir=output/sora/Perform Video-to-Audio Generation with Temporal Alignment
mainTo ensure the generated audio aligns better with visual cues in the video, use the
--temporal_alignflag. This utilizes a temporal adapter to synchronize audio events with visual changes.python inference.py \ --temporal_align \ --input=input/avsync \ --save_dir=output/avsync/Launch the Gradio Demo
mainYou can interact with FoleyCrafter through a web-based Gradio interface by running
app.py. Use the--shareflag to generate a public URL if you want to share the interface.python app.py --shareReference: inference.py CLI Arguments
mainThe
inference.pyscript accepts the following command-line arguments for controlling the audio generation process.options: -h, --help show this help message and exit --prompt PROMPT prompt for audio generation --nprompt NPROMPT negative prompt for audio generation --seed SEED ramdom seed --temporal_align TEMPORAL_ALIGN use temporal adapter or not --temporal_scale TEMPORAL_SCALE temporal align scale --semantic_scale SEMANTIC_SCALE visual content scale --input INPUT input video folder path --ckpt CKPT checkpoints folder path --save_dir SAVE_DIR generation result save path --pretrain PRETRAIN generator checkpoint path --device DEVICEUse the FoleyController.foley API for video-to-audio generation
mainThe
FoleyController.foleymethod is the core API for generating synchronized audio. It takes a video and several control parameters to guide the generation process.Parameters:
input_video(str): Path to the input video file.prompt_textbox(str): Text prompt describing the desired sound.negative_prompt_textbox(str): Text prompt for sounds to avoid.ip_adapter_scale(float): Visual Content Scale (0.0 to 1.0). Controls semantic alignment with visual content.temporal_scale(float): Temporal Align Scale (0.0 to 1.0). Controls how well the audio aligns with temporal visual cues.sampler_dropdown(str): The sampling method to use. Options:DDIM,Euler,PNDM.sample_step_slider(int): Number of inference steps (10 to 100).cfg_scale_slider(float): Classifier-Free Guidance (CFG) scale (7.5 to 20).seed_textbox(str): Seed for reproducibility.
Returns:
save_sample_path(str): Path to the generated.mp4file containing the original video with the new synchronized audio.
# Note: This is a conceptual usage of the controller method result_video_path = controller.foley( input_video="path/to/video.mp4", prompt_textbox="birds chirping", negative_prompt_textbox="", ip_adapter_scale=1.0, temporal_scale=0.2, sampler_dropdown="DDIM", sample_step_slider=25, cfg_scale_slider=7.5, seed_textbox="42" )