wittydvd

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

WittyDVD

A DVD-Video engine in pure Go.
Plays a disc image the way a DVD player does: first-play, menus with highlighted buttons, titles, chapters and every command in between.

No cgo Fuzzed

Quick start · Command-line tool · Library · Design · DVD guide

Read-only mirror of modules/wittydvd in WittyMediaServer, where development happens. Please open issues and pull requests there.

WittyDVD is the DVD engine of WittyMediaServer, and a library and tool for anyone building a player. It is an original implementation of the public DVD-Video navigation model.

What it does

Capability Details
💿 Reads discs without mounting .iso/.img images (UDF and ISO 9660 bridge discs) and VIDEO_TS folders, through WittyDisc, which gives each file's byte ranges for a decoder such as FFmpeg
📋 Parses the disc's program VMG and VTS IFO tables: titles, program chains, programs and cells, menu languages, audio and sub-picture attributes, palettes, parental levels, regions
⚙️ Runs the disc's commands a virtual machine with 16 general and 24 system registers: links, jumps, calls, comparisons, arithmetic, the navigation timer
🧭 Navigates like a player first play, menus and titles, resume points, stills, menu loops, chapter skipping, and the title, root, audio, subtitle, angle and chapter menu keys
🔘 Reads NAV packs button positions, colours and links (PCI), cell timing and seamless branching (DSI), interleaved multi-angle cells
🖼️ Decodes sub-pictures menu highlights and subtitles rendered to RGBA with the disc's palette, cropped to the button or line
🔒 Refuses scrambled discs CSS-protected images are detected and refused; nothing is ever decrypted
🛠️ Diagnoses discs the wittydvd tool reports all of the above and simulates a run through the menus

What it leaves to the player: decoding the video and audio. WittyDVD tells a player which bytes to play, when, and what to draw over them.

Quick start

go install github.com/wittywilla/wittydvd/cmd/wittydvd@latest
wittydvd info SHREK_2.ISO

Needs Go 1.26 or newer; the tool lands in $(go env GOPATH)/bin. To use the library in your own program: go get github.com/wittywilla/wittydvd@latest.

The command-line tool

Command What it shows
wittydvd info <disc> titles, menus, languages and the first-play program
wittydvd walk <disc> [button…] simulates inserting the disc, then pressing menu buttons by number
wittydvd crawl <disc> presses every button of every menu and reports dead ends
wittydvd pgc <disc> fp|vmgm|vtsm|vts <vts> <pgcn> the commands of one program chain
wittydvd render <disc> <dir> the first menu's highlight pictures
wittydvd disc ls <disc> the files inside the image

The output holds no video or artwork, so it's safe to attach to a bug report. The same commands are built into WittyMediaServer as wms dvd ….

Using the library

import "github.com/wittywilla/wittydvd"

o, err := wittydvd.Open("SHREK_2.ISO")     // an image or a VIDEO_TS folder
if err != nil { return err }
defer o.Close()

nav := wittydvd.NewNav(o.Disc, wittydvd.NavOptions{})
step := nav.Start()                          // a menu, a title cell, or stop
for step.Kind != wittydvd.StepStop {
    switch step.Kind {
    case wittydvd.StepMenu:
        rd, _ := o.Reader(wittydvd.SpaceFor(step.Domain, step.VTS))
        pic, _ := wittydvd.ScanMenu(rd, step.FirstSector, step.LastSector,
            wittydvd.MenuScanOptions{Palette: step.Palette})
        _ = pic                              // buttons, rectangles, highlight artwork
        step = nav.PressButton(1, nil)
    case wittydvd.StepTitle:
        ext, _ := o.CellExtents(wittydvd.SpaceFor(step.Domain, step.VTS), step.Cell)
        _ = ext                              // play these byte ranges, then:
        step = nav.CellEnded()
    }
}
The navigator at a glance
Call Does
Start, CellEnded first play; what comes after a cell
PressButton, MenuKey, GoUp, OpenMenu menu interaction
PlayTitle, NextChapter, PrevChapter, Resume titles and chapters
SetAudio, SetSubpicture, SetAngle streams
Tick the navigation timer
Clone explore a disc without disturbing the live session
CellSubpictures, DecodeSPU, SPU.Render subtitles as images

Requirements: Go 1.26 or newer, no cgo. Its only dependency is WittyDisc.

Design

