Adding my little grain of salt, this is the Python script I came up with to split into several chapters. The number is extracted automagically.
Note that:
- You need Handbrake CLI (currently available at this address: https://handbrake.fr/downloads2.php)
- You need to have the installation folder of Handbrake CLI in your PATH
You just need to call the following Python script with the location of DVD as the argument of the script (something like python episodes_splitter.py "path of my folder").
import os
import re
import subprocess
import sys
Ugly but simple way to get first argument = folder with DVD
We will get DVD name by removing all / and \
dvd = sys.argv[1]
dvd_name = re.sub(r'.*[/\]', '', dvd).rstrip('/').rstrip('\')
s = subprocess.Popen(
['HandBrakeCLI', '-i', dvd, '-t', '0'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if not s.stdout:
print(f'ERROR: Could not open "{dvd}"!')
sys.exit(1)
count = 0
for line in s.stdout:
if re.search(rb"+ title [0-9]+:", line):
count += 1
print(f'==Extracting {count} chapters from "{dvd}"==')
for i in range(1, count+1):
output = f"{dvd_name}{i}.mp4"
cmd = ['HandBrakeCLI', '--input', dvd, '--title', str(i), '--preset', 'Normal', '--output', output]
log = f"encoding{output}.log"
with open(log, 'wb') as f:
s = subprocess.Popen(cmd, stdout=f, stderr=subprocess.STDOUT)
s.communicate()
if not os.path.isfile(output):
print(f'ERROR during extraction of "{output}"!')
else:
print(f'Successfully extracted Chapter #{i} to "{output}"')