Batch Converting TV Show DVDs

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
e3opian
Posts: 5
Joined: Fri Jul 17, 2009 6:59 pm

Batch Converting TV Show DVDs

Post by e3opian »

Any of you command line guys find a solution for TV show discs, or other discs with multiple titles? My standard script is just like most of yours using the -L argument to return the longest title. But, for TV show discs there might be 5 or 6 titles that need to be ripped for each episode.

A FOR loop to iterate through and encode each title would work (later deleting the non-episode titles), but we need a way to return the total number of titles. I'm a little stuck on this one...

-Aaron
rhester
Veteran User
Posts: 2888
Joined: Tue Apr 18, 2006 10:24 pm

Re: Batch Converting TV Show DVDs

Post by rhester »

-t 0 will return a title scan, from which you could use a bit of logic to derive the title list you want to convert (avoiding very short titles, etc).

I suspect, however, you may be reinventing the wheel here. This has been explored by various users many times already.

Rodney
e3opian
Posts: 5
Joined: Fri Jul 17, 2009 6:59 pm

Re: Batch Converting TV Show DVDs

Post by e3opian »

Thanks for pointing me in the right direction. I've been doing plenty of reading but had not come across this, yet.

Cheers,
Aaron
gminnick
Posts: 23
Joined: Thu May 07, 2009 7:49 pm

Re: Batch Converting TV Show DVDs

Post by gminnick »

Here is what I do. It takes a little setup but works for me.

First I Decrypt a season of DVDs into a folder naming them <show name>_SxDy (where x is the season number and y is the disk number)
I will use Stargate SG1 Season 1 as my example

I use SG1_S1D1 for season 1 disc 1

I then create a .txt file with 4 columns like this. One of my main reasons for doing it this way was to have the episode title. When I viewed this after entering and submitting, the tabs show up as single spaces between columns so it may be hard to read. If you use excel you will get tabs showing more space.


Episode# Title# Folder Episode name <--- Do not put this line in your txt file. This is just to show you what the columns mean.

01 1 SG1_S1D1 Children of the Gods
02 2 SG1_S1D1 The Enemy Within
03 3 SG1_S1D1 Emancipation
04 1 SG1_S1D2 The Broca Divide
05 2 SG1_S1D2 The First Commandment
06 3 SG1_S1D2 Brief Candle
07 4 SG1_S1D2 Cold Lazarus
08 5 SG1_S1D2 Thor's Hammer
09 1 SG1_S1D3 The Torment of Tantalus
10 2 SG1_S1D3 Bloodlines
11 3 SG1_S1D3 Fire and Water
12 4 SG1_S1D3 The Nox
13 5 SG1_S1D3 Hathor
14 1 SG1_S1D4 Cor-Ai
15 2 SG1_S1D4 Singularity
16 3 SG1_S1D4 Enigma
17 4 SG1_S1D4 Tin Man
18 5 SG1_S1D4 Solitudes
19 1 SG1_S1D5 There But for the Grace of God
20 2 SG1_S1D5 Politics (1)
21 3 SG1_S1D5 Within the Serpent's Grasp (2)



If you are good with Excel you can create this file pretty quickly. I used tv.com to get a list view of episodes and then do some cut and paste. If you find a site that has plain text it would work much better. I have not looked for one yet. Be careful though. It seems some DVDs don't have episodes in the same order as places like tv.com. I am guessing one may use production order and another air date order which sometimes are not the same. I had this problem with SG-1.


Name this file sg1s1.txt

Then I create a file called sg1s1.bat and put this in it

Code: Select all

for /f "tokens=1,2,3*" %%1 in (sg1s1.txt) do HandBrakeCLI -i "D:\VideoTemp\%%3" -t %%2 -o "E:\Videos\Stargate SG-1\Season 1\Stargate SG-1-S01E%%1-%%4.mp4" -f mp4 --crop 0:0:0:0 --decomb -p -e x264 -b 1100 -2 -T -a 1 -E faac -B 128 -R 48 -6 dpl2 -D 1 --markers -x ref=3:mixed-refs=1:bframes=6:weightb=1:direct=auto:me=umh:subq=9:analyse=all:trellis=1:no-fast-pskip=1:psy-rd=1,1 -v 
Then I run it. You will want to edit for settings you prefer and for your input and output folders. Both the .txt file and .bat file should be in a folder with HandbrakeCLI.exe

