How do you manually extract (decapsulate) an H.264 bitstream from an MP4 file

h.264, mp4, video

Solution

The process is known as multiplexing: you extract individual stream from a file with possibly multiple streams and additional information.

In Windows, Media Foundation API offers MPEG-4 File Source to read and demultiplex `.MP4` files. There are third party demultiplexers for DirectShow API as well, e.g. from GDCL.

FFmpeg's `libavformat` has its own demultiplexer.

Problem

Would extracting an H264 bitstream from an MP4 is achieved just by appending all raw data from a video track in an H.264 MP4 file, or is there some special decoding steps to realize? There are some H.264 decoder sources here and there that take a pure "264" track as input. Is this input directly readable / available from the average MP4 file? (Let's say the common iOS or Windows Phone MP4 AVC file type.)

Original source