Dark Light

I’m in the process of ripping some boxsets of DVDs to Plex, and I thought I should probably document the process. The most obvious thing I’m not using here is Handbrake, which works really well for some people, but I am not one of them.

Physical to Digital

MakeMKV turns any DVD or Bluray I’ve thrown at it into an MKV file. The one thing it could do to make my life better would be custom tags on filenames, but the default {Directory}\{DVD Identifier}\title{nn}.mkv  is good enough. {DVD Identifier} is annoyingly unspecific most of the time, and sometimes within disks of the same box set (The thing I’m currently ripping has both WW_S4_T5_D3 and WESTWING_S4_D6 in it, as discs 1 and 6 respectively), so the next stage is to make those directory names consistent. It doesn’t matter what they are, so long as when I “ls” the directory, they are in the right order. Then, I run this:

export COUNT=1; # Start at 1
find . -name \*mkv \ # Find all files ending MKV
	| while read fle;\ # For each of those (as variable $fle)
		do mv $fle $(printf "The_West_Wing-S04E%0.2d.mkv" $COUNT);\ # Increment the filename
		COUNT=$(($COUNT + 1));\ # Add one to the filename count
	done

Note: You’ll need to collapse that back into a single line without the comments for it to work:

export COUNT=1; find . -name \*mkv \| while read fle; do echo mv $fle $(printf "The_West_Wing-S04E%0.2d.mkv" $COUNT);COUNT=$(($COUNT + 1)); done

This gives me a directory of well-named MKV files.

Digital to MP4

Plex is happier with mp4 encoded videos than with MKV files, though, plus they’re smaller without a noticable (to me) drop in quality, so when I’ve got a few series of these built up, I’ll run this overnight:

for fle in mkv/*.mkv; do encode.sh $fle; done

Where encode.sh looks like this:

#!/bin/bash
file=$1
ffmpeg -i $file -codec:v libx264 -profile:v high -preset ultrafast -crf 16 -minrate 30M -maxrate 30M -bufsize 15M -metadata:s:a:0 language=eng -c:a ac3 -b:a 384k -threads 2 ${file%.*}.mp4

Which is a standard ffmpeg encode line, the only real weirdness being the ${file%.*}.mp4 bashism, which basically turns the $file variable from “Foobar.mkv” into “Foobar.mp4” (It will also turn “Foo.bar.mkv” into “Foo.mp4” though, so be careful)

MP4 to Mediacentre

Once that’s finished, I’ll get rid of the mkv files, and send them into Plex. To ensure consistency of my filenames and also get any subtitle files I need, this is done using filebot, like this:

filebot -script fn:amc --output "/media/mediashare" --log-file amc.log --action move --conflict skip -non-strict --def music=y subtitles=en artwork=y --def "seriesFormat=TV Boxsets/{n}/{'S'+s}/{s00e00} - {t}" "animeFormat=Anime/{n}/{fn}" "movieFormat=Movies/{n} {y}/{fn}" "musicFormat=Music/{n}/{fn}" --def plex=localhost .

(Filebot, rename using the (included) automediacentre script. Output to directories below my media drive mount, log to amc.log, move (don’t copy) the files, if it already exists skip it. Don’t do strict checking, download music, search for subtitles, get series artwork, send TV shows to the “TV Boxsets” directory in {Series Name}/S{Series Number}/s{Series number}e{Episode Number} – {Episode Title} format. Anime should go somewhere else, Movies somewhere else, Music somewhere else, then notify plex on the local machine. Do this on the current directory)

Operating System Notes

None of this is OS specific. Filebot, FFMPEG Plex & MakeMKV are available – and work identically – on Windows, Mac & Linux. The various bash scripts could be adapted to powershell, but I’d instead recommend Babun, which is a repackaging of cygwin with a far nicer interface and package management system that’ll give you the basic *nix commandline tools on your windows machine (all of the above up to MP4 to Mediacentre runs on my beast-sized windows gaming rig, to avoid making the puny media centre CPU cry too much)

2 comments
  1. I think you’ve got a stray backslash after the find invocation in your one-line renaming script. I’m also not convinced find reliably does the depth-first alphabetically-sorted traversal you depend on, but that’s probably just me being paranoid about find. More people should be!

    1. Yup, I should fix that.

      As for Find not being reliable, it’s certainly something I check first before I run without a safety harness, but it does appear to do depth-first reliably on the platforms I’ve tried it. If not, a pipe though sort will fix it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts