bik

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bik reads RAD Game Tools Bink (.bik) video headers — the cutscene format TA: Kingdoms uses in place of the Smacker (.zrb) videos shipped with the original Total Annihilation.

Like the smacker package, this reader parses the container header natively (geometry, frame counts, frame rate, audio tracks) but does not decode the compressed video bitstream: Bink uses a proprietary DCT-based codec with no open-source encoder. Pixel decoding and conversion are delegated to FFmpeg, which ships a Bink 1 decoder (binkvideo + binkaudio_dct/rdft). Because no Bink encoder exists outside RAD's own tools, conversion is decode-only — the reverse of smacker.ConvertFromMP4 is intentionally absent.

Index

Constants

View Source
const HeaderMinSize = 44

HeaderMinSize is the smallest valid Bink header (no audio tracks): the 44-byte fixed prefix up to and including the audio-track count.

Variables

This section is empty.

Functions

func ConvertToMP4

func ConvertToMP4(bikPath, mp4Path string) error

ConvertToMP4 decodes a Bink video to MP4 using FFmpeg, which ships a native Bink 1 decoder (binkvideo plus binkaudio_dct/binkaudio_rdft). The encode settings mirror the Smacker converter: visually-lossless H.264 (CRF 18) and high-fidelity AAC audio.

func FFmpegAvailable

func FFmpegAvailable() bool

FFmpegAvailable reports whether an ffmpeg binary is on the PATH.

Types

type AudioTrack

type AudioTrack struct {
	SampleRate int    // samples per second
	Channels   int    // 1 (mono) or 2 (stereo)
	Bits       int    // 8 or 16
	Codec      string // "DCT" or "RDFT"
	ID         uint32 // track identifier from the trailing ID table
}

AudioTrack describes one Bink audio stream.

type Header struct {
	Revision     byte // the 4th signature byte: 'b','d','f','g','h','i','k', …
	FileSize     uint32
	Frames       uint32
	LargestFrame uint32
	Width        uint32
	Height       uint32
	FPSNum       uint32
	FPSDen       uint32
	VideoFlags   uint32
	AudioTracks  []AudioTrack
}

Header holds the parsed fields of a Bink container header.

func ReadHeader

func ReadHeader(r io.Reader) (*Header, error)

ReadHeader parses a Bink header from r. It reads only as far as the audio track tables; the per-frame index and the compressed bitstream are left untouched.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader wraps an open Bink file and its parsed header.

func OpenReader

func OpenReader(path string) (*Reader, error)

OpenReader opens a Bink video file and parses its header.

func (*Reader) Close

func (r *Reader) Close() error

Close releases the underlying file handle.

func (*Reader) Duration

func (r *Reader) Duration() float64

Duration returns the playback length in seconds.

func (*Reader) FrameCount

func (r *Reader) FrameCount() int

FrameCount returns the number of video frames.

func (*Reader) FrameRate

func (r *Reader) FrameRate() float64

FrameRate returns the frame rate in frames per second. Bink stores the rate as a numerator/denominator pair, so the result can be fractional.

func (*Reader) HasAlpha

func (r *Reader) HasAlpha() bool

HasAlpha reports whether frames carry an alpha plane.

func (*Reader) HasAudio

func (r *Reader) HasAudio() bool

HasAudio reports whether the file carries at least one audio track.

func (*Reader) Header

func (r *Reader) Header() *Header

Header returns the parsed header.

func (*Reader) Height

func (r *Reader) Height() int

Height returns the video height in pixels.

func (*Reader) Info

func (r *Reader) Info() string

Info returns a formatted multi-line summary of the header.

func (*Reader) IsGrayscale

func (r *Reader) IsGrayscale() bool

IsGrayscale reports whether frames are luma-only.

func (*Reader) Version

func (r *Reader) Version() string

Version returns a human-readable codec/revision label.

func (*Reader) Width

func (r *Reader) Width() int

Width returns the video width in pixels.

Jump to

Keyboard shortcuts

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