wittydvd

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

WittyDVD

Plays DVD images and VIDEO_TS folders in WittyMediaServer the way a DVD player does, with their real menus. You need it if your disc libraries hold DVDs.

A DVD's own animated menu in a browser

The disc's own menu, in a browser. Sintel, Blender Foundation, CC BY 3.0, from its original DVD.

A disc's page

A disc's page in WittyMediaServer. Sintel, Blender Foundation, CC BY 3.0.

A disc in the tray

A disc going in. Sintel, Blender Foundation, CC BY 3.0.

The Playback and discs page in Settings

Settings, Playback & discs, in WittyMediaServer.

What it does

  • Plays the disc's own program: first play, menus with highlighted buttons, titles, chapters, angles, audio and subtitle choices, stills, resume points and parental blocks. It runs the disc's commands in a small virtual machine.
  • Reads without mounting: .iso and .img images and VIDEO_TS folders, through WittyDisc.
  • Draws subtitles and button highlights from the disc's own sub-pictures and palette.
  • Copes with damage: a broken IFO table is read from its .BUP backup, and malformed tables, commands and sub-pictures are refused rather than trusted.
  • Refuses scrambled discs. CSS-protected images are detected and refused with a clear message. Nothing is ever decrypted. The server makes its own check as well, whatever a module says.
  • Tells you what's on a disc. The wittydvd command-line tool lists titles and menus, simulates a run through the menus, and reports dead ends.

Decoding the video and audio is left to the player: WittyDVD says which bytes to play, when, and what to draw over them. Turning those steps into streams stays with the server.

How to use it is in Help inside WittyMediaServer: see DVDs.

How to get it

An admin adds it from the module store inside WittyMediaServer: Settings → Modules, then Browse the store, then Add beside WittyDVD. That needs WittyMediaServer 0.6.0-alpha or later, and it works with nothing older. The range this version fits is in module.json: 0.6.0-alpha through 0.6.x.

What it needs

  • FFmpeg, which comes with the server.
  • WittyDisc, which reads the images, and WittyModule, which is how a server talks to it. Both are built in.
  • No media comes with it.

It's written in Go with no cgo, from the published disc structure.

Platforms

A program is built for each system below, and the server uses the right one.

System Where it stands
Linux (x64, arm64, 32-bit ARM, x86) Its tests pass on x64, and a DVD title has played in a browser from a test server with it installed. The other CPUs are only built
Windows (x64, arm64) Built. This version hasn't been run on Windows since it became its own program
macOS (Intel, Apple silicon) Built by the release tool. It has not been run on a real Mac
FreeBSD (amd64, arm64) Cross-compiled only. It has not been run

On macOS and FreeBSD the server has no sandbox for a module's helper: it gets a small environment and a soft memory limit, and nothing more.

Building and testing

You need Go 1.26 or newer. In a worktree, first run the copy of dev-modules.mjs kept above the repositories (node D:/projects/dev-modules.mjs on the development machine). It writes a go.work that git ignores, so the checkout builds against the repositories beside it. Never run go work use.

go vet ./...
go test ./... -count=1
go run github.com/wittywilla/wittymodule/cmd/wittymodule check .

The last one checks the manifest. On the same tool, pack -targets linux/amd64 -out release . builds a release for one system. CI also builds for every system.

To look at a disc by hand:

go run ./cmd/wittydvd info MY_DISC.ISO
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 or 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

To use it as a library, wittydvd.Open opens an image or folder, and wittydvd.NewNav gives a navigator: Start, PressButton, CellEnded and the rest return what to do next.

wittydvdplayer/ is the same engine as a program of its own for WittyMediaPlayer, with its own go.mod and manifest.

Licence

Apache-2.0: see LICENSE and NOTICE. If you redistribute it or build on it, keep the NOTICE attribution. It's an original implementation and contains no code from other disc libraries. Each release archive carries a THIRD-PARTY-NOTICES.txt for what its programs link.

WittyDVD is an independent open-source project. It isn't associated with, sponsored by or endorsed by the DVD format's owners, any film studio or any other player project. “DVD” is a trademark of DVD Format/Logo Licensing Corporation; WittyDVD isn't a licensed or certified DVD product and uses no DVD logo. CSS-scrambled discs are refused, nothing is decrypted, and no media comes with it: you're responsible for having the rights to what you open. Any third-party names here only describe what it works with, and belong to their owners. It's provided “as is”, with no warranty; see LICENSE. Local law applies to how you use it. This isn't legal advice.

Releasing

A version tag builds a program for every platform, signs the checksum list, and publishes a release that servers can install.

Versions move in small steps as work lands. go run github.com/wittywilla/wittymodule/cmd/wittymodule@v0.3.0 bump . raises it everywhere it is written (add -part minor for a bigger step). A bump isn't a release: nothing is tagged or published until you tag it. CI fails when code changed since the last tag and the version didn't, because tags never move.

To release:

  1. Check that version in module.json is the one to publish, with the bump committed.
  2. Tag that commit and push the tag: git tag vX.Y.Z, then git push origin vX.Y.Z. A tag with a suffix, such as v1.2.0-beta, is published as a prerelease.
  3. Watch the Actions tab. The signing step uses the WMS_SIGNING_KEY secret of the release environment, and nothing is published without it.

To take a version back, run the withdraw workflow from the Actions tab. It adds the version to a signed list on the release tagged withdrawals, which servers read.

Licensed under Apache-2.0: see LICENSE and NOTICE.

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 ManifestJSON []byte

ManifestJSON is this module's manifest (docs/MODULES.md, "The manifest").

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) Karaoke added in v0.3.0

func (a AudioAttr) Karaoke() bool

Karaoke says the stream is a karaoke mix: backing on the front channels, the guide melody and vocals on the others.

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 ColConColumn added in v0.3.0

type ColConColumn struct {
	Column   int
	Color    [4]int
	Contrast [4]int
}

ColConColumn is one pixel-control entry of a CHG_COLCON line range.

type ColConLines added in v0.3.0

type ColConLines struct {
	FirstLine, LastLine int
	Columns             []ColConColumn
}

ColConLines is one CHG_COLCON line range: from each column rightwards (to the next one) pixels take that entry's colours and contrasts.

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
	// FirstRefEnd is the relative end of the VOBU's first reference
	// picture; 0 when the VOBU carries no video at all (audio-only VOBUs
	// after a cell's picture has ended).
	FirstRefEnd uint32
	VOBID       int
	CellID      int
	// NoVideoAhead is set when the VOBU search information says no later
	// VOBU of the cell carries video (sri_nvwv = 0xbfffffff).
	NoVideoAhead bool
}

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 title with the most distinct video. Structural copy protection adds decoy titles that replay the feature's cells many times over or in scrambled order, and cells that point outside the title VOB; counting each cell once, skipping junk cells and preferring the title that plays its cells in disc order picks the real one.

func (*Disc) ParentalMask added in v0.3.0

func (d *Disc) ParentalMask(country uint16, level, vts int) uint16

ParentalMask is the parental ID mask PTL_MAIT gives title set vts for a country (SPRM12) and parental level (SPRM13). Without parental control (level 15) the player acts at level 8, which permits everything; a country the table does not list uses the first entry. 0 means the disc has no table.

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
	// ButtonsUntilSec is when the buttons stop working, measured like
	// ButtonsFromSec: the earlier of the highlight end (HLI_E_PTM) and the
	// end of button selection (BTN_SL_E_PTM). 0 = until the cell ends.
	ButtonsUntilSec 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.

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) StepPGC(st *Step) *PGC

StepPGC returns the program chain a step plays, resolved the way the navigator does (menu language unit, first play).

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.

func (*Opened) TitleRuns added in v0.3.0

func (o *Opened) TitleRuns(sp Space, cells []TitleCell) ([]TitleRun, error)

TitleRuns groups the cells of a title (see Disc.Title) into runs. Cells join a run when they follow each other on the disc in one VOB and their times carry on; interleaved cells (angles, seamless branching) and anything the disc marks as a new time base stand alone.

type PCI

type PCI struct {
	NavLBN       uint32
	VOBUStartPTM uint32
	VOBUEndPTM   uint32
	// SeqEndPTM is the end of the video when this VOBU ends a video
	// sequence (sequence_end_code): a still picture the player holds.
	SeqEndPTM      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"`   // parental block: 1 first, 2 middle, 3 last
	BlockType   int  `json:"blockType"`   // 1 = parental block (alternative versions of a scene)
	// ParentalMask names the parental IDs this PGC is for; inside a parental
	// block the player plays the PGC whose mask matches PTL_MAIT for its level.
	ParentalMask int  `json:"parentalMask"`
	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 ParentalCountry added in v0.3.0

type ParentalCountry struct {
	Country string
	Masks   [8][]uint16
}

ParentalCountry is one country's parental management masks: Masks[level-1] holds one parental ID mask for the VMG (index 0) and each title set.

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
	Parental         int    // 1-8; 0 = no limit
	Country          string // two letters; "" = US
	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
	// ColCon are CHG_COLCON regions: other colours and contrasts for parts
	// of the picture (karaoke wipes, two-colour subtitles, menu artwork).
	ColCon    []ColConLines
	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 as it first appears: the state at its first start-display command (or, for units that never start, the state they leave), with StopSec the time it next changes or stops.

func DecodeSPUFrames added in v0.3.0

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

DecodeSPUFrames decodes every picture a sub-picture unit shows over time. A unit carries a chain of display control sequences, each applied at its own delay: subtitles that change colour, move, blink or show another part of the bitmap come out as one SPU per state, each with its own start and stop time (StopSec < 0: shown until the next unit replaces it).

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.

With the SPU's own look, CHG_COLCON regions recolour their part of the picture; a button's look (a highlight) replaces them inside the button.

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 TitleRun added in v0.3.0

type TitleRun struct {
	Extents []FileExtent
	// Duration is how long the run plays, in seconds.
	Duration float64
	// StartPTS is the presentation time of its first picture (90 kHz); 0 when
	// the disc doesn't say.
	StartPTS uint32
	// Lead is how long before its first picture the run's earliest packet lies,
	// in seconds: the sound stored ahead of the picture (see scanLead).
	Lead float64
	// FirstCell and Cells say which of the given cells it plays.
	FirstCell, Cells int
}

TitleRun is a stretch of a title that can be read straight through.

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
	// MenuVOBSectors is the size of VIDEO_TS.VOB in sectors according to
	// the IFO (0 when the IFO does not say).
	MenuVOBSectors uint32
	// Parental is the parental management table (PTL_MAIT), per country.
	Parental []ParentalCountry
}

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
	// Sizes of the menu and title VOBs in sectors according to the IFO
	// (0 when unknown). Cells that start beyond them are junk.
	MenuVOBSectors  uint32
	TitleVOBSectors 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.
wittydvd-module command
Command wittydvd-module is WittyDVD as a helper process, one for each open disc, so a new version of the engine can reach a server without a new server.
Command wittydvd-module is WittyDVD as a helper process, one for each open disc, so a new version of the engine can reach a server without a new server.
Package wire is what a WittyDVD helper process and a server say to each other about one open disc: the names of the calls and the form their answers travel in.
Package wire is what a WittyDVD helper process and a server say to each other about one open disc: the names of the calls and the form their answers travel in.

Jump to

Keyboard shortcuts

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