Documentation
¶
Overview ¶
Package bdmv reads the structure of a Blu-ray disc: the playlists that make up its titles, and the stream files they refer to, from a BDMV directory or directly out of a UDF disc image. It writes them too (write.go), for a disc of one film.
Index ¶
- Constants
- func AnnexBKey(coding byte, au []byte) (key bool, params []byte)
- func ClipInfo(d Disc, clip string) string
- func DependentStreamPath(d Disc, it PlayItem) string
- func Index(threeD bool) []byte
- func MovieObjects() []byte
- func Mux(clips []*ClipMux, start, shift int64) error
- func Playlists(d Disc) ([]string, error)
- func StreamPath(d Disc, it PlayItem) (path string, ssif bool)
- type Clip
- type ClipMux
- type ClipStream
- type Disc
- type EPEntry
- type Live
- type Mark
- type MuxFrame
- type MuxStream
- type PlayItem
- type Playlist
- type Stream
- type SubPath
- type SubPlayItem
Constants ¶
const ( // LiveVideoPID is the video's PID in a Live stream. LiveVideoPID = 0x1011 // LivePSIFrames is how often, in frames, the PAT and PMT go out // between keyframes. LivePSIFrames = 24 )
const ( KindVideo = iota KindAudio KindPG KindIG KindSecondaryAudio KindSecondaryVideo KindPiPPG )
Stream kinds in a play item's STN table, in the order the table lists them.
const ( CodingMPEG2Video = 0x02 CodingAVC = 0x1b CodingMVC = 0x20 CodingHEVC = 0x24 CodingVC1 = 0xea CodingLPCM = 0x80 CodingAC3 = 0x81 CodingDTS = 0x82 CodingTrueHD = 0x83 CodingEAC3 = 0x84 CodingDTSHDHR = 0x85 CodingDTSHDMA = 0x86 CodingEAC3Sec = 0xa1 CodingDTSSec = 0xa2 CodingPGS = 0x90 CodingIGS = 0x91 CodingText = 0x92 )
Stream coding types (stream_coding_type in the STN table and the PMT).
const ( // Preload is how far ahead of the first frame's decoding a clip's // first packet arrives. Preload = 27_000_000 / 2 )
const SubPathMVC = 8
SubPathMVC is the sub-path type carrying the MVC dependent view.
Variables ¶
This section is empty.
Functions ¶
func AnnexBKey ¶ added in v0.20.0
AnnexBKey reports whether an Annex B access unit of a coding (CodingAVC or CodingHEVC) is a keyframe (an IDR or, for HEVC, any IRAP picture), and gives its parameter sets (SPS and PPS, HEVC's VPS too), with their start codes, when it carries any.
func DependentStreamPath ¶
DependentStreamPath returns the dependent view's own stream file, for a 3D item on a disc without an SSIF.
func Index ¶ added in v0.15.0
Index is the index.bdmv of a disc of one title, a movie (movie object 0) that its first playback and top menu (object 1) start.
func MovieObjects ¶ added in v0.15.0
func MovieObjects() []byte
MovieObjects is the MovieObject.bdmv of Index's disc: object 0, the title, plays playlist 0; object 1, the first playback and the top menu, jumps to title 1.
func Mux ¶ added in v0.15.0
Mux writes the clips, their timestamps moved by shift (90 kHz) and arriving from start (27 MHz) on.
Types ¶
type Clip ¶ added in v0.15.0
type Clip struct {
// Dependent is an MVC dependent view's clip: its stream and entry
// points in the file's 3D extensions, not its program.
Dependent bool
// RecordingRate is the clip's TS_recording_rate, in bytes a second;
// Packets its source packets.
RecordingRate, Packets uint32
PCRPID uint16
// Start and End are its presentation times, 45 kHz.
Start, End uint32
// Streams are the program's (the dependent's: its MVC stream).
Streams []ClipStream
// EPPID is the stream the entry points EP are of.
EPPID uint16
EP []EPEntry
// Extents are the source packets its SSIF extents start at, for a 3D
// clip (nil for a 2D one).
Extents []uint32
}
Clip is what a clip info file says of a clip.
type ClipMux ¶ added in v0.15.0
type ClipMux struct {
W io.Writer
Streams []*MuxStream
// Rate is the clip's highest rate, in bits a second.
Rate int
// Packets is how many source packets were written (a multiple of 32:
// the file is whole aligned units).
Packets uint32
// EP are the entry points of its first stream (the video).
EP []EPEntry
// Units are the arrival times of its aligned units' first packets (32
// packets each), 27 MHz: where an SSIF may cut it.
Units []int64
// First and Last are its first and last frames' presentation times,
// 90 kHz.
First, Last int64
}
ClipMux is a clip being muxed: its streams in (the video first, whose IDR pictures are its entry points), its source packets out to W, and what its clip info needs once done.
type ClipStream ¶
type ClipStream struct {
PID uint16
Coding byte
Lang string
// Format and Rate are the stream's coding attributes as the clip info
// gives them. Video: video_format (1 480i, 2 576i, 3 480p, 4 1080i,
// 5 720p, 6 1080p, 7 576p, 8 2160p) and frame_rate (1 23.976, 2 24,
// 3 25, 4 29.97, 6 50, 7 59.94). Audio: audio_presentation_type (1 mono,
// 3 stereo, 6 multi-channel, 12 stereo + multi-channel) and
// sampling_frequency (1 48 kHz, 4 96 kHz, 5 192 kHz, 12 192 kHz with a
// 48 kHz core, 14 96 kHz with a 48 kHz core). Zero when not given.
Format, Rate byte
// Aspect is a video stream's aspect_ratio (2 4:3, 3 16:9), for
// writing; not read.
Aspect byte
}
ClipStream is one stream of a clip's program, from its clip info.
func ParseCLPI ¶
func ParseCLPI(b []byte) ([]ClipStream, error)
ParseCLPI reads the streams of a clip info (.clpi) file: the program's PIDs, coding types and languages, which a bare stream file does not carry in its own tables. A dependent view's clip lists its MVC stream in the file's 3D extension (ProgramInfo_SS) rather than its program, and that stream comes after the program's.
type Disc ¶
type Disc interface {
// List returns the file names in a directory, in name order.
List(dir string) ([]string, error)
// ReadFile returns a whole (small) file.
ReadFile(path string) ([]byte, error)
// Open returns a reader over a stream file and its size.
Open(path string) (io.ReadSeekCloser, int64, error)
// Exists reports whether the file is there.
Exists(path string) bool
// Describe names the disc for messages.
Describe() string
// Close releases what the disc holds open: the image file Open opened.
// A disc read from a caller's reader (OpenImage) leaves it open.
Close() error
}
Disc is a BDMV directory tree, wherever it lives. Paths are relative to the BDMV directory, with forward slashes, and matched case-insensitively: a disc authored on a case-sensitive filesystem may use either case.
func OpenImage ¶
OpenImage reads a UDF disc image from r, which holds size bytes; label names it in messages. The image may be partial — a pre-download sample with only its first and last pieces, say — as long as the reads the directory and the files asked for need succeed: a read outside what r has is an ordinary error. The caller owns r; Close leaves it open.
type EPEntry ¶ added in v0.15.0
EPEntry is an entry point of a clip: an access unit a player may start decoding at (an IDR picture), its PTS (90 kHz), the source packet it starts in, and IEnd, how far into the clip its I picture ends, coded as the clip info codes it (I_end_position_offset: 1 to 7, a coarser count of packets the higher).
type Live ¶ added in v0.20.0
type Live struct {
W io.Writer
Coding byte // CodingAVC or CodingHEVC
// FromKey drops what comes before the first keyframe: a player that
// joins a stream under way starts there.
FromKey bool
// Params are the parameter sets to put ahead of a keyframe that
// carries none, with their start codes: the last ones seen (Frame
// keeps them), or a stream's first for a writer that joins it late.
Params []byte
// contains filtered or unexported fields
}
Live writes one video stream as a transport stream as its frames are made, for a player reading it live (over HTTP, say): plain 188-byte packets, the PAT and PMT ahead of every keyframe and at least every LivePSIFrames frames, a PCR before every frame. The frames come in display order and are decoded in it (no B-frames). The parameter sets of the last keyframe that carried them go ahead of any keyframe that does not, so a player joining late starts at the next keyframe.
type Mark ¶
type Mark struct {
Type int
PlayItem int
Time uint32 // ticks on the item's clip timeline
PID uint16
Duration uint32
}
Mark is a playlist mark: a chapter (type 1) or a link point (type 2).
type MuxFrame ¶ added in v0.15.0
type MuxFrame struct {
PTS, DTS int64 // 90 kHz
Data []byte
// Key is a random access point: an IDR picture, an entry point.
Key bool
}
MuxFrame is one frame of a stream: a video access unit, an audio frame, a subtitle segment.
type MuxStream ¶ added in v0.15.0
type MuxStream struct {
PID uint16
Coding byte
// Lang, Format, Rate and Aspect are its attributes (ClipStream's).
Lang string
Format, Rate, Aspect byte
// Descriptors are its PMT descriptors after the registration one
// (an AC-3 stream's audio descriptor, say).
Descriptors []byte
// Buffer is its decoder buffer, in bytes: how much of it may arrive
// ahead of its decoding.
Buffer int
// Next gives its frames in decode order; io.EOF ends them.
Next func() (MuxFrame, error)
}
MuxStream is a stream of a clip.
type PlayItem ¶
type PlayItem struct {
Clip string // five digits, the clip file name without its extension
Codec string // "M2TS"
// ConnectionCondition is 1 for a discontinuity and 5 or 6 for a
// seamless join with the previous item.
ConnectionCondition int
STCID int
// InTime and OutTime bound the item on its clip's timeline, in ticks.
InTime, OutTime uint32
// Angles lists the other angles' clips of a multi-angle item.
Angles []string
Streams []Stream
// DependentClip is the clip holding the MVC dependent view of this item,
// from the playlist's MVC sub-path; empty for a 2D item.
DependentClip string
// DependentPID is the dependent view's PID from the STN_table_SS, or 0
// when the playlist does not say (Blu-ray uses 0x1012).
DependentPID uint16
// OffsetSequences is how many offset sequences the MVC stream's offset
// metadata carries (the STN_table_SS's number_of_offset_sequences).
OffsetSequences int
}
PlayItem is one clip of a playlist.
type Playlist ¶
type Playlist struct {
Version string
Items []PlayItem
SubPaths []SubPath
Marks []Mark
// BaseViewIsRight is the mvc_base_view_R_flag: the disc says its base
// view is the right eye.
BaseViewIsRight bool
}
Playlist is a parsed .mpls file.
func ReadPlaylist ¶
ReadPlaylist parses PLAYLIST/<name>.
func (*Playlist) Chapters ¶
Chapters returns the chapter marks as offsets from the start of the playlist, in order.
func (*Playlist) MPLS ¶ added in v0.15.0
MPLS is the playlist file of p: its items' stream tables and marks, and for a 3D playlist its dependent view's sub-path and STN_table_SS.
func (*Playlist) UniqueDuration ¶
UniqueDuration is the playing time counting each stretch of a clip once. A disc can carry playlists that loop one short clip a hundred times — menus, demo loops, and decoys meant to confuse rippers — which last longer than the feature without holding more of it.
type Stream ¶
type Stream struct {
Kind int
// EntryType says where the stream lives: 1 in the play item's own clip,
// 2 and 4 in a sub-path's clip, 3 in a sub-path's clip in-mux.
EntryType int
PID uint16
SubPath int
SubClip int
Coding byte
// Format and Rate are the 4-bit video format / frame rate, or audio
// presentation / sample rate fields.
Format, Rate byte
// Lang is the ISO 639-2 code for audio, PG, IG and text streams.
Lang string
// OffsetSequence is, for a PG stream of a 3D play item, the offset
// sequence of the MVC stream's offset metadata that sets its depth:
// how far the graphics move apart in the two eyes, frame by frame. -1
// when the playlist gives none.
OffsetSequence int
}
Stream is one entry of a play item's STN table.
type SubPath ¶
type SubPath struct {
Type int
Items []SubPlayItem
}
SubPath is an auxiliary path of a playlist: secondary audio or video, or the MVC dependent view (type 8).