Tutorial: Direct Blu-Ray playback with IINA.app

The place to discuss Mac OS X version of MakeMKV
Post Reply
trimblebrev
Posts: 1
Joined: Tue Dec 14, 2021 12:42 pm

Tutorial: Direct Blu-Ray playback with IINA.app

Post by trimblebrev »

IINA is a feature-rich modern media player for macOS that in my own experience runs way more smoothly and reliably than VLC but unfortunately doesn't have the same MakeMKV app integration as off now. After reading up on this thread the other day I felt tempered to try archiving Blu Ray playback with libmmdb.dylib manually and succeeded! Be aware that menus are not supported by IINA and you'll only be able to play the main title.

NOTE: I've tried to write this guide as failsafe as possible. I assume no knowledge in handling the terminal and compiling code, it should be easy to follow if you just follow step-by-step and copy each command. Terminal commands need to be copied, pasted and executed line-by-line, not the whole block. Should you run into trouble trying to replicate this guide anyway, don't feel afraid to ask.


1. Replace libbluray.dylib
First I stumbled on this thread reporting a change in libbluray's source code that broke on-the-fly decryption in Kodi. From what I can tell, this also seems to be present in IINA's version of libbluray in use today so I've tried to edit the source code in the same way and recompiled libbluray to replace the version found in IINA.

First download and unpack the latest version of libbluray (1.3.0 at time of writing) of the source code into your Downloads folder.
Open the terminal and open libbluray-master/src/libbluray/disc/bdplus.c in nano.

Code: Select all

nano ~/Downloads/libbluray-1.3.0/src/libbluray/disc/bdplus.c
Replace lines 219 to 237 containing the following script:

Code: Select all

    if (set_fopen) {
        /* New libbdplus. Use libbluray for file I/O */
        p->bdplus = bdplus_init(NULL, NULL, vid);
        set_fopen(p->bdplus, file_open_handle, file_open_fp);
    } else if (root) {
        /* Old libbdplus or libmmbd. Disc is mounted. */
        p->bdplus = bdplus_init(root, NULL, vid);
    } else if (device) {
        /* Unmounted device */
        if (p->impl_id == IMPL_LIBMMBD && !strncmp(device, "/dev/", 5)) {
            char *tmp = str_printf("dev:%s", device);
            if (tmp) {
                p->bdplus = bdplus_init(tmp, NULL, vid);
                X_FREE(tmp);
            }
        } else {
            BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Too old libbdplus detected. Disc must be mounted first.\n");
        }
    }
With just this one line of code:

Code: Select all

   p->bdplus = bdplus_init(NULL, NULL, vid);
Press Ctl+O to save and then Ctrl+S to exit nano.
If you don't feel comfortable editing files using the terminal you can also just manually replace the code using Notepad.app

Next we need to compile libbluray.dylib ourselves.
The easiest way to take care of all dependencies is by installing and using Homebrew.
If you haven't installed Homebrew already, you can just use the following command:

Code: Select all

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Use Homebrew to install all the dependencies we need to compile libbluray

Code: Select all

brew install fontconfig freetype2 libxml12 ant git pkg-config openjdk
Now it's time to compile libbluray from the source code we changed

Code: Select all

cd ~/Downloads/libbluray-1.3.0/
./configure --prefix=/usr/local/Cellar/libbluray/1.3.0 --disable-bdjava-jar   
make
sudo make install
Lastly, we link our compiled libraries to /usr/local/lib/ and replace the version in the IINA package as well.
The first two commands are unnecessary if links in /usr/local/lib/ already exist, but it won't hurt either.

Code: Select all

ln -sf /usr/local/Cellar/libbluray/1.3.0/lib/libbluray.2.dylib /usr/local/lib/libbluray.2.dylib
ln -sf /usr/local/Cellar/libbluray/1.3.0/lib/libbluray.2.dylib /usr/local/lib/libbluray.dylib
ln -sf /usr/local/Cellar/libbluray/1.3.0/lib/libbluray.2.dylib /Applications/IINA.app/Contents/Frameworks/libbluray.dylib  
ln -sf /usr/local/Cellar/libbluray/1.3.0/lib/libbluray.2.dylib /Applications/IINA.app/Contents/Frameworks/libbluray.2.dylib
If the last two commands get you a "no such file or directory" error, IINA might only be installed for you and not all users. Try this instead:
The first two commands are unnecessary if links in /usr/local/lib/ already exist, but it won't hurt either.

Code: Select all

ln -sf /usr/local/Cellar/libbluray/1.3.0/lib/libbluray.2.dylib ~/Applications/IINA.app/Contents/Frameworks/libbluray.dylib  
ln -sf /usr/local/Cellar/libbluray/1.3.0/lib/libbluray.2.dylib ~/Applications/IINA.app/Contents/Frameworks/libbluray.2.dylib

2. Symlink libmmbd from MakeMKV to IINA and System Files
It should go without saying that MakeMKV needs to be installed for this step as it provides the libmmbd library. We create some symlinks to the library into the system folder and for good measure also directly into IINA.app's frameworks folder to grant access, that should do the trick.

Code: Select all

ln -sf /Applications/MakeMKV.app/Contents/lib/libmmbd_new.dylib /Applications/IINA.app/Contents/Frameworks/libaacs.dylib
ln -sf /Applications/MakeMKV.app/Contents/lib/libmmbd_new.dylib /Applications/IINA.app/Contents/Frameworks/libbdplus.dylib
If the last two commands get you a "no such file or directory" error, IINA and MakeMKV might only be installed for you and not all users. Try this instead:

Code: Select all

ln -sf ~/Applications/MakeMKV.app/Contents/lib/libmmbd_new.dylib ~/Applications/IINA.app/Contents/Frameworks/libaacs.dylib
ln -sf ~/Applications/MakeMKV.app/Contents/lib/libmmbd_new.dylib ~/Applications/IINA.app/Contents/Frameworks/libbdplus.dylib




Congrats, you should now be able to play Blu Ray discs directly within IINA!
Simply open the app and then open finder, click on the name of your mac and drag-and-drop the disk showing up there in IINA.
You may need to wait a few seconds before the disks content is fully recognized depending on the speed of your drive, just be patient.

A few notes:
  • Initially a few of my discs had problems loading up. I'm not sure what caused this and I haven't seen it in a while, but usually trying to skip to the next title of the disc solved the problem. Try this if your disc doesn't load up after a few seconds.
  • If you're reading this in the far-away future where 1.3.0 isn't the latest version of libbluray anymore, replace any instance of 1.3.0 in the provided commands with the current version number. This might or might not work depending on future version changes but that's the first thing I'd try.
Post Reply