BroadcasTheNet

Forums > Support > Approved Tutorials > [Encoding] Remuxing Untouched Bluray to MKV

#788324 by RightClickSaveWorld (Master)1 Tutorial ( No relation. ) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
RightClickSaveWorld's avatar
Joined: 7 years, 4 months ago
Introduction

This tutorial will tell you how to take a M2TS Bluray torrent like this and turn it into MKV files like these. We’ll be working on a Windows system, but I know MKVToolNix and MediaInfo are available on Linux and Mac OS X as well.

An untouched Bluray disc contains many files and folders, like .M2TS, .MPLS, and .BDMV files. Many, if not most, users prefer to have .MKV files that are properly named so they know exactly what they are playing and it is more convenient to access it. The discs not only include the episodes, but any extras and menus as well. These Bluray discs are usually encoded by other users and it makes the episodes a lot smaller and size, but they also lose their quality. But with remuxing there is no quality loss because the streams are taken in and are put into a .MKV container. Remuxing is also much faster and less CPU intensive than encoding, and you also don’t need specific settings. The .MKV file will contain the main video stream and all the audio and text tracks (subtitles) as well. The file size is usually smaller since there is lossless compression.


Required Tools and Dependencies
If you already have MKVToolNix please make sure it is at least version 7.3.0.


Instructions
Here are the steps summarized:
1. Get an untouched Bluray disc either by downloading it or ripping it yourself.
2. Install MKVToolNix for MKVMerge
3. Put the command line in a text file, and change the file extension.
4. Run the script (either for the .MPLS or .M2TS files)
5. Put the .MKV files into the folder, and only keep the episodes and maybe put the extras somewhere else. Rename the .MKV files.


Step 1. Get an untouched Bluray
You can get one from here or another torrent site, and make sure it untouched. Or you can copy a Bluray disc yourself if you have a Bluray drive, which I never have done beforebut I’m sure there are guides all over the Internet. So I’ll continue with how to download Blurays from here. The container you’ll be looking for is M2TS and you can see all the ones posted on this site here torrents.php?action=advanced&format=M2TS

Before downloading it you want to make sure no one made a Remux of it yet. For example: torrents.php?id=168880
You can see the M2TS Torrent Veep.S02.1080p.Blu-ray.AVC.DTS-HD.MA.5.1-NTb, but right below it is the Remux one Veep.S02.1080p.Remux.BluRay.DTS-HD.MA.5.1.H.264-KDL. Look at the file sizes, the untouched Bluray is 86.80 GB while the Remux is 66.18 GB. And look at the largest encode Veep.S02.1080p.BluRay.x264-ROVERS, which is only 21.78 GB. The Remuxes should be much bigger than the encoded videos. I think there might be Remuxes that aren’t labeled as such, so you might not always know for sure if someone uploaded a remux already. But if you determined that the remux isn’t already available, grab the M2TS torrent and download it with your torrent client.


Step 2.  Installing MKVToolNix for MKVMerge
This is pretty straight forward. Go to this site, http://www.bunkus.org/videotools/mkvtoolnix/downloads.html and pick your OS and follow the links to the download. I recommend choosing the installation version over the portable version just because the script depends on MKVMerge being in a static location. You can use MKVMerge via script or by using the GUI which is mmg.exe on Windows, and drag in the file you want to make into a .MKV and start it up. In this tutorial we want to keep it simple and quick, so I’ll leave out those details.


Step 3. Making the Command Line Script
Here is the script for Windows. This part is for Windows only, and you will need to figure out how to do it easily for your own OS. I would imagine the first script only needs a slight modification to work on Linux and Mac OS X.

You need to change the location of mvkmerge.exe and eac3to.exe if it is not in Program Files (x86) or if you aren't using Windows.

Pick one script to use.

Simple script where the only pre-requisite is MKVToolNix for Windows. You just copy this script to the folder with the files you want to remux in order to run it.
Code
set mkvmerge="C:\Program Files (x86)\MKVToolNix\mkvmerge.exe"
for %%f in (*.m2ts) do %mkvmerge% -o "%%~nf.mkv" "%%~f"
for %%f in (*.mpls) do %mkvmerge% -o "%%~nf.mkv" "%%~f"


