[Script] convert episodes or main-feature from DVD or BD or convert multiple files (on any os)

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.
mortenfirst
Posts: 7
Joined: Sun Dec 21, 2014 8:56 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by mortenfirst »

I can't use the latest version, I have to use this version because om some other compability problems - so that is not an option.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Then create just the plist-file with the newest version.
mortenfirst
Posts: 7
Joined: Sun Dec 21, 2014 8:56 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by mortenfirst »

Thats also a problem - because the new versions of HandBrake have the x264 presets - my version does not :-)
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Can you explain, why you have to use a version without x264 presets?
mortenfirst
Posts: 7
Joined: Sun Dec 21, 2014 8:56 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by mortenfirst »

This is the only version precompiled for my Debian kernel 3.16. I have tried compiling the newest, but it does not work.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Have you tried one of this packages?
https://packages.debian.org/search?keyw ... dbrake-cli
mortenfirst
Posts: 7
Joined: Sun Dec 21, 2014 8:56 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by mortenfirst »

Yes, but my kernel is backported, so I also have an old version of handbrake.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Ok, then it's maybe time for a kernel update. :-)
But I think you can set your settings in hb.rb at least with the --xtra argument
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

Hi,

Well this script is exactly what I've been looking for! However, I'm trying to figure out how to do multiple tracks with it. I'm the sort of person who likes audio commentaries, so I'd like to add those to the ripped file. However, I'm drawing a blank as to how.

I'd prefer to do a direct copy on the primary audio track, then re-encode the commentary to aac, 96Kb/s, stereo. Reading the help suggests I specify the audio options twice, as there's an example which re-encodes the primary track, then copies a secondary, but I can't make it work as it just seems to ignore it and only copy the primary.

I pre-ripped the DVD using dvdbackup to a directory.

I'm doing all of this on Ubuntu 14.10, 64-bit. Handbrake 0.10 is installed from the ppa on the Handbrake site.

This is what I'm doing:

Code: Select all

ruby hb.rb --input /data/SOURCE-DVD/ --out "/data/Ripping/Target_#pos#.mkv" --episodes ---audio-track encoder=copy --audio-track encoder=av_aac,mixdown=stereo,bitrate=96 --subtitles=eng
Handbrake does identify the original source as containing two tracks (AC3 5.1 and AC3 Stereo), but says the target just contains AC3 5.1.

Any suggestions most gratefully received!
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Adding a copied and a reencoded track should work theoretically (maybe I've disabled this function accidentally in one of my last committs.
But this function will copy and reencode each audio track (also the primary). The main-goal for this function was to copy the oroginal audio track and create a mixdown track for older devices.

The reason why you get only one track in your output is that you use --episodes because this sets also only-first-track-per-language.

In your case I would suggest something like this
ruby hb.rb --input /data/SOURCE-DVD/ --output "/data/Ripping/#title#_#pos#.mkv" --lang=eng --audio-copy --min-length 00:10:00 --max-length 00:50:00 --skip-duplicates
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

Well, there we go. I simply substituted the --episodes switch for --min-length 00:10:00 --max-length 00:50:00, and it now appears to be encoding a file exactly as I want.

Edit: Just finished the encode, and it appears to have just copied everything instead. So it seems it only honours the first encoder option.

Tried this, too, and ended up with two copied tracks.

Code: Select all

ruby hb.rb --input /data/SOURCE/ --out "/data/Ripping/Target_#pos#.mkv" --min-length 00:10:00 --max-length 00:50:00 --lang=eng --audio-copy --audio-track encoder=av_aac,mixdown=stereo,bitrate=128 --subtitles=eng
Seems the audio-track option gets ignored.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

You should substitute --episodes at least with -lang=eng --min-length 00:10:00 --max-length 00:50:00 --skip-duplicates
If you want to create a copy and an encoded audio track you could try to remove the break in lib/hb_lib.rb line 1092
https://github.com/AlBundy33/hb_rb/blob ... b.rb#L1092
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

That doesn't seem to work either. The command it's passing through is this:

Code: Select all

"/usr/bin/HandBrakeCLI" --input "/data/SOURCE" --output "/data/Ripping/Target_S1_04.mkv" --encoder x264 --quality 20.0 --decomb --detelecine --crop 0:0:0:0 --loose-anamorphic --format mkv --markers --title 4 --audio 1,1,2,2 --aencoder copy,av_aac,copy,av_aac --mixdown auto,stereo,auto,stereo --ab auto,128,auto,128 --drc 0.0,0.0,0.0,0.0 --aname "English (AC3) (5.1 ch)","English (Stereo)","English (AC3) (Director's Commentary 1) (2.0 ch)","English (Director's Commentary 1) (Stereo)" --audio-fallback lame --subtitle 1,7  2>/dev/null
It's doing this:

Code: Select all

[2014-12-30, 22:38:02]  WARN -- hb.rb:   audio-tracks
[2014-12-30, 22:38:02]  WARN -- hb.rb:     - track 1: English (AC3) (5.1 ch) - Auto Passthru
[2014-12-30, 22:38:02]  WARN -- hb.rb:     - track 1: English (Stereo) - AAC (avcodec)
[2014-12-30, 22:38:02]  WARN -- hb.rb:     - track 2: English (AC3) (Director's Commentary 1) (2.0 ch) - Auto Passthru
[2014-12-30, 22:38:02]  WARN -- hb.rb:     - track 2: English (Director's Commentary 1) (Stereo) - AAC (avcodec)
So it's sort of what I want, but not entirely.

Interestingly, the edit isn't on line 1092 for me. It's line 1106. I'd originally downloaded the zip linked from the first post in this thread, so I figured I'd checkout from github and try again, but the same thing.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

It was line 1092 in the linked commit - maybe it's now 1106.

Your output looks fine - the output contains the primary and commentary track as copy and reencoded.
This is the wanted behavior.
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

Hmm, I'm expecting to have two tracks in the output - 5.1 original copy (or whatever the primary is), and the commentary just re-encoded to aac, nothing else. It suggests it's putting four tracks in. I'll let it encode and see what I get.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Each --audio-track will be applied to each found audio track.
So in your case you'll get 4 audio tracks in output.

If you only want 2 tracks you can:
a) copy the generated commandline and change it to your needs
b) simply remove your encoder settings - so the commentary will be copied too

I would prefer the last one.
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

Aaah I see. I may have to just live with it not re-encoding the secondary track then. Probably won't use vastly more space, to be honest.

Well thanks, it's an excellent script and exactly what I was gearing up to write anyway. I'm going to play more with profiles and things as I found I need to treat different media differently, so I'll probably come up with some sort of wrapper script to apply different profiles depending on which directory the source files are dropped in. That's the plan, at least.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

You can already define presets for my script.
These are my presets: https://github.com/AlBundy33/hb_rb/blob ... hb.presets
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Btw there is an option c - you can define to reencode ac3 stereo only and copy all other tracks.
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

I appear to have just stumbled onto a solution, thanks to you mentioning profiles. Added a profile:

Code: Select all

[anim-com]
--audio
eng
--subtitles
eng
--audio-track
encoder=auto
--audio-settings
track=1,encoder=copy
--audio-settings
track=2,encoder=av_aac,mixdown=stereo,bitrate=96
It's regex to chose the tracks, so took a wild guess and whacked the track numbers in. I'm sure I can do something cleverer there.

Then used this command:

Code: Select all

ruby hb.rb --hbpreset anim-com --input /data/SOURCE/ --out "/data/Ripping/TARGET_S01_#pos#.mkv" --min-length 00:10:00  --max-length 00:50:00
Currently encoding a file with just two audio tracks. :)
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

