PDA

View Full Version : DVD to MKV using CLI


jdlk
1st September 2009, 12:47
As others in this forum have done, I'm about to start the rather scary task of ripping all my DVDs to my media server.

One thing I have learned over the years is that, unless I automate the process as much as possible, it will never happen. Which means developing a script that requires little or no human intervention.

So here's where I've reached: I rip the DVD to disk, ensuring the rip contains only one audio track and one subtitle track. Then I run the following script:

1. SET DGINDEX="C:\Program Files\megui\tools\dgindex\DGIndex.exe"
2. SET X264="C:\Program Files\x264\x264.exe"
3. SET MKVMERGE="C:\Program Files\MKVtoolnix\mkvmerge.exe"
4. SET HOME=C:\DVD_Convert
5. SET PGCDEMUX="C:\Program Files\PGCDemux\PgcDemux.exe"
6. SET SUBTITLECREATOR="C:\Program Files\SubtitleCreator\SubtitleCreator.exe"

7. FOR /D %%A IN ("%HOME%\*.* ") DO (
8. %PGCDEMUX% "%%A\VTS_01_0.IFO" %HOME%
9. REN "%HOME%\*.sup" index.sup
10. %SUBTITLECREATOR% %HOME%\index.sup -ven -aIndex.idx
11. DIR "%%A\*.VOB" /s/b > "%HOME%\filelist.lst"
12. %DGINDEX% -HIDE -IA=5 -FO=0 -OM=0 -YR=1 -DRC=0 -DSA=0 -BF=[%HOME%\filelist.lst] -OF=[%HOME%\index]
-AT=[C:\Program Files\AviSynth 2.5\templates\film with autocrop.avs] -EXIT
13. REN "%HOME%\*.ac3" index.ac3
14. %X264% --crf 21 --bframes 3 --sar 16:11 --weightb --subme 7 --ref 3 --me umh --mixed-refs --b-adapt 2
--vbv-maxrate 10000 --vbv-bufsize 10000 -o "%HOME%\video.264" %HOME%\Index.avs
15. %MKVMERGE% --output "%%~nA".mkv --title "%%~nA".mkv "%HOME%\video.264" %HOME%\index.ac3 %HOME%\Index.idx
--chapters "C:\chapters.txt"
16. REN %HOME%\LogFile.txt LogFile"%%~nA".txt
17. DEL "%HOME%\video.264" %HOME%\filelist.lst "%HOME%\index.ac3" %HOME%\Celltimes.txt %HOME%\index.avs
%HOME%\index.d2v %HOME%\Index.idx %HOME%\Index.sub %HOME%\*.sup "%HOME%\filelist.lst" AutoCrop.log
18. MOVE "%%A" "%HOMEPATH%\My Documents\Video\Finished VIDEO_TS folders"
19. MOVE "%%~nA".mkv "%HOMEPATH%\My Documents\Video\Finished MKV movies"
20. )


The AVS script is:
mpeg2source("__vid__")
AutoCrop(mode=3, wMultOf=4, hMultOf=4)
assumefps(25)


Chapters.txt just adds a chapter mark every five minutes. Different versions of the script are used for different SAR values.

The one thing I have not managed to automate is checking the VOBS to find out if a delay is reported -- I do open PCGDemux to check that manually. I'd like to add a line that says "if delay not equal to zero, put message on screen", but that's beyond my abilities.

I am considering changing the script to run the VOBs through Quickstream Fix in VideoRedo, which would sort out any sync issues, and then change the script to process the resulting MPG (while still taking the subtitles from the original VOBS). Any views on this?

I've run this script on two discs, and it's been successful on both, which is great. But my knowledge of scripting is dodgy and I'm new to using MKV, so I thought I'd ask the old hands in this forum to glance at the script if they have a moment, and tell me about any weaknesses they see. I'd be grateful for any views.

neuron2
1st September 2009, 13:45
The one thing I have not managed to automate is checking the VOBS to find out if a delay is reported You can use your AVS template to cause the delay to be automatically adjusted. Refer to the __del__ macro.

stax76
1st September 2009, 14:16
I've experience with batch processing and think you will run into lots of problems, I would just rip one every once in a while manually.

jdlk
1st September 2009, 16:30
You can use your AVS template to cause the delay to be automatically adjusted. Refer to the __del__ macro.
I wasn't aware of that. Thank you.

I've experience with batch processing and think you will run into lots of problems, I would just rip one every once in a while manually.
Thanks for the response. Are you saying that, no matter how comprehensive the script, there are simply too many variables in the process to be able to use a batch script, or are you saying my particular script is not yet up to the job?

stax76
1st September 2009, 17:17
More like too many variables and not using powerful enough tools, I would use StaxRip as it has batch automation support but if I had to write a script I would use a scripting or programming language like WSH JScript, PowerShell, Python, VB.NET console applications etc. because batch code is not suitable for this.

jdlk
1st September 2009, 21:05
More like too many variables and not using powerful enough tools, I would use StaxRip as it has batch automation support but if I had to write a script I would use a scripting or programming language like WSH JScript, PowerShell, Python, VB.NET console applications etc. because batch code is not suitable for this.
Would you mind elaborating on that? I'm struggling to work out what the GUIs such as StaxRip would achieve that a batch script would not (presuming that you take a quick look at each set of VOBs to establish SAR and framerate before you run the batch script).

stax76
1st September 2009, 22:53
Maybe it's not such a big deal and batch is not so bad, the d2v file contains if the DVD is anamorphic, maybe you find a way to automate detecting the --sar value for x264.

smok3
1st September 2009, 22:57
there could be only 4 possible sar values no (if we simplify stuff a bit)?

pal 4:3, pal 16:9, ntsc 4:3 and ntsc 16:9

other than parsin d2v, you could probably use mediainfo in similar fashion as this
http://forum.doom9.org/showthread.php?p=1308111#post1308111

TinTime
1st September 2009, 23:11
Chapters.txt just adds a chapter mark every five minutes.

A minor thought that you may or may not be interested in - if you want to retain the original chapters you can use ChapterXtractor (http://www.videohelp.com/tools/ChapterXtractor) to get these...

ChapterXtractor.exe "VTS_01_0.IFO" "chapters.txt" -p5 -t1

...and use this chapter file with mkvmerge.


EDIT: Just spotted another thing. When muxing a raw AVC stream with mkvmerge it assumes that the framerate is 25fps. Presumably the tests you've run successfully were with 25fps video so this didn't matter. Instead I'd use x264 to produce an mkv file as output, not a raw stream. Then you don't need to set the fps when muxing your final mkv.

jdlk
2nd September 2009, 03:03
@stax76 -- appreciate your feedback. I'll keep plugging away with the script and report back if it proves to be a waste of time.

@TinTime -- thanks. I've added ChapterXtractor to the script. Didn't realise it was so easy to extract the original chapters. Another step on the road to automation...

@smok3 -- I also took your advice and used Mediainfo to grab the aspect ratio.

Thanks all for your help.

For those interested, this is what I added to the script to use ChapterXtractor and MediaInfo:

EDIT: code removed -- MediaInfo code not working reliably yet...

roozhou
3rd September 2009, 10:40
Why don't you try mencoder? The sar could be automatically set.

stax76
3rd September 2009, 12:15
@roozhou

I guess it would not work with AviSynth but I think AviSynth wouldn't be needed here anyway.

jdlk
3rd September 2009, 14:56
I used to use Mencoder exclusively back in my XviD days, but when I started working with x264, I vaguely recall reading persuasive posts in this forum that suggested that Mencoder was not a good option, at that time, for x264/MP4/MKV. I may be wrong, or things might have changed in recent months...