What is an M2TS File?

An M2TS file holds a BDAV MPEG-2 transport stream, the variant of the MPEG-2 transport stream used by Blu-ray Disc and AVCHD, in which a 4-byte header precedes every 188-byte transport packet. It can multiplex video, audio, subtitle graphics, and other elementary streams in one file.

How M2TS Files work

The Blu-ray Disc read-only format stores each clip’s audio and video as a BDAV MPEG-2 transport stream in a .m2ts file. The stream is a sequence of 192-byte source packets, each a 4-byte TP_extra_header followed by a standard 188-byte MPEG-2 transport packet, grouped into 6144-byte aligned units of 32 packets. Inside the transport packets the usual MPEG-2 Systems rules apply: the Program Association Table points to a Program Map Table, which identifies the program’s elementary streams by packet identifier. On a disc, the .m2ts file is only half of a clip. A same-numbered .clpi file stores the time stamps of access points into the stream, and .mpls playlist files describe what to play as a list of play items, each an in-point and out-point on a clip’s time axis. AVCHD camcorders record into the same container, and the Library of Congress format description lists mts as a second extension for it.

Key facts

  1. Each source packet is 192 bytes: a 4-byte TP_extra_header followed by a standard 188-byte MPEG-2 transport packet. A parser that steps through the file in 188-byte packets will not stay aligned, because the transport sync byte sits at offset 4 of every source packet. FFmpeg’s MPEG-TS demuxer handles this by probing the packet size and skipping the first 4 bytes of each 192-byte packet.
  2. A lone .m2ts file holds one clip’s stream, not a title. On a Blu-ray disc the .mpls playlists in BDMV/PLAYLIST select intervals of clips and their order, and the .clpi clip-information files in BDMV/CLIPINF hold the access-point time stamps a player uses to find where to start reading. Titles sit one level higher: the disc’s index table points each title to a movie object or BD-J object, and movie objects, stored in BDMV/MovieObject.bdmv, launch playlist playback. Opening the files in BDMV/STREAM one by one therefore yields each clip’s streams without the playing order and in- and out-points that the playlists define.
  3. Blu-ray subtitles can live in two places. Bitmap presentation graphics streams are multiplexed in the BDAV transport stream alongside video and audio. Text subtitles are a separate, out-of-mux clip, which a playlist attaches through a sub-path, so they are not in the main clip’s .m2ts. That clip’s stream file sits in BDMV/STREAM with the audio and video clips, and the subtitle fonts are separate .otf files in the AUXDATA directory.
  4. Rewrapping M2TS into another container with stream copy leaves the encoded video and audio untouched, because nothing is decoded or re-encoded; FFmpeg notes that stream copy can still fail when the target container needs information the source does not provide. Blu-ray clips may carry MPEG-2, H.264/AVC, or VC-1 video, so check each stream against what the target container accepts. Subtitles show the limit: in the FFmpeg 8.0 source, the MP4 muxer has no codec tag for either Blu-ray subtitle codec and rejects those streams. Clips from commercial discs are a separate case: the Library of Congress notes that M2TS itself has no encryption support but that Blu-ray discs are often protected with AACS.

When M2TS Files matter

Media pipelines meet M2TS when ingesting AVCHD camcorder recordings or the clip files in the BDMV/STREAM directory of a Blu-ray Disc structure. The decision that matters is whether to treat a file as a standalone stream or as one clip of a disc: a single .m2ts can be demultiplexed on its own, but playing order and access-point tables are defined in companion playlist and clip-information files, and the disc’s titles in its index table.

Working with M2TS Files

FFmpeg’s MPEG-TS muxer has an m2ts mode that writes the 4-byte prefix before every transport packet and uses fixed packet identifiers. In the FFmpeg 8.0 source the automatic setting turns the mode on when the output name ends in .m2ts, and the muxer refuses more than one program in that mode. The value FFmpeg writes into the prefix is a 30-bit timestamp taken from the stream’s program clock.

Writing a file of 192-byte packets is not the same as authoring a disc. A Blu-ray BDMV structure also needs index, movie-object, playlist, and clip-information files, and players navigate through those rather than through the stream files. To read a playlist instead of a single clip, FFmpeg offers a bluray input protocol that reads a playlist from a mounted disc structure.

Sources

Turn media knowledge into a working pipeline

Connect uploads, processing, AI, storage, and delivery through one declarative API — with the encoding stack, scaling, and format churn handled for you.

Try Transloadit for free