archived-things


Project maintained by sometimes-archives-things Hosted on GitHub Pages — Theme by mattgraham

The Blutopia Guide to Blu-ray Remuxing

DRAFT DOCUMENT

This guide is a work in progress.

Aims

To equip users with the knowledge and experience to become an advanced remuxer with the necessary skills to pass the BLURANiUM User Release Program.

A BLURANiUM approved remux aims to (i) provide the best possible home viewing and listening experience and (ii) serve as the ultimate source for an encode.

Table of Contents

0 Changelog

1 Installation


All software used must be up to date.

For metadata extraction:

For demuxing/remuxing:

For playback:

For losslessly encoding audio:

For analysing video:

For analysing audio:

For editing/converting subtitles:

2 Decrypt


2 Decrypt

Skip to step 3 (Demux) if you don’t need to rip a physical disc.

Otherwise, first follow the Full Disc Ripping Guide.

3 Demux


Subject to the exceptions below, you should use Eac3to to demux the disc. To date, it is still the best demuxer in terms of error detection and correction capabilities which is essential if a disc has mastering or manufacturing errors.

Exception: Since eac3to is unable to process PTS timing correctly on HEVC video, you must use DGDemux or MakeMKV for UHDBDs that employ seamless branching.

Prepare eac3to:

  1. Eac3to from StaxRip is recommended as it includes the latest codecs.
  2. Add the directory of eac3to to the system path (Search online: how to add directory to system path).

3.1 Demux BDs (1080p)

BDs consist of playlists (.MPLS files) which consist of media (.M2TS files). Scanning the BD with BDInfo shows the available playlists.

To demux a BD, specify the playlist you wish to demux, and if applicable, the individual tracks. The -demux flag will extract all the tracks in the specified playlist. Extracting specific tracks from the playlist can also be done as shown below. See here for more commands.

To demux a BD:

Method 1 (using eac3to):

  1. Open Windows Command Prompt and change the current directory to your project folder:
    • cd /d <projectFolderPath>
    • E.g. cd /d "D:\workshop\"
  2. Use eac3to summary to find the correct playlist:
    • eac3to <BDMVFolderPath>
    • E.g. eac3to "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR"
  3. Demux all media in the playlist to your project folder:
    • eac3to <BDMVFolderPath> <playlistNumber>) -demux -log="eac3to.txt"
    • E.g. eac3to "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR" 1) -demux -log=eac3to.txt
  4. To demux specific playlists and tracks, specify via the command line:
    • eac3to <BDMVFolderPath> <playlistNumber>) <trackNumber>:outputFilename.* -log="eac3to.txt"
    • E.g. eac3to "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR" 1) 1:chapters.txt 2:video.* 3:audio.* 4:subtitles.* -log="eac3to.txt"

Method 2 (using DGDemux):

  1. Open Windows Command Prompt and change the current directory to your project folder:
    • cd /d <projectFolderPath>
    • E.g. cd /d "D:\workshop\"
  2. Use DGDemux to find the correct playlist:
    • dgdemux -d <BDMVFolderPath>
    • E.g. dgdemux -d "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR"
  3. Demux all media in the playlist to your project folder:
    • dgdemux -i <MPLSFilePath> -o <OutputFilePath>
    • E.g. dgdemux -i "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR\BDMV\PLAYLIST\00001.mpls" -o "00001"
    • Exclude the file extension in the -o flag.
  4. To demux specific tracks, specify via the command line:
    • dgdemux -i <MPLSFilePath> -o <OutputFilePath> -demux <PID>,<PID>,<PID>,...
    • E.g. dgdemux -i "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR\BDMV\PLAYLIST\00001.mpls" -o "tenet" -demux 1011,1100,Chapters
    • PID aka playlist ID is the hex value of the playlist shown using dgdemux -i <MPLSFilePath>.
    • Chapters is a valid PID.

Method 3 (useful when eac3to/DGDemux does not find all the playlists):

  1. Use BDInfo to generate a BDInfo log of all playlists:
    • CLI
      • bdinfo <BDMVFolderPath> -i
      • E.g. bdinfo "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR" -i
    • GUI
      • Open the BDMV folder inside the program.
  2. Open Windows Command Prompt and change the current directory to your project folder:
    • cd /d <projectFolderPath>
    • E.g. cd /d "D:\workshop\"
  3. Demux the correct playlist based on the information given in the BDInfo log:
    • eac3to
      • eac3to <MPLSFilePath> 1) -demux -log="eac3to.txt"
      • E.g. eac3to "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR\BDMV\PLAYLIST\00001.mpls" 1) -demux -log="eac3to.txt"
    • DGDemux
      • dgdemux -i <MPLSFilePath> -o <OutputFilePath>
      • E.g. dgdemux -i "D:\discs\Tenet 2020 1080p Blu-ray AVC DTS-HD MA 5.1-ESiR\BDMV\PLAYLIST\00001.mpls" -o "00001"
      • Exclude the file extension in the -o flag.

If there are hundreds of playlists

  1. Open Process Monitor.
  2. Filter by including Process Name is vlc.exe and including Path contains mpls.
  3. Press the capture icon to start capturing.
  4. Open and play the disc in VLC.
  5. When you click play for example, vlc reads the playlist .MPLS file, which Process Manager filters.
  6. eac3to <playlistPath> -demux -log="eac3to.txt"

Log warnings

TrueHD

Lossy audio tracks

Embedded forced subtitles

Playlist properties

Distributor logos

3.2 Demux DVDs

MakeMKV should be used to demux DVDs, and it will often reveal hidden text-based subtitles.

Audio and subtitles can be extracted from DVD remuxes using MKVExtract:

  1. Open Windows Command Prompt and change the current directory to your project folder:
    • cd /d <projectFolderPath>
    • E.g. cd /d "D:\workshop\"
  2. Find subtitle track ID:
    • mkvmerge <MKVFilePath> --identify
    • E.g. mkvmerge "D:\title_01.mkv" --identify
  3. Extract subtitles:
    • mkvextract <MKVFilePath> tracks <TrackID>:<OutputFileName>
    • E.g. mkvextract "D:\title_01.mkv" tracks 2:subs
      • This will create files subs.idx and subs.sub.

