smk

package module
v0.0.0-...-dabb4d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2018 License: Unlicense Imports: 5 Imported by: 0

Documentation

Overview

Package smk implements decoding of Smacker video files.

File format reference:

https://wiki.multimedia.cx/index.php?title=Smacker

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// File header.
	FileHeader
	// contains filtered or unexported fields
}

A File is a container of Smacker video and audio tracks.

func Parse

func Parse(r io.Reader) (*File, error)

Parse returns a new File for accessing the video and audio tracks of r.

It reads and parses the Smacker file header, the frame size and type information, and the Huffman decoding tables, but skips all frame data.

func ParseFile

func ParseFile(path string) (*File, error)

ParseFile returns a new File for accessing the video and audio tracks of path.

It reads and parses the Smacker file header, the frame size and type information, and the Huffman decoding tables, but skips all frame data.

func (*File) Close

func (f *File) Close() error

Close closes the underlying reader if it implements io.Closer, and performs no operation otherwise.

type FileHeader

type FileHeader struct {
	// File signature; "SMK2" or "SMK4".
	Signature string `struc:"[4]byte"`
	// Frame width.
	Width int `struc:"uint32,little"`
	// Frame height.
	Height int `struc:"uint32,little"`
	// Number of frames. Excluding "ring" frames.
	NFrames int `struc:"uint32,little"`
	// Frame rate.
	FrameRate FrameRate `struc:"int32,little"`
	// Video flags.
	Flags Flag
	// Size of the largest unpacked audio data buffer in bytes; one per track.
	AudioSize [7]int `struc:"[7]uint32,little"`
	// Total size in bytes of Huffman trees stored in file.
	TreesSize int `struc:"uint32,little"`
	// Allocation size for the mono blocks maps Huffman tree.
	MMapSize int `struc:"uint32,little"`
	// Allocation size for the mono blocks colours Huffman tree.
	MClrSize int `struc:"uint32,little"`
	// Allocation size for the full blocks Huffman tree.
	FullSize int `struc:"uint32,little"`
	// Allocation size for the block type descriptors Huffman tree.
	TypeSize int `struc:"uint32,little"`
	// Frequency and format information for each sound track; one per track.
	// TODO: Verify if little or big endian encoding.
	TrackInfo [7]TrackInfo `struc:"[7]uint32,little"`

	// Frame size in number of bytes. Bit 0 determines if the frame is a key
	// frame. The purpose of bit 1 is unknown. Note, to get the proper length,
	// clear bit 0 and 1.
	FrameSizes []int `struc:"[]uint32,little,sizefrom=NFrames"`
	// Frame types.
	FrameTypes []FrameType `struc:"sizefrom=NFrames"`
	// contains filtered or unexported fields
}

FileHeader is a general file description header.

type Flag

type Flag uint32

Flag specifies a set of video flags.

type FrameRate

type FrameRate int32

FrameRate specifies the number of frames per second.

The frame rate can be determined as follows:

if (FrameRate > 0) {
   fps = 1000 / FrameRate
} else if (FrameRate < 0) {
   fps = 100000 / (-FrameRate)
} else {
   fps = 10
}

func (FrameRate) FPS

func (rate FrameRate) FPS() float64

FPS returns the frame rate in frames per second.

type FrameType

type FrameType uint8

FrameType describes the contents of the corresponding frame.

The 8 bits have the following meaning when set:

7 - frame contains audio data corresponding to track 6
6 - frame contains audio data corresponding to track 5
5 - frame contains audio data corresponding to track 4
4 - frame contains audio data corresponding to track 3
3 - frame contains audio data corresponding to track 2
2 - frame contains audio data corresponding to track 1
1 - frame contains audio data corresponding to track 0
0 - frame contains a palette record
const (
	FrameTypePaletteRecord FrameType = 1 << iota
	FrameTypeAudioDataTrack0
	FrameTypeAudioDataTrack1
	FrameTypeAudioDataTrack2
	FrameTypeAudioDataTrack3
	FrameTypeAudioDataTrack4
	FrameTypeAudioDataTrack5
	FrameTypeAudioDataTrack6
)

Frame types.

type TrackInfo

type TrackInfo uint32

TrackInfo describes the frequency and format information of a sound track.

The 32 constituent bits have the following meaning:

bit 31 - data is compressed
bit 30 - indicates that audio data is present for this track
bit 29 - 1 = 16-bit audio; 0 = 8-bit audio
bit 28 - 1 = stereo audio; 0 = mono audio
bits 27-26 - if both set to zero - use v2 sound decompression
bits 25-24 - unused
bits 23-0 - audio sample rate

func (TrackInfo) BitRate

func (info TrackInfo) BitRate() int

BitRate returns the bit rate of the audio data of the track.

func (TrackInfo) HasAudioData

func (info TrackInfo) HasAudioData() bool

HasAudioData reports whether the audio data of the track is present.

func (TrackInfo) IsCompressed

func (info TrackInfo) IsCompressed() bool

IsCompressed reports whether the audio data of the track is compressed.

func (TrackInfo) IsVersion2

func (info TrackInfo) IsVersion2() bool

IsVersion2 reports whether the audio data of the track is stored using v2 sound compression.

func (TrackInfo) NChannels

func (info TrackInfo) NChannels() int

NChannels returns the number of channels used by the track.

func (TrackInfo) SampleRate

func (info TrackInfo) SampleRate() int

SampleRate returns the audio sample rate of the track.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL