Answers:
您可以编写一个Shell脚本来为每个标题调用HandBrakeCLI。
Linux(源):
$ 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的回答:
该脚本不使用固定数量的标题,但可以通过手刹确定它们。
#!/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
加上一点点的盐,这是我想出的Python脚本,分为几章。该数字是自动提取的。
注意:
您只需要使用DVD的位置作为脚本的参数来调用以下Python脚本。
#!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}"')
该生产线count=$(echo $rawout | grep -Eao "\\+ title [0-9]+:" | wc -l)
从@ForestPhoenix当第一章是超过10秒小不起作用。
这是代码的改进:
rohausgabe=$(HandBrakeCLI -i "$iso" -t 0 2>&1 >/dev/null)
anzahl=$(echo $rohausgabe | grep -Eao "scan: DVD has [0-9]" | awk -F " " '{print $4}')