moonmedia Reel 03 · The cutting room

Reel 03 · The cutting room

Anatomy

A one-second clip, cut into two segments and pushed through a transport stream. Every number here was read from the bytes this library wrote: twelve frames, two fragments, one packet.

Where the cuts fall

A decoder can start at a key frame and nowhere else, so the packager cuts there. The target duration is what it aims for; the key frames are what decides. Below are the twelve frames of the clip, and the two segments that came out.

starts at
0.00 s
duration
0.60 s
size
8,755 bytes
video samples
6
audio samples
5

The playlist that names them starts with the initialisation section a player fetches once, then one line per segment:

playlist
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-MAP:URI="init.mp4"
#EXTINF:0.6,
segment0.m4s
#EXTINF:0.6,
segment1.m4s
#EXT-X-ENDLIST

What this shows

The three sizes of a stream

A player sees segments; a decoder sees a fragment; the wire sees packets.

The three views are the same video. A segment is what a player asks for by URL and what a playlist names. Inside it, a fragment tells a decoder where the samples are without reading the whole file. Underneath, the same bytes travel as packets, because a transport stream has to be readable from anywhere in it — a receiver that joins in the middle finds the clock and the tables without needing the beginning.

Reading one and writing the other is the whole library: the packager turns a file into segments, the box layer reads a segment apart, and the transport layer does the same for packets.