Drag and drop the files you want to remux into MKV (m2ts or mpls), rather than remuxing the whole folder you select and drop the files you want onto the .BAT script. It requires MKVToolNix and Windows. It can be very useful if you are going through a folder and you are looking for videos you want to remux because you can drag and drop one or more files you want onto the script and while it is remuxing you can drag and drop the some more. You also can keep the .BAT script in one location instead of moving it to each of the folders, because it automatically outputs to the input folders.
Code
@echo OFF
set mkvmerge="C:\Program Files (x86)\MKVToolNix\mkvmerge.exe"
:again
if "%~1" == "" goto done
echo "%~1"
set source=%~1
set dest=%~n1%.mkv
%mkvmerge% -o "%dest%" "%source%"
shift
goto again
:done
exit


Copy it and paste it in a Text Document (Notepad), and save it as any name you want. Change the file’s extension to “.bat”, so that the file would be named like this, “TheScript.bat”.


Step 4. Run the Script
You will need to decide whether you want to remux the .M2TS files directly into .MKV files, or if you want to remux the .MPLS playlists into .MKV files. If every single episode is contained in their own .M2TS file, then it will be fine to remux those. But if each episode is split into multiple .M2TS files, which is pretty uncommon from what I can tell, then you want to remux the .MPLS files which link together the multiple .M2TS files. Check the length of .M2TS files and see if there are some that are the episode length. The .M2TS files are located in the STREAM folder, and the .MPLS files are in the PLAYLIST folder.

If you are using the first script, put the script in the “BDMV\STREAM” folder or the “BDMV\PLAYLIST” folder. And run it. If the command prompt window appears and then immediately disappears, then something went wrong and go to “Common Problems” section for further help. This script will search for .M2TS and .MPLS files to make the .MKV files.

If you are using the second script, just drag and drop the .M2TS and/or .MPLS files that you want to remux into .MKV files.

Wait until the command prompt window to close by itself, so you know that the script has finished running. Look through the .MKV files and collect the ones that are whole episodes, and keep the extras if you want. Make sure it has the correct audio and subtitle tracks using MediaInfo. Repeat this process for the other Bluray discs.


Step 5. Name the Episodes
Put all the .MKV episodes in one folder. The episodes aren’t always in order, and in my experience they usually aren’t. So you have to go through each episode and figure out which one they are. If there is a title card screen or anything like that, then that would be very helpful in figuring that out. If not then go to the Wikipedia page or someplace that has the episode descriptions for the season, and then go through the episode to try to figure out what episode is what. Name the episode something like, “Veep.S02E02.Signals.1080p.Bluray-YourReleaseName” so that if someone is looking for a specific episode, but their episode order is different from yours then they could go based off of the name instead of just the number.


Common Problems
An Audio Track is missing in the Remux
If the audio track is in the LPCM format, then try updating MKVToolNix to version 7.3.0 or higher (highly recommended), or if you have an older version of MKVToolNix (before version 7.3.0) try using the script posted here forums.php?action=viewthread&threadid=17596#post790673 .

Command Prompt Closes Immediately
If the command line window pops up and immediately disappears then something went wrong.
Go to the parent folder (the folder above the current one) and hold CTRL+SHIFT and then Right Click the folder you were just in and choose, “Open command window here”. Type in the name of the script to run it (without .bat), and if it has spaces in the name then put the whole thing between double quotes like this “TheScript”, and hit enter and it will run and read the resulting error message and try to fix the problem.


Special Thanks and Last Word
Thanks to onana for notifying me about MKVToolNix being updated to support LPCM audio tracks.

Also thanks to keyfan for making this script that's no longer needed if you have the updated MKVToolNix by itself. If you still want it for legacy reasons, then it is still kept here in this post: forums.php?action=viewthread&threadid=17596#post790673

Feel free to PM or to post here if you have any questions. If you are a little bit confused I'll read your post and improve the tutorial so it is more clear to others.

Last edited by RightClickSaveWorld1 Tutorial 5 years, 9 months ago
#788760 by keyfan (Master) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
keyfan's avatar
Joined: 7 years, 3 months ago
Upload: 6.83 TB
Bonus Points: [14,142,034]
Posts: 97
I tried with an anime bluray and it only include the audio track. The audio in bluray is LPCM format btw. I think it's a more reliable method to use eac3to.
#788761 by RightClickSaveWorld (Master)1 Tutorial ( No relation. ) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
RightClickSaveWorld's avatar
Joined: 7 years, 4 months ago
keyfan Wrote:
I tried with an anime bluray and it only include the audio track. The audio in bluray is LPCM format btw. I think it's a more reliable method to use eac3to.


