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,243

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"
}
Grilse
  • 3,793
  • 3
  • 19
  • 14
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
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}"')

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}')
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
  • 58,727
-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

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,334