From 99f0fef5bc32086770f0c78c397c580e59c3b881 Mon Sep 17 00:00:00 2001 From: Joel Trauger Date: Thu, 6 Mar 2025 23:49:59 -0600 Subject: [PATCH] potential fix for #8 --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++--- __init__.py | 23 +++++++++++++++++++++- nodes.py | 6 +++--- 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 22ee711..39187f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ComfyUI-Riffusion -A ComfyUI extension for Riffusion audio generation. +A ComfyUI extension for Riffusion audio generation. Requires installation of 3rd-party software FFmpeg. ## Installation @@ -9,7 +9,56 @@ A ComfyUI extension for Riffusion audio generation. OR Install via Comfy Registry: https://registry.comfy.org/publishers/traugdor/nodes/riffusion -2. Restart ComfyUI +2. Download and install FFMPEG by following these instructions: + +### Windows users + +1. **Download FFmpeg:** + * Go to the [official FFmpeg download page](https://ffmpeg.org/download.html). + * Click on the "Windows" logo and select a build (usually, the "gpl" builds are recommended). You may find builds hosted by third-party sites like Gyan.dev or BtbN. +2. **Extract the Files:** + * Once downloaded, extract the contents of the ZIP file to a location on your computer (e.g., C:\ffmpeg). +3. **Add FFmpeg to System PATH:** + * Right-click on "This PC" or "Computer" on your desktop or in File Explorer and select "Properties." + * Click on "Advanced system settings" on the left side. + * In the System Properties window, click on the "Environment Variables" button. + * In the Environment Variables window, find and select the "Path" variable in the "System variables" section, then click "Edit." + * Click "New" and add the path to the bin directory of the extracted FFmpeg folder (e.g., C:\ffmpeg\bin). + * Click "OK" to close all dialog boxes. +4. **Verify Installation:** + * Open Command Prompt (press Win + R, type cmd, and hit Enter). + * Type the following command and press Enter: + ```bash + ffmpeg -version + ``` + * If FFmpeg is correctly installed, you will see version information and other details. You may need to close and reopen your Command Prompt/Powershell/Terminal window to get the latest environment variables. +5. **Restart ComfyUI** + +### Linux users + +1. **Open Terminal** +2. **Install FFmpeg** using your package manager + * Debian/Ubuntu-based: + ```bash + sudo apt update + sudo apt install ffmpeg + ``` + * Fedora: + ```bash + sudo dnf install ffmpeg + ``` + * Arch: + ```bash + sudo pacman -S ffmpeg + ``` +3. **Verify installation** + * After installation is complete, you can verify that FFmpeg is installed correctly by running: + ```bash + ffmpeg -version + ``` + * If FFmpeg is installed, you will see version information and other details about the installation. + +4. **Restart ComfyUI** ## Usage @@ -18,4 +67,4 @@ The extension adds a new node "Riffusion" under the audio category. ## TODO - Add support for multiple images (as input) to generate a single audio file for longer audio lengths - Add support for multiple images to generate multiple audio files -- Add support for other audio types (wav, mp3, ogg, etc.) \ No newline at end of file +- Add FFmpeg installer for Windows/Linux? Current method is to warn user and disable audio formats that require FFmpeg \ No newline at end of file diff --git a/__init__.py b/__init__.py index d63d447..5ed57d2 100644 --- a/__init__.py +++ b/__init__.py @@ -2,6 +2,8 @@ import sys import subprocess from pathlib import Path +FFMPEG_IS_NOT_INSTALLED = False + ### GET PACKAGES ### def packages(versions=False): try: @@ -32,7 +34,26 @@ required_packages = read_requirements() for package in required_packages: if package.lower() not in [pkg.lower() for pkg in installed_packages]: install_package(package) -print("All packages needed by Riffusion are installed.") +print("All Python packages needed by Riffusion are installed.") + +### Ensure FFmpeg is installed ### +# FFmpeg is a 3rd-party program that is needed for Riffusion to work and it's not a Python library. +# determine if system is windows or linux??? MacOS is not really supported for Stable Diffusion +try: + result = subprocess.check_output(['ffmpeg', '-version'], stderr=subprocess.STDOUT) + print("FFmpeg is installed.") +except subprocess.CalledProcessError as e: + print("[Riffusion WARNING] An error occurred while checking FFmpeg installation:", e.output.decode()) + print("[Riffusion WARNING] All other audio formats will be disabled until until the previous error is resolved.") + FFMPEG_IS_NOT_INSTALLED = True +except FileNotFoundError: #Windows gives a FileNotFoundError + print("[Riffusion WARNING] FFmpeg is not installed.") + print("[Riffusion WARNING] Please install FFmpeg from https://ffmpeg.org/download.html. All other audio formats will be disabled until FFmpeg is installed.") + # set flag to signal FFMpeg is not installed + FFMPEG_IS_NOT_INSTALLED = True + +# TODO: Add FFmpeg installer for Windows +# TODO: Add FFmpeg installer for Linux ### Don't import nodes until all packages are installed ### from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS diff --git a/nodes.py b/nodes.py index 074bb50..8288b8a 100644 --- a/nodes.py +++ b/nodes.py @@ -23,7 +23,7 @@ class RiffusionNode: return { "required": { 'spectrogram': ("IMAGE",), - 'filename_prefix': ("STRING", {"default": "Riffusion"}), + 'filename_prefix': ("STRING", {"default": "audio\Riffusion"}), }, } @@ -132,7 +132,7 @@ class RiffusionNode: else: max_number = 0 for file in list_of_files: - number = int(file.split("_")[-1].split(".")[0]) + number = int(file.split("_")[-2]) max_number = max(max_number, number) # Increment the number and add it to the filename and add the extension new_number = max_number + 1 @@ -155,7 +155,7 @@ class RiffusionNode: print(f"Duration of {new_filename}: {duration}") # get full output path - full_output_path = os.path.join(self.output_dir, new_filename) + full_output_path = os.path.join(output_dir, new_filename) # save the audio with open(full_output_path, 'wb') as f: