Merge pull request #210 from rakuri255/user-defined-ffmpeg

User defined ffmpeg
This commit is contained in:
Vadim Rangnau authored and GitHub committed 2024-12-26 00:29:46 +01:00
commit 8cf2f80e6f
7 files changed
+70 -19

No files matched your search

+2 -1
View File
@@ -70,7 +70,7 @@ This will help me a lot to keep this project alive and improve it.
### Installation
* Install Python 3.10 **(older and newer versions has some breaking changes)**. [Download](https://www.python.org/downloads/)
* Also install ffmpeg separately with PATH. [Download](https://www.ffmpeg.org/download.html)
* Also download or install ffmpeg with PATH. [Download](https://www.ffmpeg.org/download.html)
* Go to folder `install` and run install script for your OS.
* Choose `GPU` if you have an nvidia CUDA GPU.
* Choose `CPU` if you don't have an nvidia CUDA GPU.
@@ -134,6 +134,7 @@ _Not all options working now!_
--format_version 0.3.0|1.0.0|1.1.0|1.2.0 >> ((default) is 1.2.0)
--musescore_path path to MuseScore executable
--keep_numbers Transcribe numbers as digits and not words
--ffmpeg Path to ffmpeg and ffprobe executable
[yt-dlp]
--cookiefile File name where cookies should be read from
+1
View File
@@ -7,6 +7,7 @@ Date: 2024.12.22
- Optimized whisper language check with confidence
- Improved arguments, so you dont need to use true or false
- Added interactive mode
- Use user defined ffmpeg path
# Version: 0.0.12
Date: 2024.12.19
+3 -1
View File
@@ -10,6 +10,7 @@ from modules.Ultrastar.ultrastar_txt import FormatVersion
@dataclass_json
@dataclass
class Settings:
APP_VERSION = "0.0.13-dev2"
CONFIDENCE_THRESHOLD = 0.6
CONFIDENCE_PROMPT_TIMEOUT = 4
@@ -24,7 +25,8 @@ class Settings:
input_file_is_ultrastar_txt = False # todo: to process_data
keep_cache = False
interactive_mode = False
user_ffmpeg_path = ""
# Process data Paths
input_file_path = ""
output_folder_path = ""
+29 -13
View File
@@ -19,11 +19,11 @@ from modules.Audio.vocal_chunks import (
from modules.Audio.silence_processing import remove_silence_from_transcription_data, mute_no_singing_parts
from modules.Speech_Recognition.Whisper import WhisperModel
from modules.Audio.separation import DemucsModel
from modules.Audio.convert_audio import convert_audio_to_mono_wav, convert_wav_to_mp3
from modules.Audio.youtube import (
download_from_youtube,
)
from modules.Audio.bpm import get_bpm_from_file
from modules.console_colors import (
ULTRASINGER_HEAD,
@@ -67,8 +67,8 @@ from modules.musicbrainz_client import search_musicbrainz
from modules.sheet import create_sheet
from modules.ProcessData import ProcessData, ProcessDataPaths, MediaInfo
from modules.DeviceDetection.device_detection import check_gpu_support
from modules.Audio.bpm import get_bpm_from_file
from modules.Image.image_helper import save_image
from modules.ffmpeg_helper import is_ffmpeg_available, get_ffmpeg_and_ffprobe_paths
from Settings import Settings
@@ -153,13 +153,13 @@ def run() -> tuple[str, Score, Score]:
print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Hyphenation will not be applied')}")
process_data = InitProcessData()
process_data.process_data_paths.cache_folder_path = (
os.path.join(settings.output_folder_path, "cache")
if settings.cache_override_path is None
else settings.cache_override_path
)
# Create process audio
process_data.process_data_paths.processing_audio_path = CreateProcessAudio(process_data)
@@ -213,7 +213,7 @@ def run() -> tuple[str, Score, Score]:
# Cleanup
if not settings.keep_cache:
remove_cache_folder(process_data.process_data_paths.cache_folder_path)
# Print Support
print_support()
return ultrastar_file_output, simple_score, accurate_score
@@ -586,12 +586,29 @@ def main(argv: list[str]) -> None:
"""Main function"""
print_version(settings.APP_VERSION)
init_settings(argv)
if settings.interactive_mode:
check_requirements()
if settings.interactive_mode:
init_settings_interactive(settings)
run()
sys.exit()
def check_requirements() -> None:
if not settings.force_cpu:
settings.tensorflow_device, settings.pytorch_device = check_gpu_support()
print(f"{ULTRASINGER_HEAD} ----------------------")
if not is_ffmpeg_available(settings.user_ffmpeg_path):
print(
f"{ULTRASINGER_HEAD} {red_highlighted('Error:')} {blue_highlighted('FFmpeg')} {red_highlighted('is not available. Provide --ffmpeg ‘path’ or install FFmpeg with PATH')}")
sys.exit(1)
else:
ffmpeg_path, ffprobe_path = get_ffmpeg_and_ffprobe_paths()
print(f"{ULTRASINGER_HEAD} {blue_highlighted('FFmpeg')} - using {red_highlighted(ffmpeg_path)}")
print(f"{ULTRASINGER_HEAD} {blue_highlighted('FFprobe')} - using {red_highlighted(ffprobe_path)}")
print(f"{ULTRASINGER_HEAD} ----------------------")
def remove_cache_folder(cache_folder_path: str) -> None:
"""Remove cache folder"""
os_helper.remove_folder(cache_folder_path)
@@ -671,7 +688,7 @@ def init_settings(argv: list[str]) -> Settings:
f"{ULTRASINGER_HEAD} {red_highlighted('Error: Format version')} {blue_highlighted(arg)} {red_highlighted('is not supported.')}"
)
sys.exit(1)
elif opt in ("--keep_cache"):
elif opt in ("--keep_cache"):
settings.keep_cache = True
elif opt in ("--musescore_path"):
settings.musescore_path = arg
@@ -686,6 +703,8 @@ def init_settings(argv: list[str]) -> Settings:
settings.cookiefile = arg
elif opt in ("--interactive"):
settings.interactive_mode = True
elif opt in ("--ffmpeg"):
settings.user_ffmpeg_path = arg
if settings.output_folder_path == "":
if settings.input_file_path.startswith("https:"):
dirname = os.getcwd()
@@ -693,9 +712,6 @@ def init_settings(argv: list[str]) -> Settings:
dirname = os.path.dirname(settings.input_file_path)
settings.output_folder_path = os.path.join(dirname, "output")
if not settings.force_cpu:
settings.tensorflow_device, settings.pytorch_device = check_gpu_support()
return settings
@@ -726,10 +742,10 @@ def arg_options():
"format_version=",
"keep_cache=",
"musescore_path=",
"keep_numbers=",
"interactive",
"keep_numbers",
"cookiefile="
"interactive",
"cookiefile=",
"ffmpeg="
]
return long, short
@@ -12,11 +12,9 @@ pytorch_gpu_supported = False
def check_gpu_support() -> tuple[bool, bool]:
"""Check worker device (e.g cuda or cpu) supported by tensorflow and pytorch"""
print(f"{ULTRASINGER_HEAD} Checking GPU support for {blue_highlighted('tensorflow')} and {blue_highlighted('pytorch')}.")
print(f"{ULTRASINGER_HEAD} Checking GPU support.")
tensorflow_gpu_supported = False
pytorch_gpu_supported = False
gpus = tf.config.list_physical_devices('GPU')
if gpus:
tensorflow_gpu_supported = True
+3 -1
View File
@@ -56,7 +56,9 @@ def print_help() -> None:
--plot Enable creation of plots. Plots are disabled by default.
--format_version 0.3.0|1.0.0|1.1.0|1.2.0 >> ((default) is 1.2.0)
--musescore_path path to MuseScore executable
--keep_numbers Transcribe numbers as digits and not words
--ffmpeg Path to ffmpeg and ffprobe executable
[yt-dlp]
--cookiefile File name where cookies should be read from and dumped to.
+31
View File
@@ -0,0 +1,31 @@
"""FFmpeg helper module."""
import os
import shutil
def __add_ffmpeg_to_path(ffmpeg_path) -> None:
os.environ["PATH"] = os.pathsep.join([os.environ["PATH"], ffmpeg_path])
def get_ffmpeg_and_ffprobe_paths():
ffmpeg_path = shutil.which("ffmpeg")
ffprobe_path = shutil.which("ffprobe")
if not ffmpeg_path:
raise FileNotFoundError("FFmpeg executable not found in the system path.")
if not ffprobe_path:
raise FileNotFoundError("FFprobe executable not found in the system path.")
return ffmpeg_path, ffprobe_path
def is_ffmpeg_available(user_path: str = "") -> bool:
if shutil.which("ffmpeg"):
return True
if (path := user_path) and path not in os.environ["PATH"]:
__add_ffmpeg_to_path(path)
if shutil.which("ffmpeg"):
return True
return False