These settings were for the older 0.9.3. I have not updated for 0.9.4 but I think this will give you an idea. The for command is one of the best DOS utilities I use at work for automating things. In the for comman the %%1, %%2, %%3 and %%4 represent the data in the 4 columns in your text file. You can add more data to your .txt file and change the for command to match. I put the title at the end because it is the one element that has spaces and I use spaces as the default delimeter so the "tokens=1,2,3*" means to make %%1 = column 1, %%2 = column 2, %%3 = column 3 and %%4 = everything past 3 (represent by *).

If you type in the for command at a command line instead of a batch file, you have to use %1, %2, %3 and %4. In batch you have to double up the %.

This works for me since most TV shows will have the same setting. However, if you have TV shows on DVD that were on the air during transition times (ie: standard to widescreen or stereo to 5.1 audio) then you will want to scan the DVDs and see when that change took place. I wrote a VBscript that just parses the scan log of handbrake. I will post it below. You may have to edit for your own paths.

It basicly list all the subfolders in the folder you specify in set objFolder. These subfolders would be the folder you create when decrypting your DVD that has your VIDEO_TS folder.
Then you select the folder you want to scan by choosing the number
It will use the -t 0 option in Handbrake to create a tmp file hbtmpscan.txt and then it will scan that file and just output the number of titles found and each title with the duration, size, PAR, DAR, FPS and audio tracks. I just use that to see if the DAR or audio has changed between titles.

You have to run this using cscript (ie: cscript hbscan.vbs) if you name the file hbscan.vbs

Code: Select all

Set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = wscript.createObject("wscript.shell")
set objFolder = objFSO.GetFolder("d:\videotemp")
set colSubfolders=objFolder.Subfolders

dim arFolders(100)

For iCount = 1 to 5
	Wscript.Echo " "
Next

icount = 1
For Each objSubfolder in colSubFolders
	Wscript.Echo icount & " " & objSubfolder.Name
	arFolders(iCount) = objSubfolder.Name
	icount = icount + 1
Next


Wscript.Echo "Choose Which Folder to scan"
Selection = Wscript.STdIn.ReadLine

path = "d:\videotemp\" & arFolders(selection)

For iCount = 1 to 5
	Wscript.Echo " "
Next

iRC = objShell.Run("CMD /C handbrakecli.exe -i " & path & " -t0 > hbtmpscan.txt 2>&1", , True)

Set input = objFSO.OpenTextFile("hbtmpscan.txt", 1)


line = input.readline
do until InStr(line,"libhb: scan thread found")
	line = input.readline
loop

wscript.echo line

do while not input.atendofstream
	line = input.readline
	if InStr(line,"+ title") then
		WScript.echo Line
		line = input.readline
		do until InStr(line,"+ audio tracks:")
			if InStr(line,"size") then WScript.Echo line
			if InStr(line,"duration:") then WScript.Echo line
			line = input.readline
		loop
		WScript.Echo line
		line = input.readline
		do until InStr(line,"+ subtitle tracks:")
			wscript.echo line			
			line = input.readline
		loop
	end if
loop

input.close


Set objFSO = Nothing
set objShell = Nothing
set objFolder = Nothing
set colSubfolders = Noting

There may be better ways to do this, but as I said this works for me. I really wanted a way to have the season#, episode# and episode name quickly entered without having to go back and type them all in. You may have to customize this for your use. I did not write this with others in mind, but when I saw this post I thought I would share what I did. You may be able to make it even better.
e3opian
Posts: 5
Joined: Fri Jul 17, 2009 6:59 pm

Re: Batch Converting TV Show DVDs

Post by e3opian »

Thanks for sharing. That's really good stuff since I had not entirely solved my problem yet. :oops:

Ideally, I'd like to rip now / edit the episode names later approach but this might be the better way to go.
Post Reply