makemkvcon, BD backup, and seamless branching discs [SOLVED]

Discussion of advanced MakeMKV functionality, expert mode, conversion profiles
Post Reply
ectospasm
Posts: 5
Joined: Wed Aug 21, 2013 3:24 am

makemkvcon, BD backup, and seamless branching discs [SOLVED]

Post by ectospasm »

SOLVED: I changed the HandbrakeCLI flags from "--input $1/BDMV/STREAM/$LARGE" to "--input $1", and added "--main-feature", and now it converts the seamless BD rips accordingly. The relevant part of my convert script, as modified (see original post below)

Code: Select all

      HandBrakeCLI \
  --input "$1" \
  --output "$1/${1}.$TYPE" \
  --main-feature \
  --min-duration 1800 \
  --encoder x264 \
  --quality 20.0 \
  --audio 1,1 \
  --aencoder lame,copy:ac3 \
  --ab 160,160 \
  --mixdown dpl2,auto \
  --arate Auto,Auto \
  --drc 0.0,0.0 \
  --audio-copy-mask aac,ac3,dtshd,dts,mp3 \
  --audio-fallback ffac3 \
  --format $TYPE \
  --large-file \
  --decomb \
  --loose-anamorphic \
  --modulus 2 \
  --x264-preset medium \
  --h264-profile high \
  --h264-level 4.1

ORIGINAL POST:
I've been using a process for quite some time, and it usually works quite well. I rip a BD with makemkvcon, making a full-fat backup to a directory on my NAS. I play these files on my Raspberry Pi running OpenELEC with XBMC. Sadly, I cannot play the full M2TS files on the RPi due to its rather limited network bandwidth and RAM. My solution is to grab the largest M2TS file and transcode it to MKV using HandbrakeCLI. This works great, except for seamless branching discs.

Unfortunately these "seamless branching discs" (a new term for me), present a challenge. If I grab the largest M2TS file, that will be a significant chunk of the movie, but always somewhere in the middle of it. I need to refine my process so I get full-length titles from my BDs regardless of whether they're (what I call) "standard," or one of these seamless discs.

Just to document my scripts:

filename: rip

Code: Select all

!/bin/bash

MAKEMKVCON=/usr/bin/makemkvcon
TITLE=$1
#BDROM=/dev/sr0
BDROM=0
MKVOPTS="--messages=-stdout --progress=-stdout --directio=true --decrypt --robot"

echo MAKEMKVCON=$MAKEMKVCON
echo MKVOPTS=$MKVOPTS
echo TITLE=$TITLE
echo BDROM=$BDROM

echo $MAKEMKVCON \
  $MKVOPTS \
  backup \
  disc:$BDROM \
  "$TITLE"

$MAKEMKVCON \
  $MKVOPTS \
  backup \
  disc:$BDROM \
  "$TITLE"
filename: convert

Code: Select all

#!/bin/bash


# Get options
TEMP=$(getopt --options id: --long ios,dir --name 'bd_convert' -- "$@")
[ $? != 0 ] && echo "Invalid options..." >&2 && \
               echo "Usage:  $0 [-i|-m] [<BD directory>]" >&2 && \
               echo " -i|--ios  encode MP4 container" >&2 && \
               echo " -m|--mkv  encode MKV container (default)" >&2 && \
               echo " -d|--dir  convert only specified directory (not all)" >&2 && \
               #echo " -b|--both        (default) encode both types" >&2 && \
               exit 1


eval set -- "$TEMP"

IOS=0 # 0: mkv, 1: mp4, 2: both

while true;
do
  case "$1" in
    -i|--ios) IOS=1; shift ;;
    -m|--mkv) IOS=0; shift ;;
    #-b|--both) IOS=2; shift ;;
                -d|--dir) DIR=$2; shift; shift ;;
    --) shift; break ;;
    *) echo "Internal option parsing error!" >&2 && exit 127 ;;
  esac
done


if [ $IOS -eq 1 ];
then
  echo "Processing for IOS (MP4)..."
  TYPE="mp4"
elif [ $IOS -eq 2 ];
then
  echo "Processing for both IOS and MKV..."
else
  echo "Processing MKV"
  TYPE="mkv"                                                                                                                                                                   
fi