As in there was no Video and subtitle tracks? Did you let the script finish? Did you do it on the .MPLS file or .M2TS files? Try doing the other kind. If that doesn't work, please send me a PM so we can figure it out.

Edit: I found the problem. MKVMerge doesn't support LPCM audio tracks. I added it to the common problems section. Thank you. You will be able to use another program to extract he audio, transcode it, and use mkvmerge to make the .mkv file. But it is no longer a simple process, and I believe transcoding the audio track makes it so that it is no longer considered a complete remux. So in short, you'll have to use another method to remux Blurays with LPCM audio.

Last edited by RightClickSaveWorld1 Tutorial 6 years, 2 months ago
#788815 by keyfan (Master) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
keyfan's avatar
Joined: 7 years, 3 months ago
Upload: 6.83 TB
Bonus Points: [14,142,034]
Posts: 97
I just reconsidered about this and found that maybe even with LPCM audio we could still realize one-click-remux: demuxing to a sub-folder and transcode all LPCM to wav, at last merge the original m2ts and all .wav together. I know very little about command lines and don't know how to add multiple audios to mkvmerge, following is my ugly code just for reference.

Code

::for less than 2 LPCM audios only.

@echo off
setlocal EnableDelayedExpansion
for %%f in (*.m2ts) do (
md "%%f_sub"
cd "%%f_sub"
"eac3to.exe" ../%%f -demux
set aa=0
for %%g in (*.pcm) do (
"eac3to.exe" "%%g" "audio[!aa!].wav"
set /a aa=aa+1)
cd ..
if !aa!==2 (
"mkvmerge.exe" -o "%%f.mkv" "%%f" "%%f_sub"/audio[0].wav" "%%f_sub"/audio[1].wav&quot else (
if !aa!==1 (
"mkvmerge.exe" -o "%%f.mkv" "%%f" "%%f_sub"/audio[0].wav) else (
"mkvmerge.exe" -o "%%f.mkv" "%%f&quot
)
rd /s/q "%%f_sub"
)


**BTN doesn't allow me to send long messages.

How do I avoid the damn smile in the code btw?

Last edited by keyfan 6 years, 2 months ago
#788857 by RightClickSaveWorld (Master)1 Tutorial ( No relation. ) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
RightClickSaveWorld's avatar
Joined: 7 years, 4 months ago
EDIT: THIS IS OLD CODE DO NOT USE. This code is in the middle of being completed, so it will have problems.
keyfan Wrote:

Code

::for less than 2 LPCM audios only.

@echo off
setlocal EnableDelayedExpansion
for %%f in (*.m2ts) do (
md "%%f_sub"
cd "%%f_sub"
"eac3to.exe" ../%%f -demux
set aa=0
for %%g in (*.pcm) do (
"eac3to.exe" "%%g" "audio[!aa!].wav"
set /a aa=aa+1)
cd ..
if !aa!==2 (
"mkvmerge.exe" -o "%%f.mkv" "%%f" "%%f_sub"/audio[0].wav" "%%f_sub"/audio[1].wav") else (
if !aa!==1 (
"mkvmerge.exe" -o "%%f.mkv" "%%f" "%%f_sub"/audio[0].wav) else (
"mkvmerge.exe" -o "%%f.mkv" "%%f")
)
rd /s/q "%%f_sub"
)



I put the [n] tag in middle of the smiley to break it. Like this, instead of this &quot you do this "[n]) and then it looks like this ") when you post.

I'll put it in the tutorial if I can test it. Do you know where I can get a bluray with LPCM audio?

Last edited by RightClickSaveWorld1 Tutorial 5 years, 9 months ago
#789025 by keyfan (Master) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
keyfan's avatar
Joined: 7 years, 3 months ago
Upload: 6.83 TB
Bonus Points: [14,142,034]
Posts: 97
Thanks for the tip. Here are some LPCM audio Blu-rays at BTN.
#789928 by RightClickSaveWorld (Master)1 Tutorial ( No relation. ) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
RightClickSaveWorld's avatar
Joined: 7 years, 4 months ago
I looked at your code, and there was a few mistakes, but it was better than what I could do at the time. Over the past couple of days, I learned some batch scripting, and I'm still don't quite understand it and my code is messy, and maybe someone here can clean it up or somehow make it work with .mpls files. I used your code as a base and this what I came up with. It takes the .m2ts file, and if there are any PCM tracks in there it extracts them as a .wav into a newly created subfolder. Then it will create the .mkv file from the .m2ts and the extracted .wav track. Then it will delete the subfolder. If there are no PCM tracks then it won't create the subfolder and it will take the .m2ts and make the .mkv. This script should work for any number of PCM tracks. I want you to test it out to make sure it works on other computers, just change the location of your eac3to and mkvmerge at the top of the script. If it works then I'll ask the staff here if making the PCM into a WAV would be allowed, or if there are any acceptable formats for it to be considered a true Remux.

