[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.
AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Wed Dec 31, 2014 8:43 pm

You could try this (untested)

Code: Select all

[anim-com]
--audio
eng
--subtitles
eng
--audio-track
encoder=auto
--audio-settings
track=*,encoder=copy
--audio-settings
track=(Commentary|Stereo) ,encoder=av_aac,mixdown=stereo,bitrate=96
--min-length
00:10:00
--max-length
00:50:00
Means: if no specific setting found, copy the track (*) or reencode commentary and stereo tracks.

If you want to match a specific track number you can try ^1\. (^ = start of description, followed by a one, followed by a dot)

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Wed Dec 31, 2014 8:48 pm

The regex is tested against the audio tracks description

Code: Select all

    def to_s
      "#{pos}. #{descr} (codec=#{codec}, channels=#{channels}, lang=#{lang}, comment=#{comment}, rate=#{rate}, bitrate=#{bitrate}, commentary=#{commentary?()})"
    end

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 » Wed Dec 31, 2014 10:14 pm

Thanks for that. OK, this works on a DVD with commentaries on some tracks, or on all tracks:

Code: Select all

--audio-settings
track=1\.,encoder=copy
--audio-settings
track=Commentary,encoder=av_aac,mixdown=stereo,bitrate=96
The caret stopped it working, but the dot needs escaping all the same. However, on a DVD with no commentaries, I found only this works (and also works on the previous types):

Code: Select all

[anim-com]
--audio
eng
--subtitles
eng
--audio-track
encoder=auto
--audio-settings
track=Commentary,encoder=av_aac,mixdown=stereo,bitrate=96
--audio-settings
track=*,encoder=copy
--min-length
00:10:00
--max-length
00:50:00
So oddly, it seems doing it in reverse works best! I stripped it down to a single track matching on 1\. and ^1\., but it still won't pick up the primary track. The only difference is this DVD is 2.0 audio, whereas the others are 5.1.

Code: Select all

[2014-12-31, 21:53:15]  INFO -- hb.rb: checking audio-track 1. English (AC3) (5.1 ch) (codec=AC3, channels=5.1 ch, lang=eng, comment=, rate=48000Hz, bitrate=448000bps, commentary=false)
[2014-12-31, 21:53:15]  INFO -- hb.rb: checking audio-track 2. English (AC3) (Director's Commentary 1) (2.0 ch) (codec=AC3, channels=2.0 ch, lang=eng, comment=Director's Commentary 1, rate=48000Hz, bitrate=192000bps, commentary=true)


[2014-12-31, 21:59:13]  INFO -- hb.rb: checking audio-track 1. English (AC3) (2.0 ch) (codec=AC3, channels=2.0 ch, lang=eng, comment=, rate=48000Hz, bitrate=192000bps, commentary=false)
It's different, but it's not what I'm searching for.

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 » Wed Dec 31, 2014 10:14 pm

Thanks for that. OK, this works on a DVD with commentaries on some tracks, or on all tracks:

Code: Select all

--audio-settings
track=1\.,encoder=copy
--audio-settings
track=Commentary,encoder=av_aac,mixdown=stereo,bitrate=96
The caret stopped it working, but the dot needs escaping all the same. However, on a DVD with no commentaries, I found only this works (and also works on the previous types):

Code: Select all

[anim-com]
--audio
eng
--subtitles
eng
--audio-track
encoder=auto
--audio-settings
track=Commentary,encoder=av_aac,mixdown=stereo,bitrate=96
--audio-settings
track=*,encoder=copy
--min-length
00:10:00
--max-length
00:50:00
So oddly, it seems doing it in reverse works best! I stripped it down to a single track matching on 1\. and ^1\., but it still won't pick up the primary track. The only difference is this DVD is 2.0 audio, whereas the others are 5.1.

Code: Select all

[2014-12-31, 21:53:15]  INFO -- hb.rb: checking audio-track 1. English (AC3) (5.1 ch) (codec=AC3, channels=5.1 ch, lang=eng, comment=, rate=48000Hz, bitrate=448000bps, commentary=false)
[2014-12-31, 21:53:15]  INFO -- hb.rb: checking audio-track 2. English (AC3) (Director's Commentary 1) (2.0 ch) (codec=AC3, channels=2.0 ch, lang=eng, comment=Director's Commentary 1, rate=48000Hz, bitrate=192000bps, commentary=true)


[2014-12-31, 21:59:13]  INFO -- hb.rb: checking audio-track 1. English (AC3) (2.0 ch) (codec=AC3, channels=2.0 ch, lang=eng, comment=, rate=48000Hz, bitrate=192000bps, commentary=false)
It's different, but it's not what I'm searching for.

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Wed Dec 31, 2014 11:35 pm

Maybe

Code: Select all

^1[.].*
works to match the first track.

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Wed Dec 31, 2014 11:39 pm

I've rechecked - the pattern must match the description

Code: Select all

 def descr(remove_codec = false, remove_channels = false)
      d = @descr.dup
      d.gsub!(/\s*[(]?#{codec}[)]?/, "") if remove_codec
      d.gsub!(/\s*[(]?#{channels}[)]?/, "") if remove_channels
      d.strip!
      return d
    end
Maybe I'll change this in the next version.

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Wed Dec 31, 2014 11:43 pm

You can try this
Search in lib/hb_lib.rb for the string
t.descr.match(s["track"])
and replace it with
t.to_s.match(s["track"])

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 » Thu Jan 01, 2015 12:28 am

OK, made that change. That's pretty simple, and it gives me all the power now. :D

So I've got this: It's a work in progress but it's matching a LOT more reliably.

Code: Select all

[anim-com]
--audio
eng
--subtitles
eng
--audio-track
encoder=auto
--audio-settings
track=^1[.].*,encoder=copy
--audio-settings
track=(?=^(?![1\.]))(?=.*commentary=true)(?=.*Commentary).*,encoder=av_aac,mixdown=stereo,bitrate=96
--min-length
00:10:00
--max-length
00:50:00
So I'm looking explicitly for track 1, and copying that, then looking for anything that *isn't* track one, but is a commentary, then doing an encode. I've got a couple of dvds which present themselves thusly:

Code: Select all

[2015-01-01, 00:27:45]  WARN -- hb.rb:   audio-tracks
[2015-01-01, 00:27:45]  WARN -- hb.rb:     - track 1: [eng] English (AC3) (2.0 ch)
[2015-01-01, 00:27:45]  WARN -- hb.rb:     - track 2: [eng] English (AC3) (2.0 ch)
[2015-01-01, 00:27:45]  WARN -- hb.rb:     - track 3: [eng] English (AC3) (2.0 ch)
I may just have to admit defeat and re-encode those. Some are multiple commentaries, whilst some are stereo mixes of the main track, or Audio Described. It's a bit of a mish-mash really.

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Thu Jan 01, 2015 12:59 am

commentary=true and check for Commentaty is the same because commentary is only true if the description contains Commentary. :-)

Glad to hear that it works now.
TO DO for me: remove the break and match against to_s

The script is for "default szenarios" and tries to provide as much information as possible.
Sorry that it didn't work for all of your DVDs. ;-)

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 » Thu Jan 01, 2015 1:08 am

commentary=true and check for Commentaty is the same because commentary is only true if the description contains Commentary. :-)
Haha! There's always a simpler answer.... Oh well!

Still, this gives me a lot of flexibility.

Thing is, I found when I was trying to do similar things with the HandbrakeGUI, it would do some really funky things depending on the source DVD. There's no consistency between DVDs. The ones I'm testing with are from various sources, and they're all different, so it's very hard to make a one-size fits all. That said, I think I've got something that is pretty good in that it'll cover a lot of bases. I'll obviously have to do some custom ones for special cases, but that's OK.

Thanks for all the help. This is a really great script. :D

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Thu Jan 01, 2015 1:24 am

You're welcome.
Btw.: happy new year ;-)

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 » Thu Jan 01, 2015 1:39 am

Happy new year to you too. 8)

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Fri Jan 02, 2015 8:51 pm

I've updated my files - I've removed the break-statement and changed t.descr to t.to_s to match tracks.
If you run with --verbose you'll set the output of to_s in the audio-track-listing.

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 » Fri Jan 02, 2015 10:29 pm

I tried it with and without the break, and it didn't seem to make much difference. I think it's running with it, right now.

I'll test more thoroughly soon, I probably won't get much chance to play around with it again until Sunday at the earliest.

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Sun Jan 18, 2015 5:00 pm

Did the last version work for you?

Al

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 » Sun Jan 18, 2015 7:17 pm

Weirdly, I was just staring at the machine I was running all this on, thinking 'I should try that again soon'. I'm so sorry, I've not had chance to get back to it yet. Been meaning to but just not found time I'm afraid. Hopefully I'll take a look in the next couple of days. In the brief testing I did do, however, it did seem to be working.

virgilfox
Posts: 6
Joined: Fri Jan 23, 2015 1:07 pm

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

Post by virgilfox » Fri Jan 23, 2015 1:11 pm

Love this script! Is there a way to block subtitles without also blocking the commentary track from the encoded file?

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Fri Jan 23, 2015 1:27 pm

Simply set --subtitles none

Al

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Thu Mar 19, 2015 7:18 pm

i've uploaded a new version.
Some users reported that encoding with hb_rb did not start - reason was that the modification time of the file was in future.
Therefore a warning is now logged, if my script waits for a "future-file". :-)

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Thu Jul 02, 2015 6:04 pm