3.3 Demux UHDBDs

3.4 See also

WARNING: the eac3to log will include your Windows username depending on the directory in which it is located.

Notes regarding MakeMKV:

4 BDInfo


Use BDInfo to gather detailed information of all tracks:

  1. Open the disc with BDInfo, select the playlist that was demuxed and click Scan Bitrates.
  2. View and copy the report quick summary for later use.

Alternatively, use the CLI:

Some discs may require DVDFab’s version of BDInfo.

5 Compare


It is important to identify the best source when studios of different regions have released the same film, resulting in different languages, bitrates, codecs and perceptual qualities.

Repeat step 2 (Decrypt) through step 5 (Compare) for all sources you can obtain.

5.1 Find best video track

Perceptual quality is of highest importance. The codec and bitrate can influence this. To compare two sources:

Cut and combine sources (not recommended unless you know what you are doing) (click to expand)

If one video source is not consistently better throughout the film, it is possible to losslessly cut and combine the best zones of each source for an ultimate hybrid track:

  1. Use AVSPmod with 5.6 AviSynth+ script 2/5.8 VapourSynth script 1.
  2. A video stream can only be cut on an I-frame that has a P-frame directly before it.
  3. A video stream must start with an I-frame.
  4. A video stream must end with either a P-frame or B-frame.
  5. The above principles constitute a “Group Of Pictures” (GOP)).
  6. Find the timestamp / frame number of the start and end of a GOP.
  7. Split the video files using MKVToolNix → Multiplexer → Output → Splitting.
  8. Avidemux can also be used as a GUI to cut on black frames easily.

5.2 Find best audio track

Audio track quality attributes ranked from highest priority to lowest:

  1. First priority: Perceptual quality is the most important characteristic when deciding quality. For example:
    • A lower bit depth or even a lossy track without clipping might sound better than a lossless track with noticeable clipping.
    • A music related production originally mixed in stereo and subsequently upmixed to 5.1 might sound better in stereo.
    • A DVD may sound better than the BD: http://blah-ray.blogspot.com/2017/01/dekalog-1989.html.
    • Share comparisons of spectrogram and ampltiude statistics with others using https://slow.pics to gauge public opinion.
  2. Second priority: lossless encoding (LPCM, TrueHD, DTS-HD MA, DTS:X) is better than lossy (DD, DD+, DTS, DTS-HD HRA).
  3. 3rd priority: an object-based layer (DTS:X, Atmos) is better than none.

If multiple mixes with different channel counts exist:

Commentary tracks:

If a track is available in different languages:

More audio exceptions (click to expand)

5.2.1 Split or combine sources

Not recommended unless you know what you’re doing (click to expand)

5.3 Collect all subtitles

Subtitles must be collected as follows:

To determine the language of unfamiliar subtitles:

5.4 See also

Using the sites below is encouraged in order to gain general, historical, and technical insight into the title your are preparing:

5.5 AviSynth+ script 1

# These 2 lines aren't required if you copy the plugins to your plugins folder (C:\Program Files (x86)\AviSynth+\plugins+\)
import("C:/PATH/TO/ffms2-2.23.1-msvc/FFMS2.avsi")
LoadPlugin("C:/PATH/TO/ffms2-2.23.1-msvc/x64/ffms2.dll")

a=ffvideosource("C:/PATH/TO/sourceA.mkv")
a=a.Subtitle("A", y=54)
a=a.FFInfo(framenum=true,frametype=true,cfrtime=true,vfrtime=false,version=false,cropping=false,colorrange=false,colorspace=false,sar=false)

b=ffvideosource("C:/PATH/TO/sourceB.mkv")
b=b.Subtitle("B", y=54)
b=b.FFInfo(framenum=true,frametype=true,cfrtime=true,vfrtime=false,version=false,cropping=false,colorrange=false,colorspace=false,sar=false)

interleave(a, b)

5.6 AviSynth+ script 2

# These 2 lines aren't required if you copy the plugins to your plugins folder (C:\Program Files (x86)\AviSynth+\plugins+)
import("C:/PATH/TO/ffms2-2.23.1-msvc/FFMS2.avsi")
LoadPlugin("C:/PATH/TO/ffms2-2.23.1-msvc/x64/ffms2.dll")

FFVideoSource("C:/PATH/TO/source.mkv")
FFInfo(framenum=true,frametype=true,cfrtime=true,vfrtime=false,version=false,cropping=false,colorrange=false,colorspace=false,sar=false)

5.7 VapourSynth script 1

# This following line isn't required if you copy btpfunc.py to your plugins folder:
# - `C:\Program Files\Python39\Lib\site-packages` (Windows),
# - `/usr/local/lib/python3.9/dist-packages` (Ubuntu),
# - `/usr/lib/python3.9/site-packages` (Fedora & Arch)
# Note: the Python folder is different depending on the version you have installed

LoadPlugin(path='C:/PATH/TO/btpfunc.py')

import vapoursynth as vs
import btpfunc as btp
core = vs.get_core()
path1=r'C:/PATH/TO/sourceA.mkv'
clip1=core.ffms2.Source(path1) # You can also use src=core.lsmas.LWLibavSource(path1)
clip1=btp.FFInfo(clip1, text='A', frame_num=True, frame_type=True, frame_time=True,color='0000FFFF') # Prints frame type (I/P/B) and absolute time.
path2=r'C:/PATH/TO/sourceB.mkv'
clip2=core.ffms2.Source(path2) # You can also use src=core.lsmas.LWLibavSource(path2)
clip2=btp.FFInfo(clip2, text='B', frame_num=True, frame_type=True, frame_time=True,color='0000FFFF') # Prints frame type (I/P/B) and absolute time.
comp=core.std.Interleave([clip1,clip2])
comp.set_output()

5.8 VapourSynth script 2

# This following line isn't required if you copy btpfunc.py to your plugins folder:
# - `C:\Program Files\Python39\Lib\site-packages` (Windows),
# - `/usr/local/lib/python3.9/dist-packages` (Ubuntu),
# - `/usr/lib/python3.9/site-packages` (Fedora & Arch)
# Note: the Python folder is different depending on the version you have installed

