Demuxing

On this page 7

Demuxing, short for demultiplexing, is the process of reading a container file or transport stream and separating its interleaved tracks into individual elementary streams, such as a video stream, one or more audio streams, subtitles and metadata. In video containers and formats, demuxing is the counterpart of muxing: a muxer packs streams into a container such as MP4, MOV, MKV or MPEG-TS, and a demuxer unpacks them again.

Every media player, editor and transcoder performs demuxing before it can decode anything, because codecs work on elementary streams, not on containers. Demuxing on its own does not decode or re-encode the content: the compressed data is extracted bit for bit, which makes it fast and lossless.

How demuxing separates streams in a container

A container stores several streams interleaved in small chunks, so that video and audio for the same moment sit close together in the file. A demuxer reads the container’s index and headers, identifies each track with its codec, timing and language, and then routes every packet to the correct output stream.

Timing is the most delicate part of the job. Each packet carries timestamps, typically a presentation timestamp (PTS) and often a decoding timestamp (DTS). The demuxer must preserve these values, because they tell the decoder when to display each frame and how to keep audio and video in sync. Losing or rewriting timestamps incorrectly is the main cause of drift after extraction.

The demuxer’s output can be passed directly to decoders, as in a media player, or written to separate files. Written streams are either kept in a raw elementary form, such as an .h264 or .aac file, or remuxed into a new container with a single track. The compressed data itself remains identical.

How container structure affects demuxing

Each container organizes its streams differently, which changes how a demuxer finds and extracts data. The table summarizes the main formats in this topic.

ContainerInternal structureDemuxing characteristics
MP4ISO base media file format with boxesUses a sample table index; fast seeking
MOVQuickTime atoms, closely related to MP4Same principles as MP4, more legacy track types
MKVMatroska elements based on EBMLFlexible tracks, rich subtitle and chapter support
MPEG-TSFixed 188-byte packets with PIDsStreamable, resilient to errors, no global index
MXFProfessional KLV-coded structureUsed in broadcast; may store tracks in separate files
Demuxing behavior of common containers

In MPEG-TS, each stream is identified by a packet identifier (PID), and the program tables PAT and PMT describe which PIDs belong to which program. A demuxer can start reading a transport stream at any point, which is why it is used in broadcasting and live streaming. In MP4 and MOV, the moov box holds the index; if it is missing or placed at an unreadable position after an interrupted recording, demuxing fails until the file is repaired.

Demuxing is frequently confused with transcoding, but the two operate at different layers. Demuxing works on the container; transcoding works on the encoded content.

OperationWhat changesQuality impactSpeed
DemuxingStreams are separated from the containerNone, losslessVery fast, limited by disk speed
MuxingStreams are combined into a containerNone, losslessVery fast
RemuxingStreams move to a different containerNone, losslessVery fast
DecodingCompressed data becomes raw frames or samplesNone by itselfProcessor-intensive
TranscodingContent is decoded and encoded againGeneration loss possibleSlow, processor-intensive
Demuxing distinguished from related processes

Because demuxing and remuxing keep the original compressed data, they are the preferred way to change containers when the target device supports the existing codec. Transcoding should be reserved for cases in which the codec itself must change, for example when a device cannot play H.265 or a broadcaster requires a different format.

Practical uses of demuxing

Demuxing appears throughout video production and delivery, often invisibly. Typical tasks include the following.

TaskTypical inputResult
Extracting audio for mixingMOV from a cameraSeparate WAV or AAC track for the sound editor
Pulling subtitlesMKV with several subtitle tracksSRT or ASS files for translation
Repairing sync problemsRecording with drifting audioStreams realigned and remuxed
Adaptive streaming packagingMuxed MP4 masterSeparate video and audio renditions
Broadcast monitoringMPEG-TS from a satellite feedIndividual programs and audio languages
Common demuxing tasks

Command-line tools such as FFmpeg perform demuxing with stream copy options, for example selecting a single track and copying it without re-encoding. Graphical tools for Matroska and MP4 offer the same operation through track lists. In adaptive streaming formats such as HLS and MPEG-DASH, packaging often keeps video and audio in separate segments, so players fetch only the tracks they need.

Common problems when demuxing

Most demuxing problems come from incompatible codecs, lost timing information or damaged files, rather than from the operation itself.

  • Raw streams without timing: extracting H.264 to an elementary file discards container timestamps, so variable frame rate footage can play at the wrong speed.
  • Audio offset after extraction: edit lists or start offsets in MP4 and MOV may not be carried over, shifting sync by a few frames.
  • Codec not allowed in the target container: some subtitle and audio formats cannot be remuxed into MP4 without conversion.
  • Damaged index: interrupted recordings without a valid moov box cannot be demuxed until repaired.
  • Assuming demuxing converts formats: it never changes the codec; a separate transcode step is needed.

A plain-language summary

A video file is like a box that holds several things packed together: the picture, one or more soundtracks and often subtitles. Demuxing means opening the box and taking each item out separately, without changing any of them.

Every video player does this quietly before it can show anything. Editors and technicians do it on purpose when they need only the sound, only the subtitles or want to place the same picture in a different box. Nothing is re-recorded, so nothing loses quality.

An example from practice

A video editor receives a two-hour MKV file of a recorded panel discussion containing H.264 video, two AAC audio tracks in English and German, and an English subtitle track. The client needs a German version for a platform that accepts only MP4, plus the subtitles as a separate file for review.

Instead of transcoding, the editor demuxes the streams with stream copy, selecting the video track and the German audio track and remuxing them into a new MP4. The subtitle track is extracted to an SRT file. The whole operation takes only a few minutes, a fraction of the time a full re-encode of two hours of video would need, and the picture remains bit-identical to the original. A quick check of the first and last minutes confirms that audio sync is intact.