flowchart LR
  I[Disc image] --> D[WittyDisc<br/>UDF · ISO 9660]
  D --> P[ifo.go<br/>IFO parser]
  P --> N[nav.go + vm.go<br/>navigator + VM]
  N --> S{Step}
  S -->|menu| M[cell video + buttons<br/>menu.go · navpack.go · spu.go]
  S -->|title| T[cell video + subtitles<br/>subtitles.go]
File What it does
open.go opens images and folders; title summaries; readers for each VOB address space
ifo.go VMG and VTS IFO parsing
vm.go registers, instruction decoding, the interpreter
nav.go first play, menus, titles, resume, stills, keys
navpack.go, interleave.go NAV packs (PCI, DSI); cell ranges including multi-angle blocks
spu.go, menu.go, subtitles.go sub-pictures, menu buttons and highlights, subtitles
cli/ the command-line tool

Safe with untrusted discs: reads are size-bounded, malformed tables, commands and sub-pictures are refused rather than trusted, and the parsers are fuzz-tested.

The Witty family

Project Role
WittyMediaServer the media server these engines power
WittyDVD · WittyBluray the DVD and Blu-ray engines
WittyDisc disc image reader

Licence

Apache-2.0, the same licence as WittyMediaServer. © 2026 WittyWilla and contributors. Use, change and share it; if you redistribute it or build on it, keep the NOTICE attribution, “WittyDVD, developed by WittyWilla”, in your NOTICE file, documentation or About screen.

Documentation

Overview

Package dvd implements DVD-Video navigation: IFO parsing, the command virtual machine, the navigator state machine, NAV-pack (PCI/DSI) parsing and sub-picture (SPU) decoding for menu highlights.

It is written from the public DVD-Video structure (the same layout documented by libdvdread/libdvdnav) and never requires a mounted disc: the caller provides IFO bytes and sector-range readers.

Index

Constants

View Source
const (
	SprmMenuLang  = 0
	SprmAudio     = 1
	SprmSubp      = 2
	SprmAngle     = 3
	SprmTTN       = 4
	SprmVTSTTN    = 5
	SprmTTPGCN    = 6
	SprmPTTN      = 7
	SprmHLBTNN    = 8
	SprmNavTimer  = 9
	SprmNavPGCN   = 10
	SprmAudioMix  = 11
	SprmCountry   = 12
	SprmParental  = 13
	SprmVideoMode = 14
	SprmAudioCap  = 15
	SprmAudioLang = 16
	SprmAudioExt  = 17
	SprmSubpLang  = 18
	SprmSubpExt   = 19
	SprmRegion    = 20
)

SPRM indexes.

View Source
const MaxIFOBytes = 16 << 20

MaxIFOBytes bounds how much of an IFO we read.

View Source
const Sector = 2048
View Source
const VideoStreamID = 0x1e0

VideoStreamID is the MPEG-PS stream id of a DVD's video, as ffmpeg reports it.

Variables

View Source
var ErrBadIFO = errors.New("dvd: malformed IFO")
View Source
var ErrNoNav = errors.New("dvd: no NAV pack at cell start")
View Source
var ErrSPU = errors.New("dvd: malformed sub-picture")
View Source
var MenuTypes = map[string]int{"title": 2, "root": 3, "subpicture": 4, "audio": 5, "angle": 6, "chapter": 7}

MenuTypes maps menu names to the entry PGC menu type codes.

Functions

func PackScrambled

func PackScrambled(pack []byte) bool

PackScrambled reports CSS scrambling on the first PES of a pack.

func YCrCbToRGB

func YCrCbToRGB(y, cr, cb int) (r, g, b uint8)

YCrCbToRGB converts a DVD palette entry (ITU-R BT.601 limited range).

Types

type AudioAttr

type AudioAttr struct {
	Codec     string `json:"codec"`
	Language  string `json:"language,omitempty"`
	Channels  int    `json:"channels"`
	Extension int    `json:"extension"`
	AppMode   int    `json:"appMode"`
}

AudioAttr describes an audio stream.

func (AudioAttr) Purpose

func (a AudioAttr) Purpose() string

Purpose names an audio stream's code extension (empty for plain audio).

func (AudioAttr) StreamID

func (a AudioAttr) StreamID(n int) int

StreamID is the MPEG-PS stream id ffmpeg gives physical audio stream n of this format (0 when the format has no fixed id).

type Button