LoadPlugin(path='C:/PATH/TO/btpfunc.py')

import vapoursynth as vs
import btpfunc as btp
core = vs.get_core()
path=r'C:/PATH/TO/source.mkv'
clip=core.ffms2.Source(path) # You can also use src=core.lsmas.LWLibavSource(path)
clip=btp.FFInfo(clip, text='source', frame_num=True, frame_type=True, frame_time=True,color='0000FFFF') # Prints frame type (I/P/B) and absolute time.
clip.set_output()

6 Conversion


Certain formats require lossless encoding for better compatibility and compression.

6.1 Convert lossless audio

All 24-bit audio (regardless of channels) must be demuxed as .PCM/.WAVS/.FLAC using eac3to to check if it is padded with zeroes or not.

If eac3to does not know the correct endianness, you can specify the format with the -little/-big flag.

If the best audio track has 2 channels or less and is encoded with a lossless codec (e.g. DTS-HD MA 2.0 or LPCM):

If the best audio track has more than 2 channels and is encoded with a lossless uncompressed codec (e.g. LPCM):

Note: do not convert lossless commentaries to lossy.

Note: do not transcode lossy audio tracks.

6.2 Convert dual mono

If a 2.0 track is dual mono (i.e. both channels are identical), do the following:

  1. Check the disc cover for e.g. DTS 2.0 Mono.

  2. Generate a spectrogram mixing channel 1 and 2 with channel 2 inverted:

    • E.g. sox dualmono.flac -n remix 1,2v-1 spectrogram -x 10000 -y 1025 -z 120 -o mono.png -c "Dual.Mono"
    • It will be entirely blank (black) if both channels are identical.
    • If only short distributor sequences are coloured, it is still dual mono.
    • Very dark blue spread throughout signifies “stereoized mono” and should be left untouched.
  3. If it is 2.0 mono, then only one channel should be included in the remux:

    • E.g. C:\eac3to.exe "F:\Das.fliegende.Klassenzimmer.1954.GERMAN.COMPLETE.BLURAY-iFPD" 1) 3:audio_mono.flac -mono -log=eac3to.txt

    Sometimes, a dual mono track will include short stereo sequences mixed by the distributor: In such cases, your new track should be based on the average of both channels:

    • E.g. sox dual.mono.flac mono.flac remix 1v0.5,2v0.5
  4. Include the spectrogram and command in your description.

6.3 Convert text-based subtitles

If the format is .VTT or another simple text-based format:

6.4 Convert image-based subtitles (aka OCR)

Use SubtitleEdit to convert low resolution VobSub image subtitles to text (only do this with languages in which you are literate). If the best available English subtitles/translation is from a DVD (VOBSub), you should OCR them to provide a more attractive option.

  1. Importing
    • Method 1 (for subtitles previously extracted with MakeMKV)
      1. Select File → Import → Import Vobsub subtitle for OCR...
    • Method 2 (when MakeMKV has errors)
      1. Select File → Import → Subtitle from VOB/IFO (DVD) and select the title’s main .IFO.
      2. The dialogue box will show the title’s sequence of VOB Files. Click Start Ripping to rip all the subtitles.
      3. Compare the extracted subtitles with the DVD Menu to verify that the language is correct.
        • DVDs often provide wrong info about languages.
      4. The dialogue box will show multiple subtitles if multiple are ripped. Go through each one and click Save As.
      5. Click OK to proceed to OCR.
  2. Initialization
    1. Set the OCR Method as Tesseract 3.02 on Windows, or Tesseract 4 on Linux.
      • Tesseract 5.0 is newer and may produce more OCR errors. The best engine will depend on subtitle type and font.
    2. Click on ... next to Language to download the language pack.
    3. Click on ... next to Dictionary to download the spell-checking dictionary.
    4. Configure the Image Palette tab with custom colours and transparency.
      • OCR works best with a black text against a white background, or white text with a black outline against a transparent background.
  3. OCR
    1. Click Start OCR. You will be prompted to verify errors or words not recognized.
  4. Review
    1. Perform a visual check. Go through each line at a mild place and compare the OCR’d text to the images. Common errors include:
      • Missing -’s in dialogue lines,
      • Full stops (.) replacing commas (,),
      • Pipe (|) replacing letter I’s,
      • Shorter words missing a few letters.
    2. Note any recurring errors and batch fix them later with the Replace tool, but correct as much as possible first.
    3. Click OK to complete the OCR which will return you to the main window.
    4. Open Tools → Fix common errors. Select any extra issues you feel might be present beyond the defaults.
    5. Click Next >, order the errors by function, and check if the errors are correctly identified.
    6. Click Apply selected fixes.
    7. Run a final spell-check.
  5. Saving
    1. Verify that encoding UTF-8 without BOM is selected.
    2. Click Save and save as SubRip (.SRT) format.
  6. SDH
    • If the OCR’d subtitles are SDH (Subtitles for the Deaf or Hard of Hearing) with non-dialogue information such as [Door creaks], you can remove such elements to have a set of non-SDH subtitles:
      1. Select Tools → Remove text for hearing-impaired....
      2. Remove the extra information to create a standard full subtitle.
      3. Do a quick visual to confirm the process was succesful.

6.5 Tonemap HDR subtitles

SDR Subtitles must be tonemapped for HDR video or else they will be too bright:

  1. Use subtitle_tonemap to tonemap SDR subtitles:
    • e.g. subtitle_tonemap "C:\path\to\subtitles.sup" --output tonemapped

HDR subtitles must be tonemapped for SDR video or else they will be too dark. Simply changing the brightness does not work as the blacks will no longer be black.

  1. Open the .PGS subtitle in BDSup2Sub and export .PGS to .PNG + .XML.
  2. Use the following script over the extract image folder with imagemagick:
    • Powershell:

      mkdir mapped
      $files = @(Get-ChildItem *.png)
      foreach ($f in $files) {
          $file=$f.name
          magick.exe $file -fuzz 15% -fill 'rgb(204,204,204)' -opaque 'rgb(152,152,152)' -fuzz 15% -fill 'rgb(195,195,195)' -opaque 'rgb(109,109,109)' mapped/$file
      }
      
    • Bash:

      mkdir mapped
      for file in *.png; do
          magick $file -fuzz 15% -fill 'rgb(204,204,204)' -opaque 'rgb(152,152,152)' -fuzz 15% -fill 'rgb(195,195,195)' -opaque 'rgb(109,109,109)' mapped/$file
      done
      
    • You might need two passes or even two different fill colours, for the fade between the black border.
    • Note: The colours may be incorrect on your first try.
  3. Import the .XML and .PNG back to .PGS using BDSup2Sub.

