主页 Swift UNIX C Assembly Go Plan 9 Web MCU Research Non-Tech

How to convert BDMV (m2ts) to MKV, MP4 and other formats by ffmpeg

2023-06-23 | Research | #Words: 1431

BDMV is the format used by Blu-ray discs. This format cannot be played using playback software, and a hard disk player, which is a specialized device, must be used. But the most classic ffmpeg can convert it to other formats and maintain the same bit rate and definition, so that it can be viewed easily.

This article uses macOS for demonstration, but will introduce some methods and operations on other platforms.

Generally, the BDMV download format is an ISO. After loading and opening, the content is roughly as follows:

ISO content

If you are using a terminal, then (if the ISO you downloaded is not called “BDROM” after loading, it needs to be modified):

## macOS
$ cd /Volumes/BDROM/

## Linux
$ cd /dev/BDROM/

## WSL
$ cd /mnt/BDROM/

## Windows(PowerShell)
$ cdBDROM:\

If you have watched a DVD or Blu-ray disc, you will know that when the disc is played, it does not start playing directly after inserting it, but there will be a selection interface, as well as extras, sound effects, advertisements and other content (but in the past few years, I watched pirated copies Some DVDs start playing directly), and if it is a TV series, there will also be a selection interface for each episode. So at this time we need to find the m2ts file of the movie to convert. For TV series, there will be multiple m2ts files. If you need highlights and other content, please follow the method below to convert it.

The BDMV in the picture above is actually a package. You can view it by right-clicking and selecting “Show Package Contents”, as follows:

Then go into the “STREAM” folder.

The above operations are as follows in the terminal, which are the same on different platforms:

## macOS
## Linux
## WSL
## Windows(PowerShell)
$ cd BDMV/STREAM/

Then the content is displayed as follows:

Generally speaking, the first one is the m2ts file we need, which can be seen by looking at the file size. Usually it is 00000.m2ts, but it may also be 00001.m2ts, such as the picture above.

It needs to be emphasized here that if you are a macOS user, please do not directly check these files with spaces, because if the m2ts of the movie is directly viewed as a noisy video, it will be easily startled at night or when it is quiet. It is recommended to look at the file size. as follows:

You can see that the first one is the largest and takes up most of the space.

If it is a TV series, there will be multiple files of similar size, so it is best to use ffprobe to look at this file:

Input #0, mpegts, from '/Volumes/BDROM/BDMV/STREAM/00001.m2ts':
   Duration: 01:59:09.15, start: 1.996000, bitrate: 42645 kb/s
   Program 1
   Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 90k tbn
   Stream #0:1[0x1100]: Audio: pcm_bluray (HDMV / 0x564D4448), 48000 Hz, stereo, s32 (24 bit), 2304 kb/s
   Stream #0:2[0x1101]: Audio: dts (DTS-HD MA) ([134][0][0][0] / 0x0086), 48000 Hz, 5.1(side), s32p (24 bit)
   Stream #0:3[0x1102]: Audio: dts (DTS) ([130][0][0][0] / 0x0082), 48000 Hz, 5.1(side), fltp, 768 kb/s
   Stream #0:4[0x1103]: Audio: dts (DTS) ([130][0][0][0] / 0x0082), 48000 Hz, 5.1(side), fltp, 768 kb/s
   Stream #0:5[0x1104]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 448 kb/s
   Stream #0:6[0x1105]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 448 kb/s
   Stream #0:7[0x1106]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 448 kb/s
   Stream #0:8[0x1107]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 448 kb/s
   Stream #0:9[0x1108]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 448 kb/s
   Stream #0:10[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:11[0x1201]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:12[0x1202]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:13[0x1203]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:14[0x1204]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:15[0x1205]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:16[0x1206]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
   Stream #0:17[0x1207]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)

You can see the duration, average bit rate and other information of the movie. The most important thing is the various video streams, audio streams, and subtitle file information included. This article only needs to know what encoding the audio file is, and then select it, otherwise it will cause problems when initializing the stream. From the above, you can see that it is in the flac format (Blu-ray movies are generally in this format). If you want to package a finished product in a specific language and subtitles, you need to use this information, which I won’t go into details in this article.

Once you know where the location is, you can perform the conversion. The following command will also include all audio tracks and subtitles of the source file and generate an output.mkv file in the current directory (not in the ISO):

## macOS
$ ffmpeg -i /Volumes/BDROM/BDMV/STREAM/00001.m2ts -map 0 -c copy -c:a flac output.mkv

Users on other platforms should modify the file path according to the previous introduction. Users using Windows CMD should also manually convert / into \. PowerShell users can automatically convert it by pressing the Tab key at the end (in fact, PowerShell does not need to be converted). Additionally, the path to the output file can be modified as needed.

The options of the above ffmpeg command mean:

The output format is MKV, because MKV is actually a video container format that can contain multiple media files, such as subtitles and audio tracks, and many players can be found on your computer. Although the MP4 format can also store multi-track subtitles and audio, it is difficult. This is why most of the Blu-ray files you downconvert are also MKV files. MKV is mainly used to store Blu-ray or DVD movies.

If you need MP4 files, I don’t recommend converting them directly to MP4. If space permits, it is more convenient to convert them to MKV first and then to MP4. The speed of converting MKV to MP4 is also very fast, basically 100x upwards. No matter what kind of conversion process, if you want to convert to MP4 files, it is recommended to select the required soft subtitles and audio tracks, or even simpler, just delete -map 0 in the above command, and then the first audio tracks and soft subtitles to MP4 files.

Although the bit rate of Blu-ray files is very high, 1080P has 40000-60000 kb/s (general streaming media 1080P is 5000-8000), if it is 4K, it will be higher, but the conversion speed is quite fast, and modern CPUs should Can achieve 5-30x or even higher speed. Moreover, the utilization rate and memory usage are not high, and it can be transcoded in the background.

​I hope these will help someone in need~