type Button struct {
	N           int     `json:"n"`
	Group       int     `json:"group"`
	X0, Y0      int     `json:"-"`
	X1, Y1      int     `json:"-"`
	Up, Down    int     `json:"-"`
	Left, Right int     `json:"-"`
	Auto        bool    `json:"auto"`
	Cmd         Command `json:"-"`
	ColorScheme int     `json:"-"`
	Select      Look    `json:"-"`
	Action      Look    `json:"-"`
}

Button is one highlight button from a PCI.

type ButtonGroup

type ButtonGroup struct {
	N    int    `json:"n"`
	Type int    `json:"type"`
	Mode string `json:"mode"` // normal | letterbox | panscan
}

ButtonGroup describes one of up to three button groups (per display mode).

type Cell

type Cell struct {
	BlockMode        int     `json:"blockMode"` // 0 normal, 1 first of angle block, 2 middle, 3 last
	BlockType        int     `json:"blockType"` // 1 = angle block
	Seamless         bool    `json:"seamless"`
	Interleaved      bool    `json:"interleaved"`
	STCDiscontinuity bool    `json:"stcDiscontinuity"`
	SeamlessAngle    bool    `json:"seamlessAngle"`
	Restricted       bool    `json:"restricted"`
	StillTime        int     `json:"stillTime"` // seconds, 0xff = infinite
	Command          int     `json:"command"`   // 1-based index into PGC cell commands, 0 none
	Duration         float64 `json:"durationSec"`
	FirstSector      uint32  `json:"firstSector"`
	FirstILVUEnd     uint32  `json:"firstIlvuEndSector"`
	LastVOBUStart    uint32  `json:"lastVobuStartSector"`
	LastSector       uint32  `json:"lastSector"`
	VOBID            int     `json:"vobId"`
	CellID           int     `json:"cellId"`
}

Cell is one cell of a PGC (cell playback info + position).

type CellSubs

type CellSubs struct {
	// BasePTM is the presentation time of the cell's first VOBU; unit PTS
	// minus BasePTM is the offset into the cell.
	BasePTM uint32
	Units   []SPUUnit
}

CellSubs are the sub-picture units of one cell, all streams.

type Command

type Command [8]byte

Command is one 8-byte VM instruction.

type DSI

type DSI struct {
	SCR     uint32
	LBN     uint32
	VOBUEnd uint32 // relative end address: VOBU spans LBN..LBN+VOBUEnd
	VOBID   int
	CellID  int
}

DSI is the parsed data search information of a NAV pack.

func ParseDSI

func ParseDSI(b []byte) *DSI

ParseDSI parses a DSI substream payload.

type Disc

type Disc struct {
	VMG *VMG
	VTS map[int]*VTS
}

Disc bundles the parsed IFOs of one DVD.

func (*Disc) MainTitle

func (d *Disc) MainTitle() *TitleSummary

MainTitle guesses the feature: the longest title.

func (*Disc) Region

func (d *Disc) Region() int

Region returns the lowest region number the disc allows (1-8), or 1 if all-region.

func (*Disc) Title

func (d *Disc) Title(number int) *TitleSummary

Title flattens one title by number.

func (*Disc) TitleAngle

func (d *Disc) TitleAngle(number, angle int) *TitleSummary

TitleAngle flattens a title for one camera angle (1-based); cells inside angle blocks are replaced by that angle's cell.

func (*Disc) Titles

func (d *Disc) Titles() []TitleSummary

Titles flattens every title (following PGC chains in program order).

type Domain

type Domain int

Domain of playback.

const (
	DomainFP Domain = iota
	DomainVMGM
	DomainVTSM
	DomainVTS
)

func (Domain) String

func (d Domain) String() string

type FileExtent

type FileExtent struct {
	File   string `json:"file"`
	Offset int64  `json:"offset"`
	Length int64  `json:"length"`
}

FileExtent is a byte range in a named file.

type Instr

type Instr struct {
	Raw     Command
	Type    int
	Invalid string
	// contains filtered or unexported fields
}

Instr is a decoded VM instruction.

func Decode

func Decode(c Command) Instr

Decode decodes one 8-byte command.

func (Instr) String

func (in Instr) String() string

String renders a human readable form (for diagnostics).

type Jump

type Jump struct {
	Op      JumpOp
	TTN     int
	PTTN    int
	Domain  Domain
	Menu    int // menu type for JumpSS/CallSS
	VTS     int
	PGCN    int
	HasPGCN bool
	RsmCell int
}

Jump is a decoded jump/call target.

func (*Jump) String

func (j *Jump) String() string

type JumpOp

type JumpOp int