You're right - it's a regex.
But you should really use a better regex because DTS 7.2 matches also 2.

I would suggest to use * instead of 1 (deafault settings) and Stereo instead of 2 so all tracks will be copied and stereo tracks reencoded (Commentary instead of 2 should also work)
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

Btw you can also add the length arguments to your preset and build presets hierarchicaly (see my sample).
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

The regex will need tightening definitely. This just proved the point.

I tried adding the length arguments (one per line) and it complained they were invalid. I'll play a little more tomorrow with the syntax because it's sounding like I can do a lot with the presets.
AlBundy
Bright Spark User
Posts: 377
Joined: Mon Dec 31, 2012 4:47 am

Re: [Script] rip episodes or main-feature from DVD or BD

Post by AlBundy »

You can do the same in the preset as hb.rb can do - the advantage is "only" that you don't have to remeber all arguments. :-)

In the presetfile each argument and each value has to be on it's own line (thats making parsing easier for me)
Works not
--min-length 00:10:00
--max-length 00:50:00

Works
--min-length
00:10:00
--max-length
00:50:00
KingDaveRa
Posts: 15
Joined: Tue Dec 30, 2014 9:12 pm

Re: [Script] rip episodes or main-feature from DVD or BD

Post by KingDaveRa »

Great, that's working now. Added it in.

I got this as a preset now, which I can call with a pretty simple commandline:

Code: Select all

[anim-com]
--audio
eng
--subtitles
eng
--audio-track
encoder=auto
--audio-settings
track=\[eng\],encoder=copy
--audio-settings
track=Director\'s Commentary,encoder=av_aac,mixdown=stereo,bitrate=96
--min-length
00:10:00
--max-length
00:50:00
I have to escape some things, but otherwise quite straight forward.

However, Track 1 is tricky to pick up, hence just looking for the english track. Is there an easy way to explicitly select 'track 1'? I could also do an 'or' with the regex to look for anything in DTS to pick that in preference, should it occur. The Director's Commentary seems to work OK for the couple of DVDs I'd tried, although I suspect they won't all be tagged as such, depending on how the DVD was authored, so I'll just have to see how that goes; I suspect in some cases it'll just be a stereo track.

As far as I can tell, in the case of what HB finds:

Code: Select all

[2014-12-31, 19:48:52]  WARN -- hb.rb:   audio-tracks
[2014-12-31, 19:48:52]  WARN -- hb.rb:     - track 1: [eng] English (AC3) (2.0 ch) (Dolby Surround)
[2014-12-31, 19:48:52]  WARN -- hb.rb:     - track 2: [eng] English (AC3) (Director's Commentary 1) (2.0 ch)
[2014-12-31, 19:48:52]  WARN -- hb.rb:   subtitles
[2014-12-31, 19:48:52]  WARN -- hb.rb:     - track 1: [eng] English
[2014-12-31, 19:48:52]  WARN -- hb.rb:     - track 2: [eng] English
I can only search the bits after "track 1:" as far as I can tell, because a search for "track 1" never seems to work. Is that right?

Also, found a typo:

[2014-12-31, 19:54:51] INFO -- hb.rb: skipping title because found to audio-tracks to add
Post Reply