Last active
October 21, 2023 00:26
-
-
Save ManeFunction/8351b01b6a601d5545ef2ca1f00ee022 to your computer and use it in GitHub Desktop.
MKA + MKV batch combiner (py)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script can easily combine MKV and MKA files to the single MKV package | |
# Required installed ffmpeg (can be easily done with brew install ffmpeg) | |
# As a bonus, can copy ass subtites as well | |
# Enjoy :) | |
# by Mane Function (2023) | |
import os | |
import shutil | |
import subprocess | |
# Define the root folder and output path | |
root_folder = '/path/to/source/folder' # Source folder path | |
output_path = '/path/to/target/folder' # Target folder path | |
# Recursively traverse the root folder | |
for folder, subfolders, files in os.walk(root_folder): | |
for file in files: | |
if file.endswith('.mkv'): | |
input_video = os.path.join(folder, file) | |
input_audio = os.path.join(folder, file.replace('.mkv', '.mka')) | |
output_file = os.path.join(output_path, os.path.relpath(input_video, root_folder)) | |
# Create the output directory structure if it doesn't exist | |
output_dir = os.path.dirname(output_file) | |
if not os.path.exists(output_dir): | |
os.makedirs(output_dir) | |
# Construct the FFmpeg command | |
ffmpeg_command = [ | |
'ffmpeg', '-i', input_video, '-i', input_audio, | |
'-codec', 'copy', output_file | |
] | |
# Run the FFmpeg command | |
subprocess.call(ffmpeg_command) | |
# Copy the corresponding .ass file | |
subtitle_file = os.path.join(folder, file.replace('.mkv', '.ass')) | |
if os.path.exists(subtitle_file): | |
output_subtitle = os.path.join(output_path, os.path.relpath(subtitle_file, root_folder)) | |
output_subtitle_dir = os.path.dirname(output_subtitle) | |
if not os.path.exists(output_subtitle_dir): | |
os.makedirs(output_subtitle_dir) | |
shutil.copy(subtitle_file, output_subtitle) | |
print("Conversion and copying completed.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment