Skip to content

Commit

Permalink
add music back to video using spleeter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalaj-G committed Sep 6, 2024
1 parent 4dd58ba commit ebccbb9
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions app_rvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import time
import hashlib
import sys
from soni_translate.spleeter import run_spleeter

directories = [
"downloads",
Expand Down Expand Up @@ -1129,15 +1130,31 @@ def multilingual_media_conversion(
else:
base_video_file = vid_subs

if not self.task_in_cache("output", [
hash_base_video_file,
hash_base_audio_wav,
burn_subtitles_to_video
], {}):
spleeter_outdir = "./spleeter/"
remove_directory_contents(spleeter_outdir)
run_spleeter(base_audio_wav, spleeter_outdir)
# vocals_spleeter = os.path.join(
# spleeter_outdir, os.path.splitext(base_audio_wav)[0], "vocals.wav"
# )
instrumental_spleeter = os.path.join(
spleeter_outdir,
os.path.splitext(base_audio_wav)[0],
"accompaniment.wav",
)
final_audio = "audio_final.mp3"
run_command(
f'ffmpeg -y -i "{mix_audio_file}" -i "{instrumental_spleeter}" -filter_complex "[0:a][1:a]amerge=inputs=2[aout]" -map "[aout]" -c:a libmp3lame -q:a 4 "{final_audio}"'
)

if not self.task_in_cache(
"output",
[hash_base_video_file, hash_base_audio_wav, burn_subtitles_to_video],
{},
):
# Merge new audio + video
remove_files(video_output_file)
run_command(
f"ffmpeg -i {base_video_file} -i {mix_audio_file} -c:v copy -c:a copy -map 0:v -map 1:a -shortest {video_output_file}"
f"ffmpeg -i {base_video_file} -i {final_audio} -c:v copy -c:a copy -map 0:v -map 1:a -shortest {video_output_file}"
)

output = media_out(
Expand Down

0 comments on commit ebccbb9

Please sign in to comment.