7 Chapters


7.1 Collect

Collect chapters using the eac3to command from step 3 (Demux).

7.2 Check for accuracy

Use the disc menu in VLC to manually navigate to each chapter and verify that the timestamps correspond to the eac3to-extracted chapters.txt file. They are often a few frames off.

If the chapters are not from the same source as your video track, confirm that they are synced to the correct scene changes.

Add a chapter for the End Credits, Mid-Credits Scene, and/or Post-Credits Scene if applicable and if they do not already exist.

Chapters from web sources should be verified to have sensible names and intervals.

Amazon example of ridiculous “chapter sentences” (click to expand)

00:00:00.000                             : en:Studio logos
00:00:23.000                             : en:Swagger &amp; Fenn &amp; Opening Credits
00:02:59.000                             : en:Swagger and Fenn Engage the Enemy
00:06:01.000                             : en:Air Support Arrives
00:08:15.000                             : en:Thirty-Six Months Later
00:10:24.000                             : en:Swagger Gets Visitors
00:12:37.000                             : en:Colonel Johnson Asks Swagger to Plan Assassination
00:16:05.000                             : en:Swagger Recreates the Shot
00:18:55.000                             : en:Swagger Scouts Possible Assassination Locations
00:20:58.000                             : en:Swagger Reports to the Colonel
00:23:14.000                             : en:Swagger and the Team Prepare
00:27:21.000                             : en:The Shooter Takes the Shot
00:31:10.000                             : en:Swagger Gives Himself First-Aid and Evades Authorities
00:34:38.000                             : en:The FBI Searches for Swagger
00:37:06.000                             : en:The Media Blames Nick Memphis for Swagger's Escape
00:39:02.000                             : en:Swagger Buys Supplies
00:41:08.000                             : en:Memphis Mans the Phones and Swagger Recovers
00:44:25.000                             : en:Swagger Asks Donny's Wife for Help, Kentucky
00:48:54.000                             : en:Memphis Explains the Discrepencies
00:51:27.000                             : en:Sarah Sews Up Swagger
00:53:43.000                             : en:Memphis Continues His Investigation
00:55:49.000                             : en:Swagger Wakes &amp; Memphis Researches
00:57:52.000                             : en:Sarah Checks Her Work
00:59:39.000                             : en:Sarah Gives Swagger a Rifle
01:02:27.000                             : en:Sarah Meets With Memphis
01:05:09.000                             : en:Memphis Digs Deeper
01:08:01.000                             : en:The Conspirators Interrogate Memphis
01:11:44.000                             : en:The Conspirators Discuss Swagger
01:13:06.000                             : en:Swagger &amp; Memphis Seek Wisdom
01:18:00.000                             : en:Tracking the shooter
01:20:02.000                             : en:Payne Attacks Sarah
01:21:24.000                             : en:Swagger &amp; Memphis Prepare for the Attack
01:23:16.000                             : en:Memphis and Swagger Infiltrate the Ranch
01:26:38.000                             : en:Swagger Interrogates Sandor
01:33:50.000                             : en:Swagger Has a Flashback
01:36:00.000                             : en:The FBI Investigates the ranch
01:37:23.000                             : en:Memphis and Swagger Make Some Calls
01:39:56.000                             : en:Memphis and Swagger Meet With the Conspirators
01:43:31.000                             : en:Swagger Takes the Shot
01:44:29.000                             : en:Calling in the FBI
01:47:26.000                             : en:Swagger Surrenders
01:50:08.000                             : en:Swagger Makes a Point
01:54:42.000                             : en:The Attourney General Gives Swagger a Suggestion
01:55:31.000                             : en:Johnson and Meacham Celebrate
01:57:27.000                             : en:Swagger Deals With the Conspirators
02:01:04.000                             : en:End Credits

Example of user-corrected chapters (click to expand)

00:00:00.000                             : en:Shooter (2007)
00:02:58.637                             : en:Engaging the Enemy
00:08:14.494                             : en:Thirty-Six Months Later
00:12:36.756                             : en:Planning an Assassination
00:27:20.097                             : en:Taking the Shot
00:31:07.866                             : en:On the Run
00:48:53.889                             : en:Discrepencies
00:53:43.220                             : en:The Investigation Continues
01:05:09.155                             : en:Digging Deeper
01:13:10.678                             : en:Seeking Wisdom
01:21:23.337                             : en:The Preparation
01:33:49.624                             : en:Flashback
01:39:56.116                             : en:Meeting the Conspirators
01:47:25.022                             : en:Surrendering
01:55:30.924                             : en:Celebration
02:00:29.222                             : en:End Credits

7.3 See also

Note: studios have been found to store chapters with incorrect timestamps, and have the Java menu quietly correct them upon playback.

If eac3to did not find chapters or they are not named:

  1. Check the BD menu with VLC.
  2. Check all other available retail sources (including DVDs and WEB sources such as an AMZN WEB-DL).
    • If a disc has non-English chapters, consider finding someone who can translate them for you.
    • Named chapters are always preferred to numbered chapters.
  3. If no acceptable chapter names can be found, name them Chapter 01, Chapter 02, etc. using the source with the best scene change intervals.
  4. If no acceptable chapter timings can be found, generate some at reasonable intervals (e.g. at major scene changes).

Named chapters should be capitalized according to the APA Style Guide. Refer to https://capitalizemytitle.com/ for further assistance.

For foreign chapters, use the MKVToolNix chapter editor to include both the original chapter names and the English-translated chapter names with the correct flags set for each.

If you are editing a chapter.txt file directly, make sure that you are using UTF-8. If you use ANSI, your chapters might break after international characters such as é.

8 Syncing


