~/bend-docscommunity

flvw.bend checks

raw source on the hub · import 0x2355f41b6f5561f50104a75ccca27cf7/flvw.bend as Flvw

Frames into an FLV file: the one container here that holds pictures, their times, and the audio most cameras send (G.711) together.

video H.264 as FLV has it: a configuration tag made of the SPS and the PPS, then a tag per picture, its NAL units each after its size. H.265 the same way under enhanced RTMP's header ("hvc1"), the configuration made of the VPS, SPS and PPS. audio G.711 as it is (format 7 for the A-law, 8 for the mu-law); AAC as a configuration tag and a tag per frame, each frame without the ADTS header it came with.

No picture is written before a key one whose parameter sets are known: they come from the stream's description, or with the picture.

4 imports
import Base
import ./bytes.bend as B
import ./frame.bend as F
import ./rtmp_core.bend as K

Types

type Fw source · line 131 · raw

Data

first: the file's header is still to write. vconf, aconf: the video's and the audio's configurations were written. audio: its codec. step: an AAC frame's length in ms. sets: the parameter sets of the stream's description.

type Put source · line 136 · raw

Data

What a frame gave: bytes to write, and the state after.

Definitions

def Nal.push source · line 22 · raw

@cur:List<&2, U32> -> @acc:List<&2, List<&2, U32>> -> List<&2, List<&2, U32>>

def Nal.split.go source · line 30 · raw

@bs:List<&2, U32> -> @cur:List<&2, U32> -> @acc:List<&2, List<&2, U32>> -> List<&2, List<&2, U32>>

def Nal.split source · line 42 · raw

@bs:List<&2, U32> -> List<&2, List<&2, U32>>

The units of an Annex B stream: what is between its start codes (00 00 00 01, which no unit can hold: a unit escapes two zeros in a row).

def Nal.type source · line 46 · raw

@h265:Bool -> @+b:U32 -> U32

A unit's type: 5 bits of its first byte in H.264, 6 in H.265.

def Nal.find source · line 54 · raw

@nals:List<&2, List<&2, U32>> -> @+h265:Bool -> @+want:U32 -> List<&2, U32>

The first unit of a type, or nothing.

def Nal.sized source · line 65 · raw

@nals:List<&2, List<&2, U32>> -> List<&2, U32>

Units each after its size in 4 bytes, as a tag holds a picture.

def Nal.set source · line 74 · raw

@+n:List<&2, U32> -> @rest:List<&2, U32> -> List<&2, U32>

A unit after its size in 2 bytes, as a configuration holds a parameter set.

def Nal.plain source · line 79 · raw

@n:Nat -> @bs:List<&2, U32> -> @+zeros:U32 -> List<&2, U32>

The first n bytes of a unit with its escapes taken out (a 03 after two zeros is not data).

def Conf.avc source · line 95 · raw

@+sps:List<&2, U32> -> @+pps:List<&2, U32> -> List<&2, U32>

H.264's (an AVCDecoderConfigurationRecord): the profile and level out of the SPS, sizes of 4 bytes, one SPS, one PPS. Nothing when either is missing.

def Conf.hevc source · line 106 · raw

@+vps:List<&2, U32> -> @+sps:List<&2, U32> -> @+pps:List<&2, U32> -> List<&2, U32>

H.265's (an HEVCDecoderConfigurationRecord) after enhanced RTMP's header: the 12 bytes of profile, tier and level out of the SPS (they follow its 2 bytes of header and one of ids), then what a decoder reads again in the SPS itself, sizes of 4 bytes, and three arrays of one: VPS (32), SPS (33), PPS (34). Nothing when one is missing.

def Conf.video source · line 116 · raw

@h265:Bool -> @+nals:List<&2, List<&2, U32>> -> List<&2, U32>

def Fw.new source · line 139 · raw

@+i:0x2355f41b6f5561f50104a75ccca27cf7/frame.Info -> Fw

def Fw.head source · line 143 · raw

@first:Bool -> List<&2, U32>

def Fw.picture source · line 152 · raw

@h265:Bool -> @key:Bool -> @body:List<&2, U32> -> List<&2, U32>

The tag a picture goes in: H.264's header (key or not, a picture, no time offset) or H.265's (key or not, a picture with no offset, "hvc1").

def Fw.conf.tag source · line 159 · raw

@conf:List<&2, U32> -> @ms:U32 -> List<&2, U32>

def Fw.video source · line 169 · raw

@w:Fw -> @+ms:U32 -> @+key:Bool -> @data:List<&2, U32> -> Put

A picture. The file's video starts at a key picture, after its configuration (made from the description's parameter sets or the picture's own): what comes before one a decoder could not use.

def Fw.asc source · line 182 · raw

@done:Bool -> @data:List<&2, U32> -> @ms:U32 -> List<&2, U32>

AAC's configuration out of a frame's ADTS header: profile, rate index and channels, in 2 bytes, in a tag of its own.

def Fw.aac.cut source · line 193 · raw

@c:0x2355f41b6f5561f50104a75ccca27cf7/bytes.Cut -> @+ms:U32 -> @acc:List<&2, U32> -> @k:(@_:List<&2, U32> -> @_:List<&2, U32> -> List<&2, U32>) -> List<&2, U32>

def Fw.aac source · line 203 · raw

@fuel:Nat -> @bs:List<&2, U32> -> @+ms:U32 -> @+step:U32 -> @acc:List<&2, U32> -> List<&2, U32>

Each ADTS frame (a 7-byte header that says its size in 13 bits) as a tag of the frame alone, step ms after the one before.

def Fw.sound source · line 213 · raw

@aac:Bool -> @alaw:Bool -> @ulaw:Bool -> @first:Bool -> @h265:Bool -> @vconf:Bool -> @+aconf:Bool -> @audio:String -> @+step:U32 -> @sets:List<&2, List<&2, U32>> -> @+ms:U32 -> @+data:List<&2, U32> -> Put

def Fw.audio source · line 230 · raw

@w:Fw -> @ms:U32 -> @data:List<&2, U32> -> Put

def Fw.put source · line 236 · raw

@w:Fw -> @f:0x2355f41b6f5561f50104a75ccca27cf7/frame.Frame -> Put

A frame into the file; its time in ms.