Remuxing ISO, DVD, or Bluray using cat and ffmpeg on Linux

Published on 2018-12-05.

Whether you're dealing with a physical DVD or Bluray disc or you have ripped your original source into an ISO file, it's the same procedure.

Mount the DVD, Bluray, or ISO somewhere on your filesystem:

$ sudo mount foo.iso /mnt

Then go to the "BDMV/STREAM" directory and list the files. It will look something like this:

$ cd /mnt/BDMV/STREAM
$ ls -lh
...
-r-xr-xr-x 1 nobody nobody 6.0K Sep 17  2011 00195.m2ts
-r-xr-xr-x 1 nobody nobody 6.0K Sep 17  2011 00196.m2ts
-r-xr-xr-x 1 nobody nobody 6.0K Sep 17  2011 00197.m2ts
-r-xr-xr-x 1 nobody nobody 942K Sep 17  2011 00650.m2ts
-r-xr-xr-x 1 nobody nobody 6.0K Sep 17  2011 00720.m2ts
-r-xr-xr-x 1 nobody nobody  40G Sep 17  2011 00800.m2ts
-r-xr-xr-x 1 nobody nobody 588M Sep 17  2011 00882.m2ts
-r-xr-xr-x 1 nobody nobody 545M Sep 16  2011 00884.m2ts
-r-xr-xr-x 1 nobody nobody 546M Sep 16  2011 00885.m2ts
-r-xr-xr-x 1 nobody nobody 547M Sep 16  2011 00886.m2ts
-r-xr-xr-x 1 nobody nobody 533M Sep 16  2011 00887.m2ts
...

Then use your favorite media player to locate the media files relevant to you. In this case I am remuxing my old "Star Wars The Phantom Menace" movie and file "00882.m2ts" is the beginning of the movie with the famous Star Wars scrolling text while "00800.m2ts" is the movie itself.

Concatenate the parts you need into a temporary file using the cat command:

$ cat 00882.m2ts 00800.m2ts > /home/foo/tmp.m2ts

It's a good idea to remember to synchronize cached writes to persistent storage with the sync command before you continue.

$ sync

Now, if you want to copy everything, all audio tracks, subtitles, etc., you can then just do the following using ffmpeg:

$ cd /home/foo/
$ ffmpeg -i tmp.m2ts -c copy Star-Wars-The-Phantom-Menace-1999-Bluray-DTS-AVC-REMUX.mkv

This will copy everything without doing any encoding.

But in my case I don't want all the foreign languages or subtitles, so I use mpv to get a list of the relevant parts. You can also use mediainfo:

$ mpv tmp.m2ts
 (+) Video --vid=1 (h264 1920x1080 23.976fps)
 (+) Audio --aid=1 (dts 7ch 48000Hz)
     Audio --aid=2 (ac3 6ch 48000Hz)
     Audio --aid=3 (ac3 6ch 48000Hz)
     Audio --aid=4 (ac3 6ch 48000Hz)
     Audio --aid=5 (dts 6ch 48000Hz)
     Audio --aid=6 (ac3 6ch 48000Hz)
     Audio --aid=7 (ac3 2ch 48000Hz)
     Audio --aid=8 (ac3 2ch 48000Hz)
     Subs  --sid=1 (hdmv_pgs_subtitle)
     Subs  --sid=2 (hdmv_pgs_subtitle)
     Subs  --sid=3 (hdmv_pgs_subtitle)
     Subs  --sid=4 (hdmv_pgs_subtitle)
     Subs  --sid=5 (hdmv_pgs_subtitle)
     Subs  --sid=6 (hdmv_pgs_subtitle)
     Subs  --sid=7 (hdmv_pgs_subtitle)
     Subs  --sid=8 (hdmv_pgs_subtitle)
     Subs  --sid=9 (hdmv_pgs_subtitle)
     Subs  --sid=10 (hdmv_pgs_subtitle)
     Subs  --sid=11 (hdmv_pgs_subtitle)
     Subs  --sid=12 (hdmv_pgs_subtitle)
     Subs  --sid=13 (hdmv_pgs_subtitle)
     Subs  --sid=14 (hdmv_pgs_subtitle)
     Subs  --sid=15 (hdmv_pgs_subtitle)
     Subs  --sid=16 (hdmv_pgs_subtitle)
     Subs  --sid=17 (hdmv_pgs_subtitle)
     Subs  --sid=18 (hdmv_pgs_subtitle)
     Subs  --sid=19 (hdmv_pgs_subtitle)
     Subs  --sid=20 (hdmv_pgs_subtitle)
     Subs  --sid=21 (hdmv_pgs_subtitle)
     Subs  --sid=22 (hdmv_pgs_subtitle)
     Subs  --sid=23 (hdmv_pgs_subtitle)
     Subs  --sid=24 (hdmv_pgs_subtitle)
     Subs  --sid=25 (hdmv_pgs_subtitle)
     Subs  --sid=26 (hdmv_pgs_subtitle)
     Subs  --sid=27 (hdmv_pgs_subtitle)
     Subs  --sid=28 (hdmv_pgs_subtitle)
     Subs  --sid=29 (hdmv_pgs_subtitle)
     Subs  --sid=30 (hdmv_pgs_subtitle)
     Subs  --sid=31 (hdmv_pgs_subtitle)

If you're in doubt about which tracks you need, you can use mpv to quickly browse through them. You can then use ffmpeg to remux the relevant tracks. ffmpeg maps the tracks starting by the number 0 for the first track (the main video track).

I want to get the video track, the English DTS audio, and the English subtitle. So I do the following:

$ ffmpeg -i tmp.m2ts -map 0:0 -vcodec copy -map 0:1 -acodec copy -map 0:9 -scodec copy Star-Wars-The-Phantom-Menace-1999-Bluray-DTS-AVC-REMUX.mkv

The options I used is a follows:

This results in a remux of the movie with the following tracks as shown by mpv:

$ mpv Star-Wars-The-Phantom-Menace-1999-Bluray-DTS-AVC-REMUX.mkv
 (+) Video --vid=1 (*) (h264 1920x1080 23.976fps)
 (+) Audio --aid=1 (*) (dts 7ch 48000Hz)
 (+) Subs  --sid=1 (*) (hdmv_pgs_subtitle)

That's it!