extracting segment map and other items to text file

Discussion of advanced MakeMKV functionality, expert mode, conversion profiles
Post Reply
dhylton
Posts: 4
Joined: Wed Jun 17, 2015 4:00 pm

extracting segment map and other items to text file

Post by dhylton » Sat Sep 17, 2016 8:54 pm

when selecting a given title on a blu-ray disc, the info box shows a bunch of related information. i'd like to be able to extract this information - particularly the segment map and file name - to a text file without having to copy/paste from the gui. and scripting this from the command-line would be a plus. one of the main reasons for this is that some of my discs have hundreds of titles, so doing this any other way is extremely tedious. examples of what i'd like to be able to extract:

Segment map: 514,517,503,512,501,520,506,515,504,502,511,508,519,510,505,518,513,507,509,516
File name: XXXXXX_t11.mkv

is there a way to script this from the command-line?

dhylton
Posts: 4
Joined: Wed Jun 17, 2015 4:00 pm

Re: extracting segment map and other items to text file

Post by dhylton » Tue Sep 20, 2016 3:58 pm

just in case anybody else cares ... after finding mention of makemkvcon elsewhere in the forums, i came up with a really quick/dirty workflow ...

the following just automates pulling the information out of the bluray backup; this is a shell function and is likely to work on any *nix as long as the MAKEMKVCON variable is pointed to the correct location:

Code: Select all

function makemkvinfo {
  # from https://www.makemkv.com/forum2/viewtopic.php?f=1&t=7680#p42661
  MAKEMKVCON=~/MyApps/DVD/MakeMKV*app/Contents/MacOS/makemkvcon
  test -d "$1" || { echo usage: makemkvinfo bluray-backup-folder ; return 1 ; }
  ${MAKEMKVCON} --noscan -r info file:"$1" > "`echo ${1} | tr -d '/'`.txt"
}
what follows is the first draft proof of concept for providing the wanted output ... it's certainly not done, but i've used it on two backups with 300+ titles each and it shaved my working time down to around 5 minutes per backup. it is extremely inefficient as-is, but was successful as a POC so i'll work on making it smarter and adding a couple of command-line arguments that make my particular workflow quicker. this is written in python and therefore should work on any *nix (and windows with some work).

Code: Select all

#!/usr/bin/env python

interestingvalues="""
  # from https://www.makemkv.com/forum2/viewtopic.php?f=1&t=7680#p42661
  ap_iaChapterCount=8,
  ap_iaDuration=9,
  ap_iaSegmentsMap=26,
  ap_iaOutputFileName=27,
"""

import re
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("inputfile", help="bd description file containing output from makemkvcon -r info", type=argparse.FileType('rU'))
parser.add_argument("-c", "--chapters", help="correct number of chapters")
parser.add_argument("-d", "--duration", help="correct duration in the form of HH:MM:SS (eg. 01:23:45)")
parser.add_argument("-s", "--segmap", help="partial segment map (eg. 315,321,431)")
args = parser.parse_args()

fullmatch = re.compile('TINFO:(?P<title>\d+),8,0,"(?P<numchapters>\d+)".+?TINFO:(?P=title),9,0,"(?P<duration>[\d:]+)".+?TINFO:(?P=title),16,0,"(?P<playlist>\d+?.mpls)".+?TINFO:(?P=title),26,0,"(?P<segmap>[\d,]+)".+?TINFO:(?P=title),27,0,"(?P<outputfile>.+?mkv)"', re.DOTALL)

output = []

content = args.inputfile.read()

for t in fullmatch.findall(content):
    title,chaps,duration,playlist,segmap,outputfile = t
    if args.chapters:
        if chaps != args.chapters:
            continue
    if args.duration:
        if args.duration not in duration:
            continue
    if args.segmap:
        if not segmap.startswith(args.segmap):
            continue

    output.append('%s -- %s -- %s -- %s -- %s -- %s' % (duration, chaps, segmap, playlist, outputfile, title))

output.sort()
for line in output: print(line)
if anyone else cares i may post updates to the script as i make them. regardless, i'm thankful for the forum and what i've learned from it.
Last edited by dhylton on Tue Sep 20, 2016 5:37 pm, edited 1 time in total.

dhylton
Posts: 4
Joined: Wed Jun 17, 2015 4:00 pm

Re: extracting segment map and other items to text file

Post by dhylton » Tue Sep 20, 2016 4:21 pm

is there a way to extract the chapter lists (eg. chapter 2 starts at 00:05:09) from the titles using makemkvcon? or another related utility?

preserve
Posts: 746
Joined: Sun Sep 13, 2015 10:21 pm
Location: Canada

Re: extracting segment map and other items to text file

Post by preserve » Wed Jan 04, 2017 2:10 am

I'm not on a *nix system, so it would be SO awesome if all data that MakeMKV has to process anyway in order to display it - list of titles with video length and codec, list of chapters, list of audio tracks and subtitle tracks, and any disc/title metadata - could be dumped by MakeMKV to a text file.
Using: ASUS BW-16D1HT 3.00

Post Reply