EDIT: THIS IS OLD CODE DO NOT USE. This code is in the middle of being completed, so it will have problems.
Code
set mkvmerge="C:\Program Files (x86)\MKVToolNix\mkvmerge.exe"
set eac3to="C:\Program Files (x86)\eac3to\eac3to.exe"

@echo off
setlocal EnableDelayedExpansion
for %%z in (*.m2ts) do (
set source=%%z
set sourceshort=%%~nz

for /f "delims=" %%a in ('"!eac3to!" !source!') do (
set str1=%%a
set str2=!str1!
call set str2=%%str2:pcm=_%%

if not %!str1!==!str2! (
md "!sourceshort!_sub"
cd "!sourceshort!_sub"
call set str2=%%str2::= %%

for /f "tokens=1* delims= " %%H IN ("!str2!") do (
set /A pcmtrack=%%H
%eac3to% "..\!source!" !pcmtrack!: "!sourceshort! - !pcmtrack!.wav" -log=nul
)
cd ..
)
)

if exist !sourceshort!_sub (
cd "!sourceshort!_sub"
set "files="
for /r %%G in (*.wav) do call set files=%%files%% "!sourceshort!_sub\%%~nxG"
cd ..
)

%mkvmerge% -o "!sourceshort!.mkv" "!source!"!files!

if exist !sourceshort!_sub (
rd /s/q "!sourceshort!_sub"
)

)




Last edited by RightClickSaveWorld1 Tutorial 5 years, 9 months ago
#789987 by keyfan (Master) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
keyfan's avatar
Joined: 7 years, 3 months ago
Upload: 6.83 TB
Bonus Points: [14,142,034]
Posts: 97
It works perfect for me, much more time & space efficient and general than my raw idea.
As to .mpls, it is almost the same. One mpls file contains one playlist, so the playlist index should always be 1. when using eac3to to find pcm track, the command line is "eac3to.exe path_to_mpls 1)" instead of "eac3to.exe path_to_m2ts". All others don't need to change.
#790673 by RightClickSaveWorld (Master)1 Tutorial ( No relation. ) 6 years, 2 months ago - [Quote] [Top]  [Subscribe] [Report]
RightClickSaveWorld's avatar
Joined: 7 years, 4 months ago
DO NOT USE THIS IF YOU HAVE MKVToolNix version 7.3.0 or HIGHER, because it sometimes creates video files with double the audio tracks making the filesize a lot bigger than needed. Please update to the latest version of MKVToolNix and not use this script below. The script below is only for people who can't update to MKVToolNix 7.3.0 or higher.

eac3to requires a Windows installation with both MKVToolnix and eac3to. This script is a little slower since it has to check with eac3to each time to see if there are any PCM tracks. If it is a PCM track, then it will losslessly convert it to FLAC. This script is only here for legacy reasons, like if you want to keep the older version of MKVToolNix for some reason. Otherwise use the scripts in the first post of this tutorial instead.
For this script below you need: eac3to (Windows only)
Code
set mkvmerge="C:\Program Files (x86)\MKVToolNix\mkvmerge.exe"
set eac3to="C:\Program Files (x86)\eac3to\eac3to.exe"

