15

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
  • 1,223
  • 9
  • 28
  • 48

7 Answers7

16

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"
}
Jean-Francois T.
  • 620
  • 2
  • 7
  • 19
Grilse
  • 3,435
  • 3
  • 17
  • 14
  • Isnt 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? – Rookie Feb 25 '13 at 15:10
  • 2
    GUI 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 Feb 26 '13 at 22:18
  • $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 Feb 26 '13 at 22:25
  • Not sure what else you want to know. Ask something specific and I'll answer. – Grilse Feb 26 '13 at 22:26
  • Thanks, now i understand it better. So its all about just commandline parameters, I can do that! – Rookie Feb 27 '13 at 15:13
  • You're welcome. Remember to upvote answers/comments if you think they are useful, and to accept an answer if it solved your problem! – Grilse Feb 28 '13 at 09:29
3

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
  • It'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. – Kaithar Mar 24 '17 at 22:09
2

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:

  1. You need Handbrake CLI (currently available at this address: https://handbrake.fr/downloads2.php)
  2. 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}"')

Jean-Francois T.
  • 620
  • 2
  • 7
  • 19
0

The line count=$(echo $rawout | grep -Eao "\\+ title [0-9]+:" | wc -l) from @ForestPhoenix does not work when the first chapter is smaller than 10 seconds.

This is an improvement of the code:

rohausgabe=$(HandBrakeCLI -i "$iso" -t 0 2>&1 >/dev/null)
anzahl=$(echo $rohausgabe | grep -Eao "scan: DVD has [0-9]" | awk -F " " '{print $4}')
Jean-Francois T.
  • 620
  • 2
  • 7
  • 19
  • 1
    Welcome to Superuser. Please take the tour at https://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" – SDsolar Aug 19 '17 at 23:28
  • @SDsolar: I tried to translate as this answer was constructive. I stopped studying German 14 years ago so I hope I did not mistranslated :) – Jean-Francois T. Jul 19 '18 at 07:38
0

Extracting the files in Linux Ubuntu via the CLI worked great. The line I used below repeats the syntax given with a little amplification to force MPEG-4 and quality. If subtitles are needed, I believe the command line (CLI) parameters and arguments would need to be expanded.

for i in `seq 4`; do HandBrakeCLI -i /media/patty/DVDTITLE -t $i -o DVDTITLE_Title$i.mp4 -e x264 -q 18; done
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
-1
    for ($title=1; $title -le 4; $title++) {
    &"C:\Program Files\HandBrake\HandBrakeCLI.exe" --input "source\sourceVideo.mp4" --title $title -e x264 -o "destination\$title.mp4"
}

This is based on @Grilse answer, whose code is now obsolete.

  • 1
    Welcome 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. – DavidPostill Apr 10 '20 at 07:49
-1

You can add the tasks to the queue

From Link 2

Just go ahead and change the title, chapter, or source in use, and be sure to rename the destination file. Tweak any settings you want. Then click the "Add to queue" button on the toolbar. Repeat these steps for the whole batch of videos you wish to convert.

Some of the comments say that they were having problems with overwriting the previous file. So you will have to be sure you name them properly. Make sure a few work before you leave it running.

sealz
  • 2,264
  • 2
  • 28
  • 41
  • adding 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 Feb 27 '12 at 20:46