Ch. 16 · Containers in Depth

한국어日本語
8 min

Reading Structure with ffprobe, and What Remuxing Can and Can't Do

Check the structures you've learned directly with ffprobe, and sort out the limits of remuxing, which changes only the container without re-encoding.

Four layers you can inspect with ffprobe

What you want to seeCommandWhat to look for
Container and overall infoffprobe -v error -show_format input.mp4format_name, duration, bit_rate, tags
Codec info per streamffprobe -v error -show_streams input.mp4codec_name, time_base, r_frame_rate, number of tracks
PTS, DTS, and keyframes of packetsffprobe -v error -select_streams v:0 -show_entries packet=pts_time,dts_time,flags -of csv input.mp4Whether PTS ≠ DTS, and how often K (keyframe) appears in flags
Box structure (where moov is)ffprobe -v trace input.mp4The order in which ftyp, moov, and mdat appear

The ffprobe output format can differ slightly between versions. Run it yourself in the same environment to check.

Check whether faststart was applied, by box order
ffprobe -v trace input.mp4 2>&1 | grep -E "type:'(ftyp|moov|mdat)'"

# If moov appears before mdat, faststart has been applied to the file.
# If mdat comes first, moov is at the end of the file.

If you compare the PTS and DTS columns in the packet list, you can see the reordering from the previous lesson with your own eyes. In a file with B-frames, PTS looks jumbled when read in DTS order, and in a file without them the two columns come out almost the same. You can do this on your own PC without uploading the file, and for simple information you can also use the File Info Inspector.

What is remuxing?

Remuxing means repackaging into a different container without touching the compressed streams. With no decoding or encoding, it is fast and loses no quality. In FFmpeg you do it with -c copy.

Basic form of an MKV → MP4 remux
# Copy the video and audio streams as they are into an MP4 (SRT subtitles are converted to MP4 text subtitles)
ffmpeg -i input.mkv -map 0:v -map 0:a -map 0:s? -c copy -c:s mov_text output.mp4

# For web use, add faststart too
ffmpeg -i input.mkv -c copy -movflags +faststart output.mp4
What worksWhat doesn't
Changing the container (MKV↔MP4, etc.) with no quality lossChanging resolution, bitrate, codec, or GOP: these change the stream itself, so re-encoding is required
Moving moov to the front with +faststart, converting between regular MP4 and fMP4Putting a codec the target container doesn't support in as-is (e.g., the subtitle formats an MP4 can hold are limited)
Re-encoding only the audio and copying the video (-c:v copy -c:a aac)Putting picture-based subtitles (PGS, etc.) into an MP4 as-is: only text subtitles can be converted and put in
Cutting at keyframe positions (-ss/-to with -c copy)Cutting exactly at an arbitrary non-keyframe: copy mode follows keyframe boundaries, so the cut can be off
Common pitfalls when remuxing

① Attachments in an MKV (such as fonts) and some tracks may not carry over to MP4. Even if you try to bring everything along with -map 0, you get an error if the target can't accept it. ② When you've remuxed HEVC from an MKV to an MP4 and it won't open on Apple devices, adding -tag:v hvc1 is widely known to fix it in some cases. ③ If the audio codec doesn't match the target container or device, it's better to re-encode only the audio (Audio container compatibility). ④ If the source's timestamps are irregular, they stay that way after remuxing and can show up as sync problems.

Check first, then run the command

This site's MKV→MP4 Lossless Remux Checker reads a file's tracks, judges whether they can be moved with -c copy, and builds the command for you. The file is not uploaded to a server. If subtitles keep drifting, also see the Subtitle Sync Fixer, and the FFmpeg Command Builder helps you put commands together.

Chapter summary

A container is a structure that records ① which tracks there are, ② where the samples are, and ③ when to show them. MP4 does this with boxes and the moov index, fMP4 with per-fragment indexes, MKV with EBML elements, and TS with 188-byte packets and PIDs, each in its own way. Changing only this structure while leaving the codec data alone is remuxing; if the codec data itself has to change, it is re-encoding.

RemuxRemux

Changing only the container while leaving the compressed streams as they are. In FFmpeg it is -c copy.

Stream copyStream copy

The FFmpeg mode (-c copy) that moves packets over as they are, without decoding or encoding. There is no quality loss.

mov_textmov_text subtitles

A text subtitle format that can be held in an MP4. Used when converting SRT and similar formats to put them in.

ffprobeffprobe

The analysis tool that ships with FFmpeg. It prints container, stream, and packet information.

Check yourself

What is the right approach for moving H.264 video from an MKV into an MP4 with no quality loss?