sturmen
1st February 2024, 04:05
Introduction
This is the workflow I've been using to convert my 3D Blu-ray collection to Apple's new MV-HEVC codec. As of Feb 12, on the Apple Vision Pro these can only be played back in the native Files and Photos applications, but I am optimistic that other, more powerful player apps will be released in the coming months.
Hardware Used
Windows PC with a processor capable of decoding MVC (I believe this means an Intel processor that contains an iGPU that supports QuickSync Video)
Apple Silicon Mac
Blu-ray drive (MakeMKV-compatible)
Portable SSD with like 500+ GB of space (optional but recommended)
Software Used
MakeMKV (https://makemkv.com/)
FFmpeg (https://ffmpeg.org/)
FRIM Decoder (https://forum.doom9.org/showthread.php?t=169651)
SpatialMediaKit (https://github.com/sturmen/SpatialMediaKit)
MP4Box (https://github.com/gpac/gpac)
Steps
I recommend saving all files to an external SSD, and simply moving the drive between the computers at the section break.
Section 1: Windows
Rip your Blu-ray with MakeMKV. Make sure to include the stereo video track! It is unchecked by default and needs to be manually selected.
Use FFmpeg to extract the MVC bitstream and audio to separate files.
ffmpeg.exe -i 'Gravity_t00.mkv' -map 0:v -c:v copy -bsf:v h264_mp4toannexb "Gravity.h264" -map 0:a:0 -c:a pcm_s24le "Gravity_5.1_LPCM.mov"
Use FRIM Decode to split the MVC video track into left and right streams. This will take three separate PowerShell windows. Execute the commands in the following order in their own window:
FRIMDecode64.exe -i:mvc Gravity.h264 -o \\.\pipe\lefteye \\.\pipe\righteye
ffmpeg -f rawvideo -s 1920x1080 -r 23.976 -pix_fmt yuv420p -i \\.\pipe\lefteye -c:v libx265 -x265-params keyint=1:min-keyint=1:lossless=1 -vtag hvc1 -movflags +faststart Gravity_left.mov
ffmpeg -f rawvideo -s 1920x1080 -r 23.976 -pix_fmt yuv420p -i \\.\pipe\righteye -c:v libx265 -x265-params keyint=1:min-keyint=1:lossless=1 -vtag hvc1 -movflags +faststart Gravity_right.mov
Section 2: Mac
Combine left and right movies into an MV-HEVC stream.
spatial-media-kit-tool merge -l Gravity_left.mov -r Gravity_right.mov -q 50 --left-is-primary --horizontal-field-of-view 40 -o Gravity_MV-HEVC.mov
(Optional) Transcode the audio to AAC to save space.
ffmpeg -i Gravity_5.1_LPCM.mov -c:a libfdk_aac -b:a 384k Gravity_5.1_AAC.mov
Use MP4Box to remux the audio back into the MV-HEVC file.
mp4box -new -add Gravity_MV-HEVC.mov -add Gravity_5.1_AAC.mov Gravity_AVP.mov
Notes and Explanations, Presented in Q&A Format
Which eye is primary? This differs based on the source material. In FFmpeg, look at the input printout of the MKV file. You should see "stereo_mode" under Metadata. "block_lr" means left is primary, "block_rl" means right is primary.
What's a good quality value for -q? I don't actually have a good answer for this yet. q=50 is what Apple calls "medium quality" and it seems fine on my 5K Studio Display, but maybe compression artifacts will be glaringly obvious inside the Vision Pro. In my testing, q=50 yields about 2.5 GB per hour of 1080p stereoscopic video. Apple calls q=75 "high quality" and that yields approximately 4x bigger files, which are still about smaller than the size of the source H.264 MVC file.
Can this be done with only a Mac? I believe so: MakeMKV does support Macs, and I read about a tool called h264-tools (https://github.com/Vargol/h264-tools) that can decode the MVC stream into the separate files. I haven't used it though.
What if my film isn't 1080p at 23.976 fps? Change your FFmpeg commands accordingly. FRIMDecoder should print out the right resolution, dimension, and colorspace. (I420 is the same as yuv420p)
Why x265 lossless? I actually use hevc_nvenc lossless, but I didn't want this guide to rely on that. We don't want to use any lossy codecs until the very end, so that eliminates a bunch of codecs, and H.264/HEVC have the advantage of being directly readable by spatial-media-kit-tool, unlike other popular lossless codecs like FFV1 or HuffyYUV. And the final tiebreaker is: lossless H.264 doesn't play in QuickTime whereas HEVC does (useful for spot-checking), so HEVC is the winner.
Can spatial-media-kit-tool work on anything other than an Apple Silicon Mac? No. It's actually a pretty thin wrapper around the proper macOS APIs that actually do all the heavy lifting for encoding. We'll have to wait x265 to add MV-HEVC support before we'll see this on any other OS.
Why MOV containers? This is again driven by compatibility with the QuickTime framework, which spatial-media-kit-tool heavily relies on. The audio file will also carry through the original chapters from the original MKV into the final MP4box mux, which is nice.
Why libfdk_aac with a bitrate of 384 kbps? According to Wikipedia, 384 is "transparent" for 5.1. I've also encountered discs that have 7.1, where I figured 512 kbps ought to be enough. I use libfdk because it supports up to 7.1 channels. If you have 5.1, I recommend you try encoding with the aac_at encoder instead, as it's supposedly even better for the same bitrate.
Why MP4box for the final mux? FFmpeg does not preserve the MV-HEVC atoms. See the GitHub readme of SpatialMediaKit.
This is the workflow I've been using to convert my 3D Blu-ray collection to Apple's new MV-HEVC codec. As of Feb 12, on the Apple Vision Pro these can only be played back in the native Files and Photos applications, but I am optimistic that other, more powerful player apps will be released in the coming months.
Hardware Used
Windows PC with a processor capable of decoding MVC (I believe this means an Intel processor that contains an iGPU that supports QuickSync Video)
Apple Silicon Mac
Blu-ray drive (MakeMKV-compatible)
Portable SSD with like 500+ GB of space (optional but recommended)
Software Used
MakeMKV (https://makemkv.com/)
FFmpeg (https://ffmpeg.org/)
FRIM Decoder (https://forum.doom9.org/showthread.php?t=169651)
SpatialMediaKit (https://github.com/sturmen/SpatialMediaKit)
MP4Box (https://github.com/gpac/gpac)
Steps
I recommend saving all files to an external SSD, and simply moving the drive between the computers at the section break.
Section 1: Windows
Rip your Blu-ray with MakeMKV. Make sure to include the stereo video track! It is unchecked by default and needs to be manually selected.
Use FFmpeg to extract the MVC bitstream and audio to separate files.
ffmpeg.exe -i 'Gravity_t00.mkv' -map 0:v -c:v copy -bsf:v h264_mp4toannexb "Gravity.h264" -map 0:a:0 -c:a pcm_s24le "Gravity_5.1_LPCM.mov"
Use FRIM Decode to split the MVC video track into left and right streams. This will take three separate PowerShell windows. Execute the commands in the following order in their own window:
FRIMDecode64.exe -i:mvc Gravity.h264 -o \\.\pipe\lefteye \\.\pipe\righteye
ffmpeg -f rawvideo -s 1920x1080 -r 23.976 -pix_fmt yuv420p -i \\.\pipe\lefteye -c:v libx265 -x265-params keyint=1:min-keyint=1:lossless=1 -vtag hvc1 -movflags +faststart Gravity_left.mov
ffmpeg -f rawvideo -s 1920x1080 -r 23.976 -pix_fmt yuv420p -i \\.\pipe\righteye -c:v libx265 -x265-params keyint=1:min-keyint=1:lossless=1 -vtag hvc1 -movflags +faststart Gravity_right.mov
Section 2: Mac
Combine left and right movies into an MV-HEVC stream.
spatial-media-kit-tool merge -l Gravity_left.mov -r Gravity_right.mov -q 50 --left-is-primary --horizontal-field-of-view 40 -o Gravity_MV-HEVC.mov
(Optional) Transcode the audio to AAC to save space.
ffmpeg -i Gravity_5.1_LPCM.mov -c:a libfdk_aac -b:a 384k Gravity_5.1_AAC.mov
Use MP4Box to remux the audio back into the MV-HEVC file.
mp4box -new -add Gravity_MV-HEVC.mov -add Gravity_5.1_AAC.mov Gravity_AVP.mov
Notes and Explanations, Presented in Q&A Format
Which eye is primary? This differs based on the source material. In FFmpeg, look at the input printout of the MKV file. You should see "stereo_mode" under Metadata. "block_lr" means left is primary, "block_rl" means right is primary.
What's a good quality value for -q? I don't actually have a good answer for this yet. q=50 is what Apple calls "medium quality" and it seems fine on my 5K Studio Display, but maybe compression artifacts will be glaringly obvious inside the Vision Pro. In my testing, q=50 yields about 2.5 GB per hour of 1080p stereoscopic video. Apple calls q=75 "high quality" and that yields approximately 4x bigger files, which are still about smaller than the size of the source H.264 MVC file.
Can this be done with only a Mac? I believe so: MakeMKV does support Macs, and I read about a tool called h264-tools (https://github.com/Vargol/h264-tools) that can decode the MVC stream into the separate files. I haven't used it though.
What if my film isn't 1080p at 23.976 fps? Change your FFmpeg commands accordingly. FRIMDecoder should print out the right resolution, dimension, and colorspace. (I420 is the same as yuv420p)
Why x265 lossless? I actually use hevc_nvenc lossless, but I didn't want this guide to rely on that. We don't want to use any lossy codecs until the very end, so that eliminates a bunch of codecs, and H.264/HEVC have the advantage of being directly readable by spatial-media-kit-tool, unlike other popular lossless codecs like FFV1 or HuffyYUV. And the final tiebreaker is: lossless H.264 doesn't play in QuickTime whereas HEVC does (useful for spot-checking), so HEVC is the winner.
Can spatial-media-kit-tool work on anything other than an Apple Silicon Mac? No. It's actually a pretty thin wrapper around the proper macOS APIs that actually do all the heavy lifting for encoding. We'll have to wait x265 to add MV-HEVC support before we'll see this on any other OS.
Why MOV containers? This is again driven by compatibility with the QuickTime framework, which spatial-media-kit-tool heavily relies on. The audio file will also carry through the original chapters from the original MKV into the final MP4box mux, which is nice.
Why libfdk_aac with a bitrate of 384 kbps? According to Wikipedia, 384 is "transparent" for 5.1. I've also encountered discs that have 7.1, where I figured 512 kbps ought to be enough. I use libfdk because it supports up to 7.1 channels. If you have 5.1, I recommend you try encoding with the aac_at encoder instead, as it's supposedly even better for the same bitrate.
Why MP4box for the final mux? FFmpeg does not preserve the MV-HEVC atoms. See the GitHub readme of SpatialMediaKit.