Skip to content

Commit

Permalink
Added finalise mode to remux and join output video to produce final v…
Browse files Browse the repository at this point in the history
…ersion
  • Loading branch information
beveradb committed Dec 19, 2023
1 parent a5a35c7 commit 341a346
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
44 changes: 44 additions & 0 deletions karaoke_prep/finalise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import subprocess
import tempfile


def karaoke_finalise():
for karaoke_file in filter(lambda f: "(Karaoke).mov" in f, os.listdir(".")):
base_name = karaoke_file.replace("(Karaoke).mov", "")
with_vocals_file = f"{base_name}(With Vocals).mov"
title_file = f"{base_name}(Title).mov"
instrumental_file = f"{base_name}(Instrumental UVR_MDXNET_KARA_2).MP3"
final_mp4_file = f"{base_name}(Final Karaoke).mp4"

if os.path.isfile(title_file) and os.path.isfile(karaoke_file) and os.path.isfile(instrumental_file):
print("Renaming karaoke file to WithVocals")
os.rename(karaoke_file, with_vocals_file)

print(f"Remuxing karaoke video with instrumental audio to '{karaoke_file}'")
subprocess.run(
["ffmpeg", "-an", "-i", with_vocals_file, "-vn", "-i", instrumental_file, "-c:v", "copy", "-c:a", "aac", karaoke_file]
)

print(f"Joining '{title_file}' and '{karaoke_file}' into '{final_mp4_file}'")
with tempfile.NamedTemporaryFile(mode="w+", delete=False, dir="/tmp", suffix=".txt") as tmp_file_list:
tmp_file_list.write(f"file '{os.path.abspath(title_file)}'\n")
tmp_file_list.write(f"file '{os.path.abspath(karaoke_file)}'\n")
subprocess.run(
[
"ffmpeg",
"-f",
"concat",
"-safe",
"0",
"-i",
tmp_file_list.name,
"-vf",
"settb=AVTB,setpts=N/30/TB,fps=30",
final_mp4_file,
]
)

os.remove(tmp_file_list.name)
else:
print(f"Required files for '{base_name}' not found.")
12 changes: 12 additions & 0 deletions karaoke_prep/utils/finalise_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import click
from karaoke_prep.finalise import karaoke_finalise


@click.command()
def main():
"""Command to finalise karaoke videos."""
karaoke_finalise()


if __name__ == "__main__":
main()
File renamed without changes.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-prep"
version = "0.5.1"
version = "0.6.0"
description = "Prepare for karaoke video creation, by downloading audio and lyrics for a specified song or youtube playlist and separatung audio stems."
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"
Expand All @@ -24,7 +24,8 @@ pillow = "^10.1.0"
black = "^23"

[tool.poetry.scripts]
karaoke-prep = 'karaoke_prep.utils.cli:main'
karaoke-prep = 'karaoke_prep.utils.prep_cli:main'
karaoke-finalise = 'karaoke_prep.utils.finalise_cli:main'

[tool.black]
line-length = 140
Expand Down

0 comments on commit 341a346

Please sign in to comment.