@echo off
setlocal EnableDelayedExpansion
set partemp=1)
for %%z in (*.*) do (

set source=%%z
set sourceshort=%%~nz
set ext=%%~xz

if /I !ext!==.mpls (
set parone=!partemp!
echo "MPLS"
) else if !ext!==.m2ts (
set parone=
echo "M2TS"
) else (
set parone="NEXTLOOP"
echo Can't convert filetype: !ext!
)

if not !parone!=="NEXTLOOP" (

for /f "delims=" %%a in ('"!eac3to!" !source! !parone!') do (
set str1=%%a
set str2=!str1!
call set str2=%%str2:pcm=_%%

if not %!str1!==!str2! (
md "!sourceshort!_sub"
cd "!sourceshort!_sub"
call set str2=%%str2::= %%

for /f "tokens=1* delims= " %%H IN ("!str2!") do (
set /A pcmtrack=%%H
%eac3to% "..\!source!" !parone! !pcmtrack!: "!sourceshort! - !pcmtrack!.flac" -log=nul
)
cd ..
)
)

if exist !sourceshort!_sub (
cd "!sourceshort!_sub"
set "files="
for /r %%G in (*.flac) do call set files=%%files%% "!sourceshort!_sub\%%~nxG"
cd ..
)

%mkvmerge% -o "!sourceshort!.mkv" "!source!"!files!

if exist !sourceshort!_sub (
rd /s/q "!sourceshort!_sub"
)
)
)


Old post before edit, please ignore this since it is no longer applicable. Wrote:
AMAZING it works. Alright, here is the complete script that does everything. If you want a one-size-fits-all script that can remux .M2TS or .MPLS to .MKV, then this is it. The only disadvantage this has compared to the three line script in the first post is that it has to check in with eac3to, which is adds time to the process and it requires eac3to to be on the computer. I'll message a staff member to make sure this is acceptable for remuxing.

EDIT: corocoro approved of it, but said to use FLAC. So I updated the code so that it is FLAC instead for PCM tracks. Which is great since the file size is smaller than if it were WAV. Added it to the tutorial.


Last edited by RightClickSaveWorld1 Tutorial 5 years, 9 months ago
#1059518 by littleman (Master) (StampsGuru) 4 years, 9 months ago - [Quote] [Top]  [Subscribe] [Report]
littleman's avatar
Joined: 6 years, 11 months ago
Upload: 21.88 TB
Bonus Points: [208,536,747]
Posts: 62
Hello.

I tried to use the script above but it is closing when I try to run it. Did the thing with CTRL+Shift+Right Click but no errors are shown, just something with set mkvmerge="path" and eac3to="path" . Is there a way to use the mkvmerge directly?
https://valid.x86.fr/cache/banner/u3714i-2.png

https://i.ibb.co/5ssDdFb/sig90.png
#1059995 by Mooi1990 (Master) 4 years, 9 months ago - [Quote] [Top]  [Subscribe] [Report]
Mooi1990's avatar
Joined: 10 years, 3 weeks ago
Upload: 8.80 TB
Bonus Points: [669,375,674]
Posts: 158
Why not take > MakeMKV

http://www.makemkv.com

Works like a charm and very easy to use.
#1060068 by RightClickSaveWorld (Master)1 Tutorial ( No relation. ) 4 years, 9 months ago - [Quote] [Top]  [Subscribe] [Report]
RightClickSaveWorld's avatar
Joined: 7 years, 4 months ago
Mooi1990 Wrote:
Why not take > MakeMKV

http://www.makemkv.com

Works like a charm and very easy to use.


I didn't download the program, but it looks like it does an entire disc instead of letting the user choose what to remux. Also it seems to require the disc or at least an emulation of one, so unless it lets you choose a directory, then you won't be able to use it. But with that said, that seems to be a very useful program.

Last edited by RightClickSaveWorld1 Tutorial 4 years, 9 months ago
#1060153 by Mooi1990 (Master) 4 years, 9 months ago - [Quote] [Top]  [Subscribe] [Report]
Mooi1990's avatar
Joined: 10 years, 3 weeks ago
Upload: 8.80 TB
Bonus Points: [669,375,674]
Posts: 158
No hard disc or emulation required but you can open an hard disc if you have a bluray drive connected.

Untouched Blurays as .iso, .bdmv on your hard drive > no problem and for sure, you can pick what you would like to demux.

Here what it looks like when you open a .bdmv


http://i.imgur.com/eQdoypf.png


Tick the audio file you want keep and subtitles, specify destination...thats it.
As you might see, you can also demux a DTS out of a DTS-HD MA ( also works for .mkv Files )

MakeMKV is really very useful if you do a lot of demuxing
#1060200 by RightClickSaveWorld (Master)1 Tutorial ( No relation. ) 4 years, 9 months ago - [Quote] [Top]  [Subscribe] [Report]
RightClickSaveWorld's avatar
Joined: 7 years, 4 months ago
Pretty useful, thanks for sharing and explaining.

Post reply