JumpOp enumerates jump/call commands.

const (
	JumpNone JumpOp = iota
	JumpExit
	JumpTT
	JumpVTSTT
	JumpVTSPTT
	JumpSS
	CallSS
)

type LangUnit

type LangUnit struct {
	Language string     `json:"language"`
	Exists   int        `json:"exists"`
	PGCs     []PGCEntry `json:"pgcs"`
}

LangUnit is a menu language unit.

type Link struct {
	Op     LinkOp
	N      int // PGCN / PTTN / PGN / CN
	Button int // button to highlight (0 = unchanged)
}

Link is a decoded link target.

func (*Link) String

func (l *Link) String() string

type LinkOp

type LinkOp int

LinkOp enumerates link commands.

const (
	LinkNone LinkOp = iota
	LinkTopCell
	LinkNextCell
	LinkPrevCell
	LinkTopPG
	LinkNextPG
	LinkPrevPG
	LinkTopPGC
	LinkNextPGC
	LinkPrevPGC
	LinkGoUpPGC
	LinkTailPGC
	LinkRSM
	LinkPGCN
	LinkPTTN
	LinkPGN
	LinkCN
)

type Look

type Look struct {
	Color    [4]int
	Contrast [4]int
}

Look is a color+contrast table for pixel codes 0..3.

type MenuButton struct {
	N       int     `json:"n"`
	X0      int     `json:"x0"`
	Y0      int     `json:"y0"`
	X1      int     `json:"x1"`
	Y1      int     `json:"y1"`
	Up      int     `json:"up"`
	Down    int     `json:"down"`
	Left    int     `json:"left"`
	Right   int     `json:"right"`
	Auto    bool    `json:"auto"`
	Cmd     Command `json:"-"`
	CmdText string  `json:"cmd"`
	Select  *RGBA   `json:"-"`
	Action  *RGBA   `json:"-"`
	Inert   bool    `json:"inert,omitempty"` // no visible highlight and no command
}

MenuButton is a button in frame coordinates with its highlight artwork.

type MenuPicture struct {
	FrameW, FrameH int
	Aspect         float64 // 4/3 or 16/9
	Buttons        []MenuButton
	DefaultButton  int
	Normal         *RGBA // sub-picture as shown with nothing selected
	ButtonsFromSec float64
	HasHighlights  bool
	Scrambled      bool
	NoButtons      bool
	// ForcedSelect is the button the disc highlights when the menu appears
	// (FOSL_BTNN); it wins over SPRM8. 0 = none.
	ForcedSelect int
	// ForcedAction is the button the disc activates by itself when button
	// selection ends (FOAC_BTNN) at ActionAtSec into the cell. 0 = none.
	ForcedAction int
	ActionAtSec  float64
}

MenuPicture is everything a client needs to draw and operate a menu.

func ScanMenu

func ScanMenu(rd SectorReader, first, last uint32, o MenuScanOptions) (*MenuPicture, error)

ScanMenu finds the highlight information for the cell [first,last] by hopping NAV pack to NAV pack, then reads the surrounding VOBUs for the sub-picture that carries the button artwork.

func (p *MenuPicture) WithDefault(navButton int) *MenuPicture

WithDefault returns a copy whose DefaultButton follows the DVD rules: a forced selection first, then the navigator's SPRM8 highlight, then the first usable button.

type MenuScanOptions struct {
	Palette     [16]uint32
	Video       VideoAttr
	SubpControl *SubpControl // from the PGC, picks the SPU stream per display mode
	Wide        bool         // viewer wants 16:9 presentation
	NavButton   int          // SPRM8 highlight to prefer as default
	MaxHops     int
	ReadAhead   int // sectors to read once buttons are found
}

MenuScanOptions tune ScanMenu.

type Nav struct {
	Disc *Disc
	// contains filtered or unexported fields
}

Nav is a DVD navigator for one viewer.

func NewNav

func NewNav(d *Disc, o NavOptions) *Nav

NewNav creates a navigator over parsed IFOs.

func (n *Nav) CellEnded() *Step

CellEnded tells the navigator the shown cell (and still) finished.

func (n *Nav) Clone() *Nav

Clone returns an independent navigator in the same state (for what-if exploration such as `wms dvd crawl`).

func (n *Nav) Current() *Step

Current returns the last step.

func (n *Nav) GoUp() *Step

GoUp is the remote's RETURN key: follow the PGC's go-up link, or resume the title when there is none.

func (n *Nav) MenuKey(kind string) *Step

