Batch convert ripped DVDs with HandbrakeCLI on Windows

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
gerardwr
Posts: 5
Joined: Thu Apr 17, 2008 9:51 am

Batch convert ripped DVDs with HandbrakeCLI on Windows

Post by gerardwr »

Hi,

I have been looking here for a way to convert al my ripped DVD's to an Ipod format on my Windows XP computer, but could not find anything suitable.

That's why I have created the "simple" BATCH file below that runs on a standard Windows XP installation. Perhaps this is of some use and/or inspiration to some of you.

Code: Select all

set INDIR=\My DVDs\
set OUTDIR=\My Ipod files\
set PRESET=iPod Low-Rez
set EXTRA=--markers --native-language nld -v

for /d /r "%INDIR%" %%i in (.) do if exist "%%~fi\video_ts." if NOT exist "%OUTDIR%%%~ni %PRESET%.m4v" TITLE Handbrake "%%~ni" preset "%PRESET%" & "handbrakecli" -i "%%~fi" -o "%OUTDIR%%%~ni %PRESET%.m4v" -Z "%PRESET%" %EXTRA% 2>>hb.log
The code:
- uses HandbrakeCLI to convert all VIDEO_TS directories (in the directory indicated by INDIR) into a .M4V file using the preset named in PRESET. EXTRA may contain "overrides" or additions to the built-in preset.
- places the .M4V files in the directory indicated by OUTDIR. Name of the .M4V files is the same as the name of the directory in INDIR thats contains the VIDEO_TS directory.
- skips the conversion of a VIDEO_TS directory if the .M4V file was already created in an earlier run.
- displays the currently converted DVD in the TITLE of the window
- logs the HandbrakeCLI output to file hb.log (read it with Wordpad)

Make sure the BATCH file is placed in a directory that also contains HandbrakeCLI.exe and cyg1win.dll. The version I use is 0.9.2.

Have fun, but as always : Use at you own risk.
Daerid
Posts: 2
Joined: Wed Apr 16, 2008 10:30 pm

Re: Batch convert ripped DVDs with HandbrakeCLI on Windows

Post by Daerid »

It's been years since I had to look at a script, would you be willing to help?

Situation:
I currently have 3 1TB drives with .iso files in them (X:\, Y:\, and Z:\)

I want to take these .iso files and convert them to Xbox360 format on a different drive (M:\). My plan is to make my own On-Demand Media Center setup with multiple 360s at each TV in the house.

How would I convert your script to do this?

Thanks!!

~Daerid
JBSil
Posts: 9
Joined: Mon Mar 17, 2008 4:23 pm

Re: Batch convert ripped DVDs with HandbrakeCLI on Windows

Post by JBSil »

I've written a similar script, before finding yours posted here, and it seems you will likely have the same problem that I do: Not specifying which Title of the DVD to use (-t 4) will cause HBCLI to default to using Title 1. While this is usually the correct title, some DVDs put their actual movie in some other title, like 4 or 15 or whatever the heck they feel like using. Do you or does anyone else know of a way to have the HBCLI automatically choose the right title, just like the HBGUI does?

-t auto has it scan all of the titles, which I imagine is used for the GUI, but it also causes the CLI to exit once it's done scanning, i.e. before any encoding is done. Any suggestions?

Edit: Now that I finally found the CLI guide, the answer is quite obvious: -L for longest title.
kabsoft
Posts: 1
Joined: Mon Jun 29, 2009 3:56 pm

Re: Batch convert ripped DVDs with HandbrakeCLI on Windows

Post by kabsoft »

here's my contirbution ...a simple XP script to process each ISO in a folder

Code: Select all

PATH=%PATH%;"C:\Program Files\Handbrake"
FOR  %%I IN ("D:\ISOs\*.ISO") DO if NOT exist "D:\MKVs\%%~nI (H264).mkv" HandBrakeCLI -i "%%~fI" -o "D:\MKVs\%%~nI (H264).mkv" -L -f mkv -m -p -e x264 -q 0.6 -a 1 -E ac3 -B 192 -R auto -6 auto -F -x ref=3:mixed-refs:bframes=3:b-pyramid:weightb:filter=-2,-1:trellis=1:analyse=all:8x8dct:me=umh:subme=9:psy-rd=1,1
exit
PATH - tells the system where to find the CLI
FOR - loops through each ISO not already processed in D:\ISOs calling the CLI to convert each to MKV/X264 with the output created in D:\MKVs