convert () {
  echo "DEBUG:  Processing '${1}'" >&2

  # Test if current file is a directory.  If not, skip to next file.
  [ -d "$1" ] || continue;

  #echo "DEBUG:  We have a directory in '$1'..." >&2

  # Test whether the current directory has a BDMV subdirectory.  If not, print
  # nonstandard directory name for manual processing, and skip to next file
  if [ -d "$1/BDMV" ];
  then

    #echo "DEBUG:  We have a full BD rip in '$1'..." >&2
    # Test whether the current directory has already been converted.  If so, skip
    # to next.
    if [ ! -f "$1/${1}.$TYPE" ]
    then
      # If we're here, we can begin processing
      echo "DEBUG:  We will process '$1'" >&2;

      # Find largest file in $1/BDMV
      LARGE=$(ls --size "$1/BDMV/STREAM" |
              sort -n |
              tail -n 1 |
              awk '{print $2}')
      echo "$1/BDMV/STREAM/$LARGE will be converted." >&2

      # Actually process the file:
      HandBrakeCLI \
        --input "$1/BDMV/STREAM/$LARGE" \
        --output "$1/${1}.$TYPE" \
        --encoder x264 \
        --quality 20.0 \
        --audio 1,1 \
        --aencoder lame,copy:ac3 \
        --ab 160,160 \
        --mixdown dpl2,auto \
        --arate Auto,Auto \
        --drc 0.0,0.0 \
        --audio-copy-mask aac,ac3,dtshd,dts,mp3 \
        --audio-fallback ffac3 \
        --format mkv \
        --large-file \
        --decomb \
        --loose-anamorphic \
        --modulus 2 \
        --x264-preset medium \
        --h264-profile high \
        --h264-level 4.1

    else
      echo "'$1' has already been converted." >&2 && continue;
    fi

  else
    echo "'$1' is not a full BD rip." >&2 && continue;
  fi
}

if [ -z "$DIR" ];
then
        DIR=*
        for dir in $DIR;
        do
                convert "$dir";
        done
else
                convert "$DIR"
fi
These scripts are not pretty, and they're mainly there so I don't have to look up how to do this every time and so my media is consistent. They are designed to run from the directory containing my BD media, so if you wanted to make these general purpose you'd have to alter them.

I would kill for an in depth guide for using makemkvcon. The incomplete documentation I've found is insufficient (all of it's not even in the same place!). I would also kill for an makemkv specific IRC channel. If it's somewhere, it isn't on Freenode.
Last edited by ectospasm on Wed Apr 02, 2014 12:43 pm, edited 1 time in total.
Romansh
Posts: 873
Joined: Sat Jan 22, 2011 7:09 pm

Re: makemkvcon, BD backup, and seamless branching discs

Post by Romansh »

Code: Select all

HandBrakeCLI --input $1 --main-feature
OR

Code: Select all

HandBrakeCLI --input $1 --title $whatever
Currently, HandBrake's Blu-ray main feature detection is limited to the longest title, so it may fail on a regular basis.
ectospasm
Posts: 5
Joined: Wed Aug 21, 2013 3:24 am

Re: makemkvcon, BD backup, and seamless branching discs

Post by ectospasm »

Romansh
Romansh wrote:

Code: Select all

HandBrakeCLI --input $1 --main-feature
OR

Code: Select all

HandBrakeCLI --input $1 --title $whatever
Currently, HandBrake's Blu-ray main feature detection is limited to the longest title, so it may fail on a regular basis.
Thanks for giving me a hint on HandBrake. I was really looking for help with seamless discs and makemkvcon, since the one I'm trying to rip (Iron Man 2) doesn't seem to have the entire feature in one M2TS file. I'd like to make a complete backup ("backup" command of makemkvcon) of the disc. If there's a better way to do it, I would love to try that instead.
Romansh
Posts: 873
Joined: Sat Jan 22, 2011 7:09 pm

Re: makemkvcon, BD backup, and seamless branching discs

Post by Romansh »

I guess it was too subtle, sorry.

I wrote:

Code: Select all

--input $1
instead of

Code: Select all

--input "$1/BDMV/STREAM/$LARGE"
on purpose. HandBrake can handle seamless branching discs too.
ectospasm
Posts: 5
Joined: Wed Aug 21, 2013 3:24 am

Re: makemkvcon, BD backup, and seamless branching discs

Post by ectospasm »

@Romansh: Thanks, I got it to work. I also added the --main-feature flag, and HandBrakeCLI just grabs the main feature.
Post Reply