Different sources will often need to be timed so that they are in sync. Chapters often need to be re-synced to scene change I-frames (see below) since less competent studios do not do this.

8.1 Sync audio to video with offset

Method 1: compare video (recommended):

  1. Open both video tracks in AviSynth+/VapourSynth.

  2. Find the difference in frame count between the same frame on both tracks.

  3. Convert the offset to seconds by dividing the frame difference (i.e. the number of frames by which the two sources are misaligned), and the frame rate of the video source you will use.

    • Note: 23.976 fps is actually 24000/1001.

    • E.g. Divide an offset of 120 frames by (24000 frames / 1001 seconds) to get 5.005 seconds.

      120 / (24000/1001) = 5.005

  4. Convert the offset to seconds using the rational framerate.

    • Note: 23.976 fps is actually 24000/1001 so divide the offset by the fraction to convert the framecount to seconds.
  5. Apply delay to audio in MKVToolNix.

Method 2: compare audio

  1. Open both audio tracks in Audacity.
  2. Find the time offset between peaks/crests in waveform.
  3. Apply delay to audio in MKVToolNix.

On negative delays, MKVToolNix cuts out the unnecessary audio which maintains compatibility. However, on positive delays, MKVToolNix applies the delay in a flag which some devices are incompatible with. For positive delays:

If the negative delay cuts off non-silent audio, you would need to prepend black video to the video track:

8.2 Sync chapters to scene-change frames

Do the following:

  1. Use 5.6 AviSynth+ script 2 or 5.8 VapourSynth script 2 with AVSPMod and open the video.
  2. Go to Macros → Import Bookmarks From File (AVSPMod) or Script → Preview → Load Chapters (VSEdit), and import the corrected eac3to-extracted chapters.txt or the corrected MKVExtract-extracted chapter XML as done in step 7.2 (Chapters: check for accuracy).
  3. Use F2 and shift+F2 (AVSPMod) or Ctrl+left and Ctrl+right (VSEdit) to jump to the next/previous chapter and verify it is on the correct scene and on the scene-change frame.
  4. If the chapter on the scene-change frame is not an I-frame.

    1. Find the closest I-frame through the next/previous frame buttons.
    2. Remove the old bookmark and add the new one by pressing Ctrl+B on the selected frame (AVSPMod) or by pressing [Un]bookmark current frame (VSEdit).
    • Exception: verify that the chosen I-frame does not have dialogue or obvious scene noises that start or finish before the video change.
      • If it does, find the nearest I-frame that doesn’t cut off that dialogue.
    • Exception: very rarely, the original intent may have been to place a named chapter change at a point that maintains a thematic beat rather than to cut a scene.
      • If it’s evident that the named chapter corresponds with a thematic beat, choose the best available I-frame that maintains that beat.
    • Another way is using Avidemux which is a GUI with buttons that “skip to the next keyframe”.

8.3 Sync subtitles

Sync retail subtitles (.PGS, VobSub):

Sync retail subtitles (.SRT):

  1. Import the .SRT file into Subtitle Edit.
  2. Import the video file you are syncing to into Subtitle Edit.
  3. Use the Synchronization tab.
  4. Adjust the frame rate if necessary.
  5. Select Adjust all times and enter the delay if necessary.
  6. Check that the sync is fitting by watching a couple of minutes at 10 minute intervals.
    • If they go out of sync at any point due to a different cut or scene change padding, find that exact point and adjust the delay accordingly.
  7. In rare cases, you might need to adjust the speed by a small margin.
    • This happens mostly with PAL DVD subtitles, usually only by less than 1% (test with 0.1% increments).
  8. Manual syncing might be required for older movies. For advanced cases or users ONLY:
    1. Select points at 5 to 10 minute intervals.
    2. Add the waveform.
    3. Sync each line that differs too much from the correct timing.

Create/edit custom subtitles (.SRT):

8.4 Sync Kino Lorber BDs

BDs distributed by Kino Lorber are known for a silent intro of their logo that is exactly 11011 milliseconds long but in which time no empty audio or subtitle track is played. This means that the audio and subtitle tracks will be out-of-sync by 11011 milliseconds with the video and chapters.

9 Tag


MKV Tags allow for useful metadata to be specified.

Create an .XML file with UTF-8 text encoding for the mkv tags for later. Note the comments inside <!-- -->.

Click each of the following to expand:

For a Movie:

<?xml version="1.0" encoding="UTF-8"?>

<tags>
    <tag>                                         <!-- Movie Template -->
        <targets>
            <targettypevalue>50</targettypevalue> <!-- 50 is used for MOVIE/EPISODE/CONCERT -->
        </targets>
        <simple>
            <name>IMDB</name>
            <string>tt#####</string>              <!-- Replace # with imdb id for that movie e.g. tt4154756 -->
        </simple>
        <simple>
            <name>TMDB</name>
            <string>movie/#####</string>          <!-- Replace # with tmdb id for that movie e.g. movie/299536 -->
        </simple>
    </tag>
</tags>

For a TV Show (simple version):

<?xml version="1.0" encoding="UTF-8"?>

<tags>
    <tag>                                         <!-- TV Show Template (simple) -->
        <targets>
            <targettypevalue>70</targettypevalue> <!-- 70 is used for COLLECTION -->
        </targets>
        <simple>
            <name>IMDB</name>
            <string>tt####</string>               <!-- Replace # with IMDB id for that tv series e.g. tt0944947 -->
        </simple>
        <simple>
            <name>TMDB</name>
            <string>tv/####</string>              <!-- Replace # with TMDB id for that tv series e.g. tv/1399 -->
        </simple>
        <simple>
            <name>TVDB</name>
            <string>####</string>                 <!-- Replace # with TVDB id for that tv series e.g. 121361 -->
        </simple>
    </tag>
</tags>

For a TV Show (advanced version - which should be used when possible):

<?xml version="1.0" encoding="UTF-8"?>

