From 749a72031b535dcae9d461aee2b3d066d5d78367 Mon Sep 17 00:00:00 2001 From: Sting <loic.allegre@ensiie.fr> Date: Wed, 21 Jun 2023 10:59:52 +0200 Subject: [PATCH] Wrap WAV & Vocals extraction in main script --- .gitignore | 1 + README.md | 12 ++++++++++-- autokara.py | 27 +++++++++++++++++++++++++++ extractWav.sh | 5 ++++- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 autokara.py diff --git a/.gitignore b/.gitignore index 7f809ec..7f215e8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ !extractWav.sh !extractAss.sh !karaUtils.py +!autokara.py media/ \ No newline at end of file diff --git a/README.md b/README.md index 1091c5e..def9463 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ Get a data buffer from an audio file: - MKVToolnix (at least the CLI utils) - Python >= 3.8 +Having a CUDA-capable GPU is optional, but can greatly reduce processing time. + ## Setup This project requires at least Python 3.8, and using a virtual environment is strongly recommended. @@ -55,9 +57,15 @@ $ deactivate # Use -To extract .wav audio from all MKVs in a folder : +To execute AutoKara on a MKV video file : +```bash +$ python autokara.py video.mkv +``` + + +To extract .wav audio from a MKV file : ```bash -$ ./extractWav.sh source_folder output_folder +$ ./extractWav.sh source_video output_audio ``` To separate vocals from instruments in an audio file : diff --git a/autokara.py b/autokara.py new file mode 100644 index 0000000..4d4512a --- /dev/null +++ b/autokara.py @@ -0,0 +1,27 @@ +import sys +import demucs.separate +import subprocess +import shlex +from pathlib import Path + + +try: + video_file = sys.argv[1] +except IndexError: + print("usage : %s video_file" % sys.argv[0]) + sys.exit("Invalid Arguments") + +Path("./media/audio").mkdir(parents=True, exist_ok=True) +basename = Path(video_file).stem +audio_file = "media/audio/%s.wav" % basename + +subprocess.call(shlex.split('./extractWav.sh "%s" "%s"' % (video_file, audio_file))) + +Path("./media/vocals").mkdir(parents=True, exist_ok=True) +output_folder = "./media/vocals" + +# Not working, don't know why +# demucs.separate.main(shlex.split('--two-stems vocals -o "%s" "%s"' % (output_folder, audio_file))) +subprocess.call(shlex.split('demucs --two-stems vocals -o "%s" "%s"' % (output_folder, audio_file))) + +vocals_file = "./media/vocals/htdemucs/%s/vocals.wav" % basename diff --git a/extractWav.sh b/extractWav.sh index 31c8b4e..6686929 100755 --- a/extractWav.sh +++ b/extractWav.sh @@ -28,8 +28,11 @@ fi filename=$1 +dest_file=$2 echo $filename +echo $dest_file + [ -e "$filename" ] || continue name=${filename##*/} base=${name%.mkv} @@ -84,7 +87,7 @@ ffmpeg -i "$base.$extension" "$base.wav" && \ #sox "$2/$base.stereo.wav" "$2/$base.wav" remix - && \ #rm "$2/$base.stereo.wav" && \ rm "$base.$extension" -mv "$base.wav" $2 +mv "$base.wav" "$2" -- GitLab