The CLI parameters are those that I'm using for ripped movies at the moment picking out the longest title (-L) and a CRF of 60% (-q 0.6) which seems fine for me but may not suit your purposes. For testing add parameters to only process 1 chapter of the title (-c 1)unless you've got all week when processing many ISOs.

Feedback and suggestions on the script and parameters welcome.
snu3
Posts: 1
Joined: Sat Aug 01, 2009 9:31 am

Re: Batch convert ripped DVDs with HandbrakeCLI on Windows

Post by snu3 »


thank you kind people for posting your code : )

here's a variation for converting MULTIPLE TITLES from a ripped DVD ...

Code: Select all

@echo off
REM # HandbrakeCLI Batch Conversion (Windows Batch File)
REM # will search all subfolders for \VIDEO_TS , then convert up to 20 titles per folder

REM # --------------------------------------------------------------------------
REM # change these settings to suit what you're converting
REM # when testing, set chapters to '-c 1-1' to save time

set INPDIR=C:\Users\Sue\Videos\DVDfab\FullDisc\
set OUTDIR=C:\Users\Sue\Videos\Handbrake\
set PGMDIR=C:\Program Files\Handbrake\
set Tracks=(1,1,20)
set Chapters=
set PRESET=NORMAL
set FileExt=avi                            
set EXTRA=-f avi --crop 0:0:0:0 -p -e xvid -q 0.9 -a 1 -E lame -B 160 -R 0 -6 dpl2 -D 1 -v

REM # --------------------------------------------------------------------------
for /d /r "%INPDIR%" %%i in (.) do if exist "%%~fi\VIDEO_TS." for /l %%t in %Tracks% do if not exist "%OUTDIR%%%~ni-%%t %PRESET%.%FileExt%" 
TITLE Handbrake Source=%%~ni Track=%%t & ECHO. & ECHO *Source* %%~fi\VIDEO_TS *Title* %%t & "%PGMDIR%\HandbrakeCLI" -i "%%~fi" -t %%t 
%Chapters% -o "%OUTDIR%%%~ni-%%t %PRESET%.%FileExt%" -Z "%PRESET%" %EXTRA% 2>>%OUTDIR%convert.log

echo *Finished*
jfnewell
Posts: 4
Joined: Fri Aug 28, 2009 6:19 pm

Re: Batch convert ripped DVDs with HandbrakeCLI on Windows

Post by jfnewell »

I created this simple batch to search out .iso files in the specific folder and subfolder. Before converting any iso it checks to see if there is already an mkv file in the destination folder. If so, it skips that iso allowing you to quit the batch and restart it later. I did notice that handbrake doesnt remove partial converted files so make sure to do that yourself if you quit while one is in progress. With this quality level and default settings (not really tested all that much) it takes about 30-40 minutes to convert a 5GB .iso that contains just the main movie...


PATH=%PATH%;"c:\program files (x86)\handbrake2\"
For /r z:\library\movies %%i in (*.iso) do if NOT exist "z:\library\convert\%%~ni.mkv" HandBrakeCLI.exe -i "%%i" -t 1 -o "z:\library\convert\%%~ni.mkv" -f mkv -m -p -9 -e x264 -q 0.65 -a 1 -E ac3 -B 160 -R 0 -6 dpl2 -D 1 -x ref=2:bframes=2:me=umh -v

modified the above script to pipe to a txt (log file) to save in temporary conversion folder. After I've verified the mkv file is good I can move it to my library and leave the log file in the conversion folder without taking up extra diskspace. Leaving the log file will allow my script to continue to pick up unconverted .iso files while still allowing me to leave any iso files around that I want to keep.

PATH=%PATH%;"c:\program files (x86)\handbrake2\"
SET SOURCE=Z:\library\movies\
SET DEST=Z:\library\convert\

For /r %source% %%1 in (*.iso) do if NOT exist "%dest%%%~n1.txt" HandBrakeCLI.exe -i "%%1" -t 1 -o "%dest%%%~n1.mkv" -f mkv -m -p -9 -e x264 -q 0.65 -a 1 -E ac3 -B 160 -R 0 -6 dpl2 -D 1 -x ref=2:bframes=2:me=umh -v > "%dest%%%~n1.txt"

The only thing that would be nice is to be able to add to this script to rename the iso files with the folder name from the source...example.

source is %source%\movie title (year)\undesirable name.iso

desired target and name would be %dest%\movie title (year).mkv

anybody got any great ideas floating around?
Post Reply