Flash Player 6 brought video inside the movie, so any ZWS movie, being SWF 13 or later, may hold it. A video is a character defined by DefineVideoStream, whose frames come one at a time in VideoFrame tags on the timeline; PlaceObject2’s Ratio says which frame to show. A DefineVideoStream with CodecID 0 and no frames is a placeholder for a Video object fed from an external stream. The explorer decodes and draws all the codecs below except CodecID 7, whose packets it reads only.
DefineVideoStream (60)
| Type | Name | Description |
|---|---|---|
| UI16 | CharacterID | The character ID |
| UI16 | NumFrames | The number of video frames |
| UI16 | Width | In pixels |
| UI16 | Height | In pixels |
| UB[4] | VideoFlagsReserved | 0 |
| UB[3] | VideoFlagsDeblocking | 0 use the video packet’s setting, 1 off, 2 level 1 (fast deblocking), 3 level 2 (better deblocking), 4 level 3 (better deblocking and fast deringing), 5 level 4 (better deblocking and better deringing), 6 and 7 reserved; levels 2 to 4 are for VP6 only. Filters a player applies after decoding; the explorer shows frames without them |
| UB[1] | VideoFlagsSmoothing | Smooth the picture when it is scaled |
| UI8 | CodecID | The codec: table below |
| CodecID | Codec | From SWF |
|---|---|---|
| 0 | None: a placeholder with no embedded frames | – |
| 2 | Sorenson H.263 | 6 |
| 3 | Screen video | 7 |
| 4 | On2 VP6 | 8 |
| 5 | On2 VP6 with alpha | 8 |
| 6 | Screen video version 2 | – |
| 7 | H.264 (not in the specification) | – |
The specification’s DefineVideoStream table lists codecs 2 to 5. Its VideoFrame table adds 6, SCREENV2VIDEOPACKET, and its video chapter defines that packet, but it gives codec 6 no SWF version, so none is listed here. Codecs 0 and 7 are in neither table: the specification does not define them for SWF. The explorer’s reading of 0 (no embedded frames) and of 7 (H.264) are its own assumptions.
VideoFrame (61)
| Type | Name | Description |
|---|---|---|
| UI16 | StreamID | The DefineVideoStream this frame belongs to |
| UI16 | FrameNum | The frame’s number |
| bytes | VideoData | The codec’s packet, to the end of the tag: H263VIDEOPACKET, SCREENVIDEOPACKET, VP6SWFVIDEOPACKET, VP6SWFALPHAVIDEOPACKET or SCREENV2VIDEOPACKET |
H263VIDEOPACKET (Sorenson H.263)
Sorenson Spark is ITU-T H.263 with a shorter picture header, bit by bit:
| Type | Name | Description |
|---|---|---|
| UB[17] | PictureStartCode | Must be 1 |
| UB[5] | Version | 0 H.263 escape codes; 1 escape codes with a 7-bit or 11-bit level |
| UB[8] | TemporalReference | The frame number, modulo 256 |
| UB[3] | PictureSize | 0 8-bit width and height follow; 1 16-bit width and height follow; 2 352 × 288; 3 176 × 144; 4 128 × 96; 5 320 × 240; 6 160 × 120; 7 reserved |
| UB[8] or UB[16] | CustomWidth | If PictureSize is 0 or 1 |
| UB[8] or UB[16] | CustomHeight | If PictureSize is 0 or 1 |
| UB[2] | PictureType | 0 I (intra), 1 P (inter), 2 disposable P (not used for reference) |
| UB[1] | DeblockingFlag | Asks the player for its post-processing filter; not part of decoding |
| UB[5] | Quantizer | 1 to 31 |
| UB[1] | ExtraInformationFlag | Repeats with UB[8] ExtraInformation until it is 0 |
| MACROBLOCK[] | Macroblocks | Each 16 × 16 pixels, left to right, top to bottom |
| varies | PictureStuffing | The last field of SWF 19’s table, “See H.263 5.1.13”: H.263’s picture stuffing (PSTUF), zero bits that pad the packet to a byte boundary. SWF 19 says no more; that meaning is from H.263, whose text was not opened for this site. The explorer does not split it from the macroblocks |
The rest is plain H.263 macroblock syntax (ITU-T H.263). In a P picture a macroblock starts with a 1-bit COD (coded macroblock flag, 1 for a skipped macroblock); then MCBPC (macroblock type and chroma coded block pattern), CBPY (luma coded block pattern), DQUANT when the type has a quantiser change, one or four motion vector differences, and the blocks. Macroblocks are bit-packed, not byte-aligned.
In an I picture MCBPC is the intra table’s and there is no COD. A block is intra DC (UB[8], 255 meaning 128), then run-length-level TCOEF codes with an escape (for Version 0, last, run and a level of 8 or, escaped again, 11 bits as H.263; for Version 1 a flag selecting a 7-bit or 11-bit level). The explorer’s Show button on a VideoFrame lists every macroblock’s type, coded blocks, quantiser and motion vectors.
SCREENVIDEOPACKET (Screen video)
| Type | Name | Description |
|---|---|---|
| UB[4] | BlockWidth | The block width: (this + 1) × 16 pixels |
| UB[12] | ImageWidth | In pixels |
| UB[4] | BlockHeight | The block height: (this + 1) × 16 pixels |
| UB[12] | ImageHeight | In pixels |
| IMAGEBLOCK[] | ImageBlocks | Left to right, from the bottom row of blocks up |
An IMAGEBLOCK is a big-endian UI16 DataSize, then that many bytes of
zlib-compressed pixels (Data), 3 bytes a pixel in BGR order, from the
bottom row of the block up. A size of 0 means the block has not changed since the
last frame. In a real SWF the packet starts with one further byte that the
specification’s table does not list: FLV’s VIDEODATA byte, a 4-bit FrameType and a
4-bit CodecID. The explorer takes the byte when the size that follows it agrees with
DefineVideoStream.
SCREENV2VIDEOPACKET (Screen video 2)
The same BlockWidth, ImageWidth, BlockHeight and ImageHeight as SCREENVIDEOPACKET, then:
| Type | Name | Description |
|---|---|---|
| UB[6] | Reserved | 0 |
| UB[1] | HasIFrameImage | IFrameImage follows the blocks |
| UB[1] | HasPaletteInfo | PaletteInfo comes before the blocks |
| IMAGEBLOCK | PaletteInfo | If HasPaletteInfo: one block of data describing the palette |
| IMAGEBLOCKV2[] | ImageBlocks | Rows from the bottom left to the top right; key blocks and inter blocks mixed |
| IMAGEBLOCKV2[] | IFrameImage | If HasIFrameImage: inter blocks to be combined with the previous key blocks |
IMAGEBLOCKV2 is UB[16] DataSize (big-endian, the size of
everything after it; 0 for a block unchanged since the last key frame, with nothing
after it), then a Format byte (IMAGEFORMAT), then IMAGEDIFFPOSITION if
HasDiffBlocks is set (UI8 RowStart, the first row with data, and UI8
Height, the number of rows; the other rows come from the last key
frame), then IMAGEPRIMEPOSITION if ZlibPrimeCompressCurrent is set (UI8 block column
and UI8 block row of the priming source), then the zlib Data.
IMAGEFORMAT is UB[3] reserved, UB[2] ColorDepth (0 24-bit
B, G, R; 2 the 15/7-bit hybrid), UB[1] HasDiffBlocks, UB[1]
ZlibPrimeCompressCurrent and UB[1] ZlibPrimeCompressPrevious.
In the hybrid coding a byte with its top bit clear is an index into a 128-colour
palette; with it set, its low 7 bits and the next byte form a 15-bit RGB colour.
Without a palette in the stream the decoder uses the specification’s default palette
(its Appendix C), as the explorer does.
Some of this is not fully described. The specification does not give the palette’s layout inside PaletteInfo, or say how IFrameImage is combined, and of priming it says only that a block “was produced with the ZLIB priming technique”. FFmpeg’s decoder treats a primed block as a raw Deflate continuation whose dictionary is the same block of the last key frame, and rejects ZlibPrimeCompressCurrent, PaletteInfo and IFrameImage. The explorer does the same for the previous-frame case, takes the current-frame case to use the named block of this frame (untested, as no sample was available), and shows PaletteInfo and IFrameImage field by field. It stops drawing a packet that has an IFrameImage, naming the reason. From a packet that has a PaletteInfo it still draws the 24-bit blocks (ColorDepth 0), which need no palette, and names the others as not drawn.
VP6SWFVIDEOPACKET and VP6SWFALPHAVIDEOPACKET (On2 VP6)
Unlike FLV’s VP6 packets, these carry no size-adjustment byte. VP6SWFVIDEOPACKET is
the raw frame. VP6SWFALPHAVIDEOPACKET is a big-endian UI24 OffsetToAlpha,
then the colour frame of that many bytes, then the alpha frame: a second VP6 stream
of the same size whose luma plane gives the alpha channel.
The frame’s first byte is UB[1] FrameMode (0 key, 1 inter), UB[6] Qp and UB[1]
Marker (the explorer’s tree calls this bit SeparatedCoefficients, as FFmpeg
does: it says the DCT coefficients are in a second partition); a key frame adds UB[5]
Version, UB[2] Profile and UB[1] Interlaced, a big-endian
UI16 offset to the coefficient partition when Marker is set or Profile is 0, and UI8
rows, columns, display rows and display columns of macroblocks. The rest is boolean
(range) coded with probabilities that adapt from frame to frame, using two DCT
partitions, as On2’s published VP6 bitstream guide describes. Because of that, a
macroblock has no bit position in the file: the explorer’s Show button lists its type
and motion vectors without one.
H.264 (not in the specification)
The SWF specification defines no H.264 codec for DefineVideoStream, and H.264 normally reaches Flash Player through NetStream from FLV, F4V or MP4 files. A CodecID of 7 is not defined for SWF, so no layout of a DefineVideoStream H.264 frame is specified. The explorer assumes FLV’s AVCVIDEOPACKET, an assumption taken from FLV and not from any SWF file or document: UI8 AVCPacketType (0 sequence header, 1 NAL units, 2 end of sequence), SI24 CompositionTime, then data. It lists the NAL units on that assumption; it has no H.264 decoder, so such frames are not drawn.