<tags>
    <tag>                                         <!-- TV Show Template (Advanced) -->
        <targets>
            <targettypevalue>70</targettypevalue> <!-- 70 is used for COLLECTION -->
        </targets>
        <simple>
            <name>IMDB</name>
            <string>tt####</string>               <!-- Replace # with IMDB id for that tv series e.g. tt0944947 -->
        </simple>
        <simple>
            <name>TMDB</name>
            <string>tv/####</string>              <!-- Replace # with TMDB id for that tv series e.g. tv/1399 -->
        </simple>
        <simple>
            <name>TVDB</name>
            <string>####</string>                 <!-- Replace # with TVDB id for that tv series e.g. 121361 -->
        </simple>
    </tag>
    <tag>                                         <!-- Season -->
        <targets>
            <targettypevalue>60</targettypevalue> <!-- 60 is used for SEASON/SEQUEL/VOLUME -->
        </targets>
        <simple>
            <name>PART_NUMBER</name>
            <string>#</string>                    <!-- Replace # with season number e.g. 1 -->
        </simple>
        <simple>
            <name>TOTAL_PARTS</name>
            <string>#</string>                    <!-- Replace # with number of episodes in that season e.g. 10 -->
        </simple>
    </tag>
    <tag>                                         <!-- Episode -->
        <targets>
            <targettypevalue>50</targettypevalue> <!-- 50 is used for MOVIE/EPISODE/CONCERT -->
        </targets>
        <simple>
            <name>PART_NUMBER</name>
            <string>#</string>                    <!-- Replace # with episode number of that season e.g. 4 -->
        </simple>
        <simple>
            <name>IMDB</name>
            <string>tt####</string>               <!-- Replace # with IMDB id for that episode e.g. tt1829963 -->
        </simple>
    </tag>
</tags>

Note: when using TMDB IDs, verify that it is correctly identified by TMDB as a movie or TV show. The metadata system breaks if, for example, TMDB identifies a movie as a TV show but is tagged the 50 TargetTypeValue. You should create a TMDB account to edit or create a new entry.

10 Mux


Use MKVToolNix to remux the assets you’ve prepared into an MKV container.

10.1 Import all the tracks

Import the following:

  1. Best video track.
  2. Best audio track, and if relevant: original mixes, commentaries, isolated score.
  3. Best subtitles from all possible languages.
    • Important: exclude all forced foreign subtitles designed for their dubbed counterparts.

If a movie is divided between more than one disc:

  1. Import the first section of the movie
  2. Right-click the first section and select Append files.
  3. Select to append the second section of the movie.

10.2 Order the tracks

The tracks must be sorted in the following order.

10.2.1 Order the video

The main video track should be placed first.

10.2.2 Order the audio

Audio should be placed second and in the following sequence:

  1. Main audio with the highest perceptual quality.
  2. Compatibility track
    • Placed immediately after the track it provides compatibility for.
    • When you demux a TrueHD track correctly (see step 3 (Demux)), the compatibility track will be exported as a separate track. Make sure to include this second compatibility track in addition to the main track.
  3. Alternative/unique audio mixes
    • If there are multiple audio mixes, order them according to quality, starting with what is objectively the best option. This will usually, but not always, be the one with the highest channel count and/or bitrate.
  4. Commentaries
    • Order of importance. Generally:
      1. Director
      2. DP/cinematographer
      3. Actors
      4. Film critics / Others
    • However, for example, if an actor is more notable than the director (e.g. a James Bond movie), the actor’s commentary should be first.

10.2.3 Order the subtitles

Subtitles should be placed next in the following order:

  1. First: Forced for non-English/foreign dialogue/titles for the production’s primary spoken language if applicable.
  2. Next: Intertitles for the production’s primary language if applicable.
  3. Next: subtitles are ordered alphabetically by their English name (except English language itself, which is always first).
    • Within each language, dialects are ordered alphabetically by their English name (except the base dialect, which is always first).
      • Within each dialect, group individual retail sources in order of quality (e.g. if a Criterion DVD source has better quality English translation than that of the Blu-ray).
        • Within each specific source, the regular subtitle variant comes first, followed by the SDH variant.
      • Do not include forced foreign subtitles designed for their dubbed counterparts.
      • Base dialects include: French (Parisian), Spanish (Castilian) and Portuguese (Iberian).
        • If the dialect is associated with the language’s country of origin, then it is usually the base dialect.
        • Chinese does not have a base dialect. Simplified, Traditional or Cantonese should be specified for the written script type.
  4. Next: For non-English parts on English dub if applicable.
  5. Next: Intertitles for the English dub if applicable.
  6. Next: subtitles for English dub if applicable.
  7. Next: subtitles for commentaries in the same order of the audio track(s).

Subtitle ordering example:

  1. English - for foreign dialogue
  2. English
  3. English - SDH
  4. Chinese - Traditional
  5. French
  6. French - SDH
  7. French - Canadian
  8. French - SDH / Canadian
  9. English - For non-English parts on English dub (only if production’s primary language was not English)
  10. English - Dub (only if production’s primary language was not English)
  11. English - Commentary by ...
  12. Chinese - Traditional / Commentary by ...
  13. French - Commentary by ...
  14. French - Canadian / Commentary by ...

10.3 Rename all the tracks

10.3.1 Name the video

The video track title should reflect the BDInfo Quick Summary

10.3.2 Name the audio

The audio track title(s) should reflect the BDInfo Quick Summary.

Audio track title naming exceptions:

Commentary track names should be descriptive:

10.3.2.1 Name older audio formats

Notes on older audio formats that may be unfamiliar to you.

Dolby Surround: (click to expand)

10.3.3 Name the subtitles

Subtitles must be set to the correct language. You may need to enable additional languages via MKVToolNix settings if some are missing. You should only give subtitles a track title in the following cases:

10.4 Set flags and add metadata

10.4.1 Set flags

Language flags. The following should be set:

  1. Set video track to the same language as the main audio track.
  2. Set audio track to its respective language.
    • If there is no dialogue, the language code is zxx.
  3. Set subtitle track to its respective language, including the dialect if applicable.

Set the following boolean flags to no if the following cases don’t apply.

Default flags. Set the Default track flag to yes for the following:

Forced flags. Set the Forced display flag to yes for the following:

Hearing impaired flags. Set the Hearing impaired flag to yes for all SDH subtitles.

Visual impaired flags. Set the Visual impaired flag to yes for all audio tracks that include auditory descriptions for the visually impaired.