Just out of curiosity, does someone use my script together with own scripts?
Maybe I can add those features to my script. :-)

nhyone
Bright Spark User
Posts: 215
Joined: Fri Jul 24, 2015 4:13 am

Re: Mass convert folder full of .ISO files

Post by nhyone » Tue Sep 01, 2015 12:18 am

Code: Select all

for %f in (*.iso) do HandBrakeCLI --input %f --output %~nf.mkv --preset <preset>
Not-interrupt safe -- it always starts from the first file. If you want something interrupt-safe, you need to skip if the output files already exist.

Trogburn
Posts: 4
Joined: Sat Sep 19, 2015 10:16 pm

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

Post by Trogburn » Sun Sep 20, 2015 3:11 am

First off, thanks OP for the awesome script, and obviously all the hard work on this project! Many props to you and this forums/group of members for looking into improving this idea.

For everyone on here, I have always been a 'custom is better' type of guy... so I tend to work outside the lane of the normal presets in handbrake, and optimize quite a bit for encoding. Using a few different resources I have built a template that works well except for a few final details that I can't seem to get to work right inside the script, and I am wondering if the community can help me on (and maybe you can benefit from my script as well? :D ).

I have not figured out how to get the DRC or GAIN to work correctly for the Audio Track. During the encode the DRC always shows up for the Audio Track as --drc 0.0 and the GAIN does not show up as all. I have tried putting both of these tags outside the --xtra section, and I have tried putting them both inside the --xtra section as well, but neither seems to work. Anyone get these to work? Also, if anyone is curious, I have provided some very helpful resources (links) at the bottom of this post that should shed some light at how I arrived at some of my custom settings.

