How to convert 50 episodes from DVD into 50 .mp4 with HandBrake, easily?

12

7

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

Posted 2012-02-27T12:35:15.430

Reputation: 1 073

Answers

12

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

Posted 2012-02-27T12:35:15.430

Reputation: 1 196

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 – 2013-02-25T15:10:59.380

1GUI 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 – 2013-02-26T22:18:28.407

$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 – 2013-02-26T22:25:03.497

Not sure what else you want to know. Ask something specific and I'll answer. – Grilse – 2013-02-26T22:26:50.623

Thanks, now i understand it better. So its all about just commandline parameters, I can do that! – Rookie – 2013-02-27T15:13:34.300

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 – 2013-02-28T09:29:47.703

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

ForestPhoenix

Posted 2012-02-27T12:35:15.430

Reputation: 31

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 – 2017-03-24T22:09:47.790

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.

#!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}"')

Jean-Francois T.

Posted 2012-02-27T12:35:15.430

Reputation: 428

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}')

kpfroemel

Posted 2012-02-27T12:35:15.430

Reputation: 1

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 – 2017-08-19T23:28:50.433

@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. – 2018-07-19T07:38:04.317

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.

patty@patty:~$ for i in `seq 4`; do HandBrakeCLI -i /media/patty/DVDTITLE -t $i -o DVDTITLE_Title$i.mp4 -e x264 -q 18; done

mark bower

Posted 2012-02-27T12:35:15.430

Reputation: 1

-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

Posted 2012-02-27T12:35:15.430

Reputation: 2 034

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 – 2012-02-27T20:46:56.993