MenuKey handles the remote's TITLE / MENU (root) / etc. keys.

func (n *Nav) NavTimerFired() *Step

NavTimerFired handles SPRM9 expiry: jump to the PGC named in SPRM10.

func (n *Nav) NextChapter() *Step

NextChapter / PrevChapter move within the current title.

func (n *Nav) OpenMenu(kind string, vts int) *Step

OpenMenu starts the disc directly in one of its menus ("title" for the disc's title menu, or root/chapter/audio/subpicture/angle of title set vts). Discs that insist on running first-play before their menus fall back to a normal start.

func (n *Nav) PlayTitle(ttn, pttn int) *Step

PlayTitle jumps straight to a title (and optional chapter).

func (n *Nav) PressButton(btn int, cmd *Command) *Step

PressButton activates button n with its 8-byte command (from the PCI).

func (n *Nav) PrevChapter() *Step
func (n *Nav) Registers() *Registers

Registers exposes the live register file (read-only use recommended).

func (n *Nav) Resume() *Step

Resume returns to the title that called the menu.

func (n *Nav) SelectButton(btn int) *Step

SelectButton highlights button n without activating it.

func (n *Nav) SetAngle(a int)
func (n *Nav) SetAudio(stream int)

SetAudio / SetSubpicture / SetAngle change the viewer's streams.

func (n *Nav) SetSubpicture(stream int, on bool)
func (n *Nav) Start() *Step

Start runs first-play and returns what to show.

func (n *Nav) SyncTitleCell(pgcn, cellN int) bool

SyncTitleCell tells the navigator which cell of the current title the viewer has reached. Clients play a whole title as one stream, so without this the navigator would still think it is on the first cell when the viewer calls a menu (and Resume would restart from there).

func (n *Nav) Tick(seconds float64) *Step

Tick advances timers; returns a new step if the nav timer fired.

type NavOptions struct {
	RegisterOptions
}

NavOptions configure a navigator.

type NavPack struct {
	Sector uint32 // relative to the scan start
	PCI    *PCI
	DSI    *DSI
}

NavPack is the PCI+DSI found at the start of a VOBU.

type Opened

type Opened struct {
	Disc   *Disc
	Source Source
	Label  string
	Format string
	// contains filtered or unexported fields
}

Opened is a DVD ready for navigation and playback.

func Open

func Open(p string) (*Opened, error)

Open opens an ISO/IMG image or a VIDEO_TS directory.

func (*Opened) CellExtents

func (o *Opened) CellExtents(sp Space, c Cell) ([]FileExtent, error)

CellExtents maps a cell (following interleaving) onto file byte extents.

func (*Opened) CellRanges

func (o *Opened) CellRanges(sp Space, c Cell) ([]SectorRange, error)

CellRanges returns the sectors that belong to one cell. Ordinary cells are one contiguous range; interleaved cells are the VOBUs carrying their ids.

func (*Opened) CellSubpictures

func (o *Opened) CellSubpictures(sp Space, cell Cell) (*CellSubs, error)

CellSubpictures reads a cell once and returns its sub-picture units (cached per disc). The read is sequential in 1 MiB chunks; the cost is a single pass over the cell's bytes.

func (*Opened) Close

func (o *Opened) Close() error

Close releases the reader file handles and the source.

func (*Opened) Extents

func (o *Opened) Extents(sp Space) ([]FileExtent, error)

Extents returns the VOB address space extents (cached).

func (*Opened) Menu

func (o *Opened) Menu(sp Space, first, last uint32, opt MenuScanOptions) (*MenuPicture, error)

Menu scans a cell for its highlight information, caching the result per disc so revisiting a menu (or moving the highlight) never touches the disk.

func (*Opened) RangeExtents

func (o *Opened) RangeExtents(sp Space, first, last uint32) ([]FileExtent, error)

RangeExtents maps sectors [first,last] of a space onto file byte extents.

func (*Opened) Reader

func (o *Opened) Reader(sp Space) (SectorReader, error)

Reader returns a SectorReader over a space. Readers are shared and keep their file handles open until the disc is closed.

type PCI

type PCI struct {
	NavLBN         uint32
	VOBUStartPTM   uint32
	VOBUEndPTM     uint32
	HLStatus       int // 0 none, 1 new, 2 same, 3 same but commands differ
	HLStartPTM     uint32
	HLEndPTM       uint32
	SelectEndPTM   uint32
	Groups         []ButtonGroup
	ButtonCount    int
	FirstButton    int
	NumericButtons int
	ForcedSelect   int
	ForcedAction   int
	Buttons        []Button
	Schemes        [3]struct{ Select, Action Look }
}

PCI is the parsed presentation control information of a NAV pack.

func ParsePCI

func ParsePCI(b []byte) *PCI

ParsePCI parses a PCI substream payload.

type PGC

type PGC struct {
	Duration     float64          `json:"durationSec"`
	Programs     []int            `json:"programs"` // entry cell number (1-based) per program
	Cells        []Cell           `json:"cells"`
	AudioControl [8]int           `json:"audioControl"` // stream number or -1
	SubpControl  [32]*SubpControl `json:"-"`
	Palette      [16]uint32       `json:"palette"` // 0x00YYCrCb
	UOPs         uint32           `json:"uops"`
	NextPGCN     int              `json:"nextPgcn"`
	PrevPGCN     int              `json:"prevPgcn"`
	GoUpPGCN     int              `json:"goUpPgcn"`
	StillTime    int              `json:"stillTime"`
	PlaybackMode int              `json:"playbackMode"`
	Pre          []Command        `json:"-"`
	Post         []Command        `json:"-"`
	CellCmds     []Command        `json:"-"`
}

PGC is a program chain.

func (*PGC) SetsHighlight

func (p *PGC) SetsHighlight() bool

SetsHighlight reports whether the PGC's pre-commands select a button (SetHL_BTNN) before its cells play, the mark of an interactive screen inside a title (voting, games). Links that merely carry a button number for the menu the title returns to (common at the end of features) don't count.

type PGCEntry

type PGCEntry struct {
	Entry       bool `json:"entry"`
	TitleNumber int  `json:"titleNumber"` // VTS title number (title domain)
	MenuType    int  `json:"menuType"`    // menu domain: 2 title,3 root,4 subp,5 audio,6 angle,7 chapter
	BlockMode   int  `json:"blockMode"`
	BlockType   int  `json:"blockType"`
	PGC         *PGC `json:"-"`
}

PGCEntry is a PGCIT row: a PGC plus its category.

type PTT

type PTT struct {
	PGCN int `json:"pgcn"`
	PGN  int `json:"pgn"`
}

PTT is one chapter entry: PGC number and program number.

type PackScanner

type PackScanner struct {
	Out *StreamScan
	// Streams limits SPU collection to these sub-picture stream numbers
	// (bit n = stream n); 0 collects every stream.
	Streams uint32
	// NoNav skips PCI/DSI parsing except for the first NAV pack.
	NoNav bool
	// contains filtered or unexported fields
}

PackScanner walks MPEG-PS packs incrementally and pulls out NAV packs and complete SPU units. Units may span calls to Feed, so a long cell can be read in chunks without holding it all in memory.

func NewPackScanner

func NewPackScanner() *PackScanner

NewPackScanner returns a scanner with an empty result.

func (*PackScanner) Feed

func (ps *PackScanner) Feed(buf []byte, firstSector uint32)

Feed scans whole sectors of buf; firstSector labels the results.

type RGBA

type RGBA struct {
	X, Y          int
	Width, Height int
	Pix           []byte // 4 bytes per pixel
}

RGBA is a premultiplied-free 8-bit RGBA bitmap.

func (*RGBA) Crop

func (r *RGBA) Crop() *RGBA

Crop returns the bitmap trimmed to its visible pixels (zero size when nothing is visible). Subtitle units usually cover the whole frame.

func (*RGBA) Opaque

func (r *RGBA) Opaque() bool

Opaque reports whether any pixel is visible.

type RegisterOptions

type RegisterOptions struct {
	MenuLanguage     string
	AudioLanguage    string
	SubtitleLanguage string
	Region           int // 1-8
	Angle            int // initial camera angle (0 = 1)
	Rand             func() float64
}

RegisterOptions seeds player preferences.

type Registers

type Registers struct {
	GPRM    [16]uint16
	Counter [16]bool // GPRM counter mode (increments once per second)
	SPRM    [24]uint16

	Rand func() float64
	// contains filtered or unexported fields
}

Register file of the DVD virtual machine.

func NewRegisters

func NewRegisters(o RegisterOptions) *Registers

NewRegisters builds a register file with spec defaults.

func (*Registers) Clone

func (r *Registers) Clone() *Registers

Clone copies the register file.

func (*Registers) Run

func (r *Registers) Run(cmds []Command, o RunOptions) Result

Run executes a command list against the registers.

func (*Registers) Tick

func (r *Registers) Tick(seconds float64) bool

Tick advances the wall clock: counter GPRMs increment, the navigation timer counts down. Returns true when the nav timer just expired.

type Result

type Result struct {
	Kind   ResultKind
	Link   *Link
	Jump   *Jump
	Reason string
	Steps  int
}

Result of running a command list.

type ResultKind

type ResultKind int

ResultKind says how a command list ended.

const (
	ResultEnd   ResultKind = iota // ran off the end
	ResultBreak                   // Break
	ResultExit                    // Exit
	ResultLink
	ResultJump
	ResultStop // invalid command / runaway
)

type RunOptions

type RunOptions struct {
	Start int  // 0-based first instruction
	Once  bool // run exactly one instruction (cell commands, button commands)
}

RunOptions tune Run.

type SPU

type SPU struct {
	X, Y          int
	Width, Height int
	Pixels        []byte // one code (0..3) per pixel
	Color         [4]int
	Contrast      [4]int
	Forced        bool
	StartSec      float64
	StopSec       float64 // <0 when absent
	Truncated     bool
}

SPU is a decoded sub-picture: a 2-bit indexed bitmap plus its default look.

func DecodeSPU

func DecodeSPU(unit []byte) (*SPU, error)

DecodeSPU decodes one sub-picture unit.

func (*SPU) Render

func (s *SPU) Render(palette [16]uint32, look *Look) *RGBA

Render paints the whole SPU with the given look (nil look = the SPU's own).

func (*SPU) RenderRect

func (s *SPU) RenderRect(palette [16]uint32, look *Look, x0, y0, x1, y1 int) *RGBA

RenderRect paints the part of the SPU inside the given frame rectangle (inclusive, frame coordinates) with the look. Pixels outside the SPU stay transparent. Result coordinates are the clipped rectangle.

type SPUUnit

type SPUUnit struct {
	Stream int
	Sector uint32
	PTS    int64
	Bytes  []byte
}

SPUUnit is a complete sub-picture unit with its presentation time.

type SectorRange

type SectorRange struct{ First, Last uint32 }

SectorRange is an inclusive run of sectors in a VOB address space.

type SectorReader

type SectorReader interface {
	ReadSectors(first uint32, count int) ([]byte, error)
}

SectorReader reads sectors of a VOB address space (menu VOB or the concatenated title VOBs of a title set).

type Source

type Source interface {
	ReadIFO(name string) ([]byte, error)
	// VOBExtents returns the byte extents (in the backing file(s)) of the VOB
	// address space, in order. Each extent names its file.
	VOBExtents(sp Space) ([]FileExtent, error)
	Close() error
	Describe() string
}

Source abstracts an ISO image or a VIDEO_TS folder.

type Space

type Space struct {
	Domain Domain
	VTS    int
}

Space names a VOB address space.

func SpaceFor

func SpaceFor(domain Domain, vts int) Space

SpaceFor maps a step to its VOB address space.

type Step

type Step struct {
	Kind          StepKind   `json:"kind"`
	Domain        Domain     `json:"-"`
	DomainName    string     `json:"domain"`
	VTS           int        `json:"vts"`
	PGCN          int        `json:"pgcn"`
	CellN         int        `json:"cellN"`
	FirstSector   uint32     `json:"firstSector"`
	LastSector    uint32     `json:"lastSector"`
	StillSec      float64    `json:"stillSec"` // +Inf = wait for the viewer
	Loop          bool       `json:"loop"`
	Palette       [16]uint32 `json:"palette"`
	DefaultButton int        `json:"defaultButton"`
	Serial        int        `json:"serial"`
	Reason        string     `json:"reason,omitempty"`
	Hold          bool       `json:"hold,omitempty"`
	Resumed       bool       `json:"resumed,omitempty"`
	Title         *TitleInfo `json:"title,omitempty"`
	CellDuration  float64    `json:"cellDurationSec"`
}

Step is the navigator's instruction to the presentation layer.

type StepKind

type StepKind string

StepKind is what the navigator wants shown.

const (
	StepMenu  StepKind = "menu"
	StepTitle StepKind = "title"
	StepStop  StepKind = "stop"
)

type StreamScan

type StreamScan struct {
	Navs      []NavPack
	SPUs      []SPUUnit
	Scrambled bool
}

StreamScan is the result of scanning a run of VOB sectors.

func ScanSectors

func ScanSectors(buf []byte, firstSector uint32) *StreamScan

ScanSectors walks MPEG-PS packs and pulls out NAV packs and SPU units. firstSector is only used to label results.

type SubpAttr

type SubpAttr struct {
	Language  string `json:"language,omitempty"`
	Extension int    `json:"extension"`
}

SubpAttr describes a sub-picture stream.

func (SubpAttr) Purpose

func (s SubpAttr) Purpose() string

Purpose names a sub-picture stream's code extension.

type SubpControl

type SubpControl struct {
	Narrow, Wide, Letterbox, PanScan int
}

SubpControl says which sub-picture stream to use per display mode.

type TitleCell

type TitleCell struct {
	PGCN  int
	CellN int
	Cell  Cell
	Start float64
}

TitleCell is one cell of a flattened title with its PGC.

type TitleInfo

type TitleInfo struct {
	TTN      int     `json:"ttn"`
	VTSTTN   int     `json:"vtsTtn"`
	PTTN     int     `json:"pttn"`
	Cells    []Cell  `json:"-"`
	CellNums []int   `json:"cellNums"`
	Duration float64 `json:"durationSec"`
}

TitleInfo describes the title being played in a title step.

type TitleSearch

type TitleSearch struct {
	Number    int `json:"number"`
	VTS       int `json:"vts"`
	VTSTitle  int `json:"vtsTitle"`
	Angles    int `json:"angles"`
	Chapters  int `json:"chapters"`
	Parental  int `json:"parental"`
	PlayType  int `json:"playType"`
	VTSSector uint32
}

TitleSearch is one TT_SRPT row.

type TitleSummary

type TitleSummary struct {
	Number   int         `json:"number"`
	VTS      int         `json:"vts"`
	VTSTitle int         `json:"vtsTitle"`
	Duration float64     `json:"durationSec"`
	Chapters []float64   `json:"chapters"` // chapter start offsets in seconds
	Angles   int         `json:"angles"`
	Audio    []AudioAttr `json:"audio"`
	Subp     []SubpAttr  `json:"subtitles"`
	Video    VideoAttr   `json:"video"`
	Cells    []TitleCell `json:"-"`
}

TitleSummary is a flattened view of one title.

type VMG

type VMG struct {
	Version      int
	RegionMask   int // bit set = region prohibited
	NumTitleSets int
	Provider     string
	FirstPlay    *PGC
	Titles       []TitleSearch
	Menus        []LangUnit
	MenuVideo    VideoAttr
	MenuAudio    []AudioAttr
	MenuSubp     []SubpAttr
	MenuVOBSec   uint32
}

VMG is VIDEO_TS.IFO.

func ParseVMG

func ParseVMG(b []byte) (*VMG, error)

ParseVMG parses VIDEO_TS.IFO.

type VTS

type VTS struct {
	Number      int
	Version     int
	Menus       []LangUnit
	PGCs        []PGCEntry
	PTT         [][]PTT // per VTS title (1-based title - 1)
	MenuVideo   VideoAttr
	MenuAudio   []AudioAttr
	MenuSubp    []SubpAttr
	Video       VideoAttr
	Audio       []AudioAttr
	Subp        []SubpAttr
	MenuVOBSec  uint32
	TitleVOBSec uint32
}

VTS is VTS_xx_0.IFO.

func ParseVTS

func ParseVTS(b []byte, number int) (*VTS, error)

ParseVTS parses VTS_xx_0.IFO.

type VideoAttr

type VideoAttr struct {
	MPEG        int    `json:"mpeg"`
	Standard    string `json:"standard"` // ntsc | pal
	Wide        bool   `json:"wide"`     // 16:9
	Letterbox   bool   `json:"letterbox"`
	PictureSize int    `json:"pictureSize"`
	PermittedDF int    `json:"permittedDf"`
}

VideoAttr describes a video stream.

func (VideoAttr) Size

func (a VideoAttr) Size() (int, int)

Width/Height of the coded picture.

Directories

Path Synopsis
cmd
wittydvd command
Command wittydvd inspects DVD-Video images and VIDEO_TS folders with the WittyDVD engine: titles, menus and languages, the disc's program, a simulated run through its menus, and the menu artwork.
Command wittydvd inspects DVD-Video images and VIDEO_TS folders with the WittyDVD engine: titles, menus and languages, the disc's program, a simulated run through its menus, and the menu artwork.

Jump to

Keyboard shortcuts

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