So here is what I have so far.

For NON-DISNEY / OLDER-STYLE ANIMATION SPECIFIC MOVIES (in other words, everything else besides older animations + disney type movies), I use the following:

Code: Select all

hb.rb --input "H:\TEST\*\*.mkv" --main --titles 1 --output "I:\MOVIES (FS - Rips & Re-encodes)\#source_parentname#\#source_basename#.mkv" --autocrop --no-loose-anamorphic --skip-commentaries --quality 20 --decomb --detelecine --only-first-track-per-language --audio-track encoder=av_aac,mixdown=stereo,language=eng,arate=auto,bitrate=320 --xtra "-f mkv -e x264 --drc 2.5 --gain 3.0 --vfr -x level=4.1:no-fast-pskip:ref=4:bframes=8:b-adapt=2:direct=auto:me=umh:subme=10:merange=24:analyse=all:trellis=2:psy-rd=1.0,0.15:no-dct-decimate=1:deblock=-1,-1:vbv-bufsize=13000:vbv-maxrate=13000:crf=21:rc-lookahead=50 --verbose=1"
For DISNEY / OLDER-STYLE ANIMATION SPECIFIC MOVIES, I use the following:

Code: Select all

hb.rb --input "H:\TEST\*\*.mkv" --main --titles 1 --output "I:\MOVIES (FS - Rips & Re-encodes)\#source_parentname#\#source_basename#.mkv" --autocrop --no-loose-anamorphic --skip-commentaries --quality 20 --decomb --detelecine --only-first-track-per-language --audio-track encoder=av_aac,mixdown=stereo,language=eng,arate=auto,bitrate=320 --drc 2.5 --gain 3.0 --xtra "-f mkv -e x264 --vfr -x level=4.1:no-fast-pskip:ref=4:bframes=8:b-adapt=2:direct=auto:me=umh:subme=10:merange=24:analyse=all:trellis=2:psy-rd=0.4,0.00:no-dct-decimate=1:deblock=1,1:vbv-bufsize=13000:vbv-maxrate=13000:crf=21:rc-lookahead=50 --verbose=1"

Image

Helpful Resources / Links:
https://mattgadient.com/2012/06/25/a-ru ... ngs-0-9-6/
https://mattgadient.com/2013/06/12/a-be ... ake-0-9-9/
https://mattgadient.com/2013/06/20/comp ... -examples/

Hope some of this information helps someone!

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Sun Sep 20, 2015 12:16 pm

drc and gain is part of your command.
The first drc with 0.0 comes as default from my script - the second one is yours.

Trogburn
Posts: 4
Joined: Sat Sep 19, 2015 10:16 pm

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

Post by Trogburn » Sun Sep 20, 2015 3:24 pm

AlBundy wrote:drc and gain is part of your command.
The first drc with 0.0 comes as default from my script - the second one is yours.
Then i guess the real question is: Does my DRC setting override your default DRC setting in your script? If not, how do I reconfigure your DRC setting your script?

Also, what about the GAIN setting? Is there a way to do that in your script?

Is there a way to verify both settings are working correctly?

AlBundy
Bright Spark User
Posts: 370
Joined: Mon Dec 31, 2012 4:47 am

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

Post by AlBundy » Sun Sep 20, 2015 3:33 pm

I hope that your drc overrides my default because your value will be added later in command line.
You could try an encode with 0 and another with a very high value and compare the results.
so, what about the GAIN setting? Is there a way to do that in your script?
What do you mean with that?

Al

Post Reply