How to convert 50 episodes from DVD into 50 .mp4 with HandBrake, easily?
Solution 1
You can write a shell script to invoke HandBrakeCLI for each title.
Linux (source):
$ for i in `seq 4`; do HandBrakeCLI --input /dev/dvd --title $i --preset Normal --output NameOfDisc_Title$i.mp4; done
Windows PowerShell:
for ($title=1; $title -le 4; $title++) {
&"C:\program files\handbrake\HandBrakeCLI.exe" --input D:\ --title $title --preset Normal --output "$title.mp4"
}
Solution 2
Based on the Answer from Grilse:
This script does not use a fixed number of titles, but lets handbrake determine them.
#!/bin/bash
rawout=$(HandBrakeCLI -i /dev/dvd -t 0 2>&1 >/dev/null)
#read handbrake's stderr into variable
count=$(echo $rawout | grep -Eao "\\+ title [0-9]+:" | wc -l)
#parse the variable using grep to get the count
for i in $(seq $count)
do
HandBrakeCLI --input /dev/dvd --title $i --preset Normal --output $i.mp4
done
Solution 3
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.
#!python
import os
import subprocess
import re
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'.*[/\\]', r'', dvd).rstrip('/').rstrip('\\')
s = subprocess.Popen(
f'HandBrakeCLI -i "{dvd}" -t 0', stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
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 = f'HandBrakeCLI --input {dvd} --title {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}"')
Related videos on Youtube
Rookie
Updated on September 18, 2022Comments
-
Rookie almost 2 years
I loaded a DVD with 50 episodes in it (chose VIDEO_TS from the program), now when i open it in HandBrake, it shows 50 "titles" in there. i choose 320x240 output format and start converting. Then i click to next title, do same again, 50 times.
Is there any way to speed this up?, because it doesnt remember my settings when i click the next title. and i tried to make preset but it crashes every time i choose it from the presets list.
-
Rookie over 12 yearsadding to queue doesnt remove the problem of repetition: i need to click to select next title, change resolution, click "add queue", repeat. what i want is to simply convert all titles at once with exact same settings. this seems to be possible only for chapters
-
Rookie over 11 yearsIsnt there any gui options for this? about that windows script example; what do i do if the $title isnt a number? im not sure what that code does. care to explain?
-
Grilse over 11 yearsGUI option: yes there is: Add to queue -> Add all. However, it's marked as (Experimental) and it didn't work when I tried it.
-
Grilse over 11 years$title not a number: $title will always be a number. That's how DVD's work. Explanation: well, it's a for-loop that counts from 1 through 4, and for each count, it executes HandBrakeCLI.exe with some parameters. Check out "HandBrakeCLI.exe --help" to see what the parameters mean.
-
Grilse over 11 yearsNot sure what else you want to know. Ask something specific and I'll answer.
-
Rookie over 11 yearsThanks, now i understand it better. So its all about just commandline parameters, I can do that!
-
Grilse over 11 yearsYou're welcome. Remember to upvote answers/comments if you think they are useful, and to accept an answer if it solved your problem!
-
Kaithar over 7 yearsIt's worth noting that if you want that count value to be right you'll need to pass --min-duration 0 to HandBrakeCLI, otherwise you'll come up short on some DVDs. For example, my test DVD has a 10 second track 1 that will be ignored in the final output.
-
SDsolar almost 7 yearsWelcome to Superuser. Please take the tour at superuser.com/Tour to get the most out of this site. As to this answer, I suggest that when the question is in English, can you please answer in English? I see that after that first command you wrote --> does not work when the first items are less than 10 sec.! Then you showed what is "Better"
-
Jean-Francois T. almost 6 years@SDsolar: I tried to translate as this answer was constructive. I stopped studying German 14 years ago so I hope I did not mistranslated :)
-
DavidPostill about 4 yearsWelcome to Super User! While this may answer the question, it would be a better answer if you could provide some explanation why it does so.