Text descriptions flags. Set the Text descriptions flag to yes for all subtitle tracks with text-based descriptions for the visually impaired that can be read via a screen reader or Braille device.

Original language flags. Set the Original language flag to yes for all audio tracks in the production’s primary language.

Commentary flags. Set the Commentary flag to yes for all audio and subtitle tracks that are commentary.

Dialog normalization. Tick Remove dialog normalization on all lossless tracks as well as DTS-HD HRA. For all other tracks, make sure it is unticked.

10.4.2 Set compression

zlib compression. Verify that zlib compression is disabled for all tracks.

10.4.3 Add additional metadata

Title naming. Give a title in the form:

Chapter file. Add the chapter file created from step 7 (Chapters) on the Output tab.

Tag file. Add the tag file created from step 9 (Tag) on the Output Tab.

10.5 Name the file

Name the file according to site rules. Use only the following characters (no spaces):

11 Request approval


Congratulations! You have now successfully completed a high-quality remux.

It is highly encouraged that you participate in Blutopia’s user release program to receive feedback and approval from Blutopia internals.

Your approval request in the appropriate forum should consist of one Pastebin including the following in the same order:

You must add a - before any tracks in the BDInfo that you have not remuxed and include the QUICK SUMMARY: label at the beginning of each Quick Summary.

Example Pastebin text for a hybrid remux (click to expand)

https://pastebin.com/xQqpscjW

QUICK SUMMARY:

Disc Label: EN_MAI_FAIS_CE_QU_IL_TE_PLAIT
Disc Size: 38,462,559,183 bytes
Protection: AACS
Playlist: 00001.MPLS
Size: 28,328,773,632 bytes
Length: 1:53:06.780
Total Bitrate: 33.39 Mbps
Video: MPEG-4 AVC Video / 24370 kbps / 1080p / 23.976 fps / 16:9 / Main Profile 4.1
-Audio: French / DTS-HD Master Audio / 5.1 / 48 kHz /  3829 kbps / 24-bit (DTS Core: 5.1 / 48 kHz /  1509 kbps / 24-bit)
-Audio: French / DTS-HD Master Audio / 2.0 / 48 kHz /  1677 kbps / 24-bit (DTS Core: 2.0 / 48 kHz /   768 kbps / 24-bit)
-Audio: French / DTS Audio / 2.0 / 48 kHz /   768 kbps / 16-bit
-Audio: French / DTS Audio / 2.0 / 48 kHz /   768 kbps / 16-bit
Subtitle: French / 5.665 kbps
Subtitle: French / 20.483 kbps

QUICK SUMMARY:

Disc Label: Come What May 2015 1080p USA Blu-ray AVC DTS-HD MA 5.1-CultFilms™
Disc Size: 43,812,883,300 bytes
Protection: AACS
Playlist: 00005.MPLS
Size: 27,188,355,072 bytes
Length: 1:53:13.411
Total Bitrate: 32.02 Mbps
-Video: MPEG-4 AVC Video / 25488 kbps / 1080p / 23.976 fps / 16:9 / High Profile 4.1
Audio: French / Dolby Digital Audio / 5.1 / 48 kHz / 448 kbps / DN -31dB
-Audio: French / DTS-HD Master Audio / 5.1 / 48 kHz / 3949 kbps / 24-bit (DTS Core: 5.1 / 48 kHz / 1509 kbps / 24-bit)
Audio: English / Dolby Digital Audio / 2.0 / 48 kHz / 448 kbps / DN -31dB
Subtitle: English / 25.049 kbps

General
Unique ID                                : 9423834467934860155940483189717009044 (0x716F6E96CA8B179C18E5C47C15B0294)
Complete name                            : Come.What.May.2015.Hybrid.1080p.BluRay.REMUX.AVC.DTS-HD.MA.5.1-BLURANiUM.mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 22.8 GiB
Duration                                 : 1 h 53 min
Overall bit rate mode                    : Variable
Overall bit rate                         : 28.8 Mb/s
Movie name                               : Come What May (2015)
Encoded date                             : UTC 2020-06-14 21:28:57
Writing application                      : mkvmerge v47.0.0 ('Black Flag') 64-bit
Writing library                          : libebml v1.3.10 + libmatroska v1.5.2
IMDB                                     : tt2296747
TMDB                                     : movie/351192

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L4.1
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Format settings, GOP                     : M=1, N=12
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 1 h 53 min
Bit rate mode                            : Variable
Bit rate                                 : 24.4 Mb/s
Maximum bit rate                         : 39.6 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.490
Stream size                              : 19.2 GiB (85%)
Title                                    : MPEG-4 AVC Video / 24370 kbps / 1080p / 23.976 fps / 16:9 / Main Profile 4.1
Language                                 : French
Default                                  : Yes
Forced                                   : No
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio #1
ID                                       : 2
Format                                   : DTS XLL
Format/Info                              : Digital Theater Systems
Commercial name                          : DTS-HD Master Audio
Codec ID                                 : A_DTS
Duration                                 : 1 h 53 min
Bit rate mode                            : Variable
Bit rate                                 : 3 951 kb/s
Channel(s)                               : 6 channels
Channel layout                           : C L R Ls Rs LFE
Sampling rate                            : 48.0 kHz
Frame rate                               : 93.750 FPS (512 SPF)
Bit depth                                : 24 bits
Compression mode                         : Lossless
Stream size                              : 3.12 GiB (14%)
Title                                    : DTS-HD Master Audio / 5.1 / 48 kHz / 3949 kbps / 24-bit
Language                                 : French
Default                                  : Yes
Forced                                   : No

Audio #2
ID                                       : 3
Format                                   : AC-3
Format/Info                              : Audio Coding 3
Commercial name                          : Dolby Digital
Codec ID                                 : A_AC3
Duration                                 : 1 h 53 min
Bit rate mode                            : Constant
Bit rate                                 : 448 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 31.250 FPS (1536 SPF)
Compression mode                         : Lossy
Stream size                              : 362 MiB (2%)
Title                                    : Commentary by director Christian Carion
Language                                 : English
Service kind                             : Complete Main
Default                                  : No
Forced                                   : No

Text #1
ID                                       : 4
Format                                   : UTF-8
Codec ID                                 : S_TEXT/UTF8
Codec ID/Info                            : UTF-8 Plain Text
Duration                                 : 1 h 45 min
Bit rate                                 : 29 b/s
Count of elements                        : 912
Stream size                              : 22.6 KiB (0%)
Language                                 : English
Default                                  : Yes
Forced                                   : No

Text #2
ID                                       : 5
Format                                   : PGS
Codec ID                                 : S_HDMV/PGS
Codec ID/Info                            : Picture based subtitle format used on BDs/HD-DVDs
Duration                                 : 1 h 45 min
Bit rate                                 : 26.9 kb/s
Count of elements                        : 2096
Stream size                              : 20.3 MiB (0%)
Title                                    : SDH
Language                                 : English
Default                                  : No
Forced                                   : No

Text #3
ID                                       : 6
Format                                   : PGS
Codec ID                                 : S_HDMV/PGS
Codec ID/Info                            : Picture based subtitle format used on BDs/HD-DVDs
Duration                                 : 1 h 42 min
Bit rate                                 : 6 258 b/s
Count of elements                        : 530
Stream size                              : 4.58 MiB (0%)
Title                                    : Pour le dialogue non français
Language                                 : French
Default                                  : No
Forced                                   : No

Text #4
ID                                       : 7
Format                                   : PGS
Codec ID                                 : S_HDMV/PGS
Codec ID/Info                            : Picture based subtitle format used on BDs/HD-DVDs
Duration                                 : 1 h 45 min
Bit rate                                 : 21.9 kb/s
Count of elements                        : 1935
Stream size                              : 16.6 MiB (0%)
Title                                    : SDH
Language                                 : French
Default                                  : No
Forced                                   : No

Menu
00:00:00.000                             : en:Communist Propaganda - fr:Propagande communiste
00:05:13.313                             : en:France, Summer 1939 - fr:France, été 1939
00:12:31.751                             : en:War - fr:Guerre
00:20:00.190                             : en:Evacuation - fr:Évacuation
00:28:14.692                             : en:Council Meeting - fr:Réunion du Conseil
00:36:43.701                             : en:Wine Cellar - fr:Cave à vin
00:42:34.550                             : en:Germans - fr:Allemands
00:49:50.988                             : en:La Fontaine Fable - fr:La Fontaine Fable
00:58:07.983                             : en:Action! - fr:Action!
01:08:15.091                             : en:Max! - fr:Max!
01:16:00.556                             : en:French Resistance - fr:Résistance française
01:21:52.407                             : en:Papa - fr:Papa
01:30:45.939                             : en:Going Home - fr:Rentrer à la maison
01:40:33.527                             : en:Across The River - fr:De l'autre côté de la rivière
01:46:46.899                             : en:End Credits - fr:Crédits de fin

eac3to v3.34
command line: "Z:\home\me\eac3to\eac3to.exe" ../EN_MAI_FAIS_CE_QU_IL_TE_PLAIT/ 1) 1: chapters.txt 2: video.h264 3: audio.dtsma 7: french-forced.sup 8: french-sdh.sup -progressnumbers -log=eac3tolog.txt
------------------------------------------------------------------------------
M2TS, 1 video track, 4 audio tracks, 2 subtitle tracks, 1:53:07, 24p /1.001
1: Chapters, 16 chapters
2: h264/AVC, 1080p24 /1.001 (16:9)
3: DTS Master Audio, French, 5.1 channels, 24 bits, 48kHz
   (core: DTS, 5.1 channels, 1509kbps, 48kHz)
4: DTS Master Audio, French, 2.0 channels, 24 bits, 48kHz
   (core: DTS, 2.0 channels, 768kbps, 48kHz)
5: DTS, French, 2.0 channels, 768kbps, 48kHz
6: DTS, French, 2.0 channels, 768kbps, 48kHz
7: Subtitle (PGS), French
8: Subtitle (PGS), French
Creating file "chapters.txt"...
[v02] Extracting video track number 2...
[s08] Extracting subtitle track number 8...
[a03] Extracting audio track number 3...
[s07] Extracting subtitle track number 7...
[v02] Creating file "video.h264"...
[a03] Creating file "audio.dtsma"...
[s08] Creating file "french-sdh.sup"...
[s07] Creating file "french-forced.sup"...
Video track 2 contains 162720 frames.
Subtitle track 7 contains 265 captions.
Subtitle track 8 contains 967 captions.
eac3to processing took 1 minute, 40 seconds.
Done.

eac3to v3.34
command line: "Z:\home\me\eac3to\eac3to.exe" "../Come What May 2015 1080p USA Blu-ray AVC DTS-HD MA 5.1-CultFilms/" 1) 1:usa.chapters.txt 4:usa.mainaudio.* -6089ms 5:commentary.* -6089ms 6:english.sup -6089ms -log=comewhatmay.usa.demuxlog.txt
------------------------------------------------------------------------------
M2TS, 1 video track, 3 audio tracks, 1 subtitle track, 1:53:13, 24p /1.001
1: Chapters, 15 chapters
2: h264/AVC, 1080p24 /1.001 (16:9)
3: AC3, French, 5.1 channels, 448kbps, 48kHz
4: DTS Master Audio, French, 5.1 channels, 24 bits, 48kHz
   (core: DTS, 5.1 channels, 1509kbps, 48kHz)
5: AC3, English, 2.0 channels, 448kbps, 48kHz
6: Subtitle (PGS), English
Creating file "usa.chapters.txt"...
[s06] Extracting subtitle track number 6...
[a05] Extracting audio track number 5...
[a04] Extracting audio track number 4...
[a05] Applying (E-)AC3 delay...
[a04] Applying DTS delay...
[a04] A remaining delay of +1ms could not be fixed.
[a05] A remaining delay of -9ms could not be fixed.
[a04] Creating file "usa.mainaudio.dtsma"...
[a05] Creating file "commentary.ac3"...
[s06] Creating file "english.sup"...
Video track 2 contains 162879 frames.
Subtitle track 6 contains 1048 captions.
eac3to processing took 1 minute, 21 seconds.
Done.