Documentation
¶
Overview ¶
Package convert drives the conversion of a frame-packed Blu-ray 3D source (MVC) into a side-by-side MKV that an ordinary decoder can play.
MVC stores the second eye as a dependent view of an AVC base view. Players that decode it are rare — Plex does not — so a 3D Blu-ray is unwatchable in most libraries even though it carries a full 1080p image per eye. Converting it to side-by-side keeps both eyes at full resolution in a single frame that any H.264/HEVC decoder handles.
Everything but the encode runs in process:
demuxer read a Blu-ray (image, folder, playlist, m2ts) or a Matroska
remux in place: the video to the decoder, audio, subtitles and
chapters to the work directory
decoder the MVC decoder of the parent package: both views decoded and
stacked side by side
encoder a GPU through its system library, in process; or x264 / x265
(ffmpeg for software half-SBS, or a GPU without its library)
muxer write the MKV
Installing an encoder program, when one is needed, is left to the operator. What this package guarantees is that it will say precisely what is missing, and why, rather than failing partway through a multi-hour run.
Index ¶
- Constants
- Variables
- func CodecSlug(t Track) string
- func DecodeFrames(ctx context.Context, goos string, o Options, path string, ...) error
- func DescribeAudio(t Track) string
- func DescribeTracks(tracks []Track) string
- func DetailTags(o Options, audio []Track, height int, picture []string) string
- func DeviceNames() string
- func IsDiscImage(path string) bool
- func KodiPGS(src mkv.Source) mkv.Source
- func OpenMVCMatroska(ctx context.Context, path string) (next func() (base, dep []byte, pts int64, err error), stop func() error, ...)
- func ParseClock(s string) (time.Duration, error)
- func ParseList(s string) []string
- func ParseSize(s string) (int64, error)
- func ProbeEncoder(ctx context.Context, enc Encoder, codec Codec, device string, viaFFmpeg bool) bool
- func ResolveGPU(o *Options)
- func SupportsEncoder(goos string, enc Encoder) bool
- func TrackKind(t Track) string
- func WithDetails(path, tags string) string
- type Codec
- type CompareResult
- type Crop
- type Decoder
- type Device
- type Encoder
- type FEL
- type Found
- type GPUAPI
- type Kind
- type Layout
- type Options
- type Plan
- type Report
- type Reporter
- type Runner
- type Scale
- type Selection
- type Step
- type Subs3D
- type SubsFile
- type Tool
- type Track
- type TrackFilter
- type Trim
Constants ¶
const CRFAuto = -1
CRFAuto is Options.CRF left for the source to decide: the quality measured to suit it (see sourceCRF).
const DefaultDepth3D = 1.5
DefaultDepth3D is --3d-depth's default: half again the depth that scores best against the 3D discs' (stereo.ShapeFor's). The discs' disparity spans 1.7 to 2.2 times that one's (5th to 95th percentile, on two films held out of its choice): a score against the disc's right eye punishes depth in the wrong place more than too little of it, so its best is flatter than the discs.
Variables ¶
var CurrentGOOS = runtime.GOOS
CurrentGOOS reports the running platform, indirected for tests.
var Devices = map[string]Device{ "coreelec": {Ext: ".mkv", About: "CoreELEC on an Amlogic box (Ugoos AM6B+ and alike): HEVC 10-bit, Dolby Vision profile 7 with its full enhancement layer kept, 3D side by side (--layout mvc for MVC), the disc's subtitles as they are", Flags: map[string]string{"codec": "h265", "bit-depth": "10", "dv-fel": "keep", "layout": "full"}}, "kodi": {Ext: ".mkv", About: "Kodi elsewhere: HEVC 10-bit, Dolby Vision profile 8.1 (the enhancement layer composed in), 3D side by side", Flags: map[string]string{"codec": "h265", "bit-depth": "10", "dv-fel": "compose", "layout": "full"}}, "plex": {Ext: ".mkv", About: "Plex and Jellyfin, played without transcoding: HEVC 10-bit, Dolby Vision 8.1, picture subtitles read as text (clients transcode PGS), 3D half side by side", Flags: map[string]string{"codec": "h265", "bit-depth": "10", "dv-fel": "compose", "subs-ocr": "true", "layout": "half"}}, "appletv": {Ext: ".mp4", About: "Apple TV and other Apple players: an MP4 of HEVC 10-bit, the sound as AC-3 where the file cannot carry the source's, subtitles as text", Flags: map[string]string{"codec": "h265", "bit-depth": "10", "subs-ocr": "true", "audio-transcode": "ac3"}}, "visionpro": {Ext: ".mov", About: "Apple Vision Pro and iPhone spatial video: MV-HEVC (both eyes in one stream), subtitles as text", Flags: map[string]string{"layout": "mvhevc", "subs-ocr": "true"}}, "quest": {Ext: ".mp4", About: "Meta Quest players (SKYBOX, Moon): MV-HEVC in MP4; their subtitles are burned in with --burn-subs", Flags: map[string]string{"layout": "mvhevc"}}, }
Devices are the presets by name.
var ErrDecodeDone = errors.New("decode done")
ErrDecodeDone stops DecodeFrames without an error, returned by its fn.
var LookPath = exec.LookPath
LookPath is the executable resolver. It is a variable so tests can supply their own without creating real executables, which would not be portable across the platforms this tool targets.
var ProbeDecoder = probeDecoder
ProbeDecoder reports whether a GPU decoder of kind k works here for the codec, opening one (the answer is kept: it takes a GPU context). A variable, so tests can decide what the machine has.
var ProbeNative = probeNative
ProbeNative reports whether a hardware encoder works in process for the codec: a short trial encode, since a library that loads is not proof of a GPU that encodes. A variable, so tests can decide what the machine has.
Functions ¶
func CodecSlug ¶
CodecSlug is a short, filesystem-safe name for a track's codec, for putting in an output filename: "TrueHD Atmos" becomes "TrueHD-Atmos".
func DecodeFrames ¶ added in v0.15.0
func DecodeFrames(ctx context.Context, goos string, o Options, path string, keep func(time.Duration) bool, fn func(*mvc.Frame) error) error
DecodeFrames decodes a video's pictures (its first video track, as --compare does) as 8-bit 4:2:0 frames, one after another, for tools that look at the pictures themselves (the 2D to 3D benchmark). A 3D disc's (or MVC file's) two views come as one frame, the eyes side by side at full width, as a full side-by-side file's do. With keep, only the pictures it keeps (by their time from the first picture) are handed to fn; return ErrDecodeDone from fn to stop early.
func DescribeAudio ¶
DescribeAudio names a track the way a log line should, so the choice the ranking made is visible rather than implicit.
func DescribeTracks ¶
DescribeTracks renders a track listing for --list: one line per track, with the track number a filter can also select on.
func DetailTags ¶
DetailTags describes a finished conversion for its file name, in the order release names use: layout, resolution per eye, video codec and its quality setting, encoder, then the main audio track and its channels, e.g. "3D FSBS 1080p HEVC CQ26 NVENC TrueHD-Atmos 7.1", or without the layout for a 2D conversion, and with the high dynamic range the output carries after the resolution ("2160p DV HDR10 HEVC 10bit CQ24 NVENC"). height is the source picture height (one eye); picture is the run's PictureTags.
func IsDiscImage ¶ added in v0.15.0
IsDiscImage reports whether an output is a disc image: a Blu-ray 3D.
func KodiPGS ¶ added in v0.8.1
KodiPGS wraps a PGS source (display sets, as Matroska carries them) so that Kodi draws its wide subtitles whole in a side-by-side 3D film.
func OpenMVCMatroska ¶ added in v0.9.0
func OpenMVCMatroska(ctx context.Context, path string) (next func() (base, dep []byte, pts int64, err error), stop func() error, err error)
OpenMVCMatroska reads a Matroska file's 3D video, its dependent view in a mvcC BlockAddition or a second track, as access units for the MVC decoder: next returns each picture's base and dependent view with its PTS (90 kHz), and io.EOF at the end; stop closes the file. The other tracks are left alone.
func ParseClock ¶ added in v0.14.0
ParseClock reads a time: [[H:]M:]S[.fraction], or a Go duration (90s, 1h30m).
func ParseList ¶
ParseList splits a comma-separated flag value, dropping blanks. Returns nil for an empty value so a flag left unset is indistinguishable from absent.
func ParseSize ¶ added in v0.14.0
ParseSize reads a size: bytes, or with K, M, G or T (powers of 1000; KiB, MiB, GiB and TiB of 1024).
func ProbeEncoder ¶
func ProbeEncoder(ctx context.Context, enc Encoder, codec Codec, device string, viaFFmpeg bool) bool
ProbeEncoder reports whether enc actually encodes codec on this machine.
func ResolveGPU ¶
func ResolveGPU(o *Options)
ResolveGPU decides whether the chosen hardware encoder runs in process: it does unless ffmpeg was asked for or the trial encode fails.
func SupportsEncoder ¶
SupportsEncoder reports whether enc is meaningful on goos. VAAPI on macOS and VideoToolbox on Linux are configuration errors worth catching early rather than at the first ffmpeg invocation, hours into a run.
func WithDetails ¶
WithDetails puts tags into a file name before its extension, unless the name already carries them.
Types ¶
type Codec ¶
type Codec string
Codec is the video codec the stacked frames are compressed with. It is a separate axis from the Encoder: every encoder here can produce either.
const ( // CodecH264 is AVC. The safe default — a side-by-side H.264 file plays on // anything, including hardware too old to decode HEVC at all. CodecH264 Codec = "h264" // CodecH265 is HEVC. A full-SBS frame is double width (3840x1080 from a // 1080p disc), which is exactly where HEVC's larger coding units pay off, // so it is materially smaller at the same quality. The cost is decoder // support: HEVC is widely but not universally direct-played, and a client // that has to transcode a 3840x1080 stream is worse off than one // direct-playing H.264. CodecH265 Codec = "h265" // CodecAV1 is AV1: smaller again than HEVC at the same quality, and // royalty-free, but the newest to decode in hardware. NVENC (RTX 40 and // later), VAAPI on recent Intel and AMD GPUs, and SVT-AV1 in software // encode it; VideoToolbox does not. CodecAV1 Codec = "av1" )
type CompareResult ¶ added in v0.14.0
type CompareResult struct {
Pictures int
PSNR, SSIM, VMAF vmaf.Pooled
Scores []vmaf.Score
Model string
}
CompareResult is a comparison's measures over the pictures compared.
func Compare ¶ added in v0.14.0
func Compare(ctx context.Context, goos string, o Options, ref, dis string, skip, every int, report Reporter) (CompareResult, error)
Compare measures the video of dis against ref's, a picture of ref against one of dis from the start, after skip pictures of ref; with every above 1, a picture in every that many.
type Crop ¶ added in v0.14.0
type Crop struct {
Top, Bottom, Left, Right int
// Auto finds the black bars to crop before the conversion starts
// (--crop auto: see cropdetect.go).
Auto bool
}
Crop is how many rows and columns come off each edge of the picture (--crop), before any scaling.
func ParseCrop ¶ added in v0.14.0
ParseCrop reads --crop: "none" (or ""), "auto", or TOP:BOTTOM:LEFT:RIGHT in samples, each even (4:2:0 chroma goes in pairs).
type Decoder ¶ added in v0.7.0
type Decoder string
Decoder says how a 2D source's video is decoded: see Options.Decoder.
type Device ¶ added in v0.14.0
type Device struct {
// Flags are the settings, by flag name.
Flags map[string]string
// Ext is the output file's kind it plays ("" for any).
Ext string
// About says what the preset is for and does.
About string
}
Device is a player's preset.
type Encoder ¶
type Encoder string
Encoder selects how the stacked frames are compressed.
const ( // EncoderAuto picks the best available for the platform. EncoderAuto Encoder = "auto" // EncoderSoftware is CPU encoding through the codec's own command-line // tool — x264 or x265, depending on the Codec. Available everywhere, // slowest, and the only one whose output does not vary with the GPU. EncoderSoftware Encoder = "software" // EncoderVAAPI is ffmpeg VAAPI — Linux only, needs a supported GPU. EncoderVAAPI Encoder = "vaapi" // EncoderVideoToolbox is ffmpeg VideoToolbox — macOS only. EncoderVideoToolbox Encoder = "videotoolbox" // EncoderNVENC is ffmpeg NVENC — NVIDIA, Linux and Windows. EncoderNVENC Encoder = "nvenc" // EncoderMediaFoundation is the encoder a Windows GPU driver installs as // a Media Foundation transform: Intel Quick Sync, AMD AMF. Windows only. EncoderMediaFoundation Encoder = "mediafoundation" // EncoderBuiltin is the encoders in this program: H.264 (8-bit; both // eyes of an MVC file), HEVC (MV-HEVC included) and AV1. No tool // needed, every platform. EncoderBuiltin Encoder = "builtin" // EncoderCopy keeps a 3D source's left eye as it is and codes the // right eye here (--layout mvc): the 2D picture stays the disc's. EncoderCopy Encoder = "copy" )
func DefaultEncoder ¶
func DefaultEncoder(ctx context.Context, goos string, codec Codec, depth int, vaapiDevice string) Encoder
DefaultEncoder resolves EncoderAuto to the fastest encoder this machine can actually use, falling back to software encoding.
Having ffmpeg is not the same as having a GPU: a stock build advertises h264_nvenc on a machine with no NVIDIA card. So each candidate is put through a one-frame trial encode rather than merely having its tools located — the alternative is choosing an encoder that fails at the encode step, hours into a conversion.
func Encoders ¶
Encoders returns the encoders that make sense on this platform, best first. The list is what the platform *supports*, not what is installed; Detect reports availability.
func ParseEncoder ¶
ParseEncoder resolves the name an operator typed. "x264" is accepted for EncoderSoftware: it was the name of this setting when H.264 was the only output, and it would otherwise silently become an unknown encoder.
func (Encoder) UsesFFmpeg ¶
UsesFFmpeg reports whether an encoder is driven through ffmpeg rather than the codec's own standalone binary.
type FEL ¶ added in v0.7.0
type FEL string
FEL says what becomes of a Dolby Vision full enhancement layer: see Options.DVFEL.
type Found ¶
type Found struct {
Tool
// Path is the resolved executable, empty when the tool was not found.
Path string
// Version is the first line the tool printed when asked, best-effort.
Version string
// Unusable says why a tool that is there cannot do the job: an ffmpeg
// built without the GPU encoder asked for, say.
Unusable string
}
Found is the outcome of looking for one tool.
type Kind ¶
type Kind int
Kind classifies a track by what the conversion must do with it.
const ( // KindOther is a track the conversion ignores. KindOther Kind = iota // KindBaseView is the AVC base view: the left eye, and a 2D-playable stream. KindBaseView // KindDependentView is the MVC dependent view: the right eye, which only // decodes against the base view. KindDependentView // KindAudio is an audio track, carried through to the output unchanged. KindAudio // KindSubtitle is a subtitle track, carried through unchanged. KindSubtitle // KindEnhancement is a Dolby Vision enhancement layer (a UHD Blu-ray's // PID 0x1015): the enhancement picture and the RPU, which only mean // something beside the base layer. KindEnhancement )
type Layout ¶
type Layout string
Layout is how the two eyes are arranged in the output frame.
const ( // LayoutFullSBS keeps both eyes at source width: 3840x1080 from a 1080p // disc, so 1920x1080 per eye. This is what a 3D library normally wants — // it is the only layout that preserves the disc's resolution. LayoutFullSBS Layout = "full" // LayoutHalfSBS squeezes both eyes into one source-width frame: // 1920x1080 total, so 960x1080 per eye. Half the horizontal detail, and // roughly half the bitrate. LayoutHalfSBS Layout = "half" // LayoutFullOU stacks both eyes at source size, the left on top: // 1920x2160 from a 1080p disc. LayoutFullOU Layout = "ou" // LayoutHalfOU squeezes both eyes, the left on top, into one // source-height frame: 1920x540 per eye. LayoutHalfOU Layout = "half-ou" // LayoutMVC keeps the two eyes as Blu-ray 3D does: MVC, an H.264 left // eye any player shows in 2D and a right eye coded as a second view of // it, which 3D players decode with it and show frame packed. 1920x1080 // per eye; --codec h264, 8-bit. LayoutMVC Layout = "mvc" // LayoutMVHEVC is MV-HEVC in an MP4 (or QuickTime) file: the left eye // an HEVC base layer any player shows in 2D, the right a second layer // predicted from it, with Apple's stereo signalling, for Vision Pro, // iPhones and the Meta Quest. NVENC codes it. LayoutMVHEVC Layout = "mvhevc" )
const InputAuto Layout = "auto"
InputAuto is the Options.InputLayout that goes by what the source says of its frame (a Matroska stereo mode).
type Options ¶
type Options struct {
Input string // .iso, a BDMV directory, a playlist or m2ts, or an MKV remux
Output string // destination .mkv
TempDir string // scratch space for the audio, subtitles and encoded video
Layout Layout
Encoder Encoder
// Codec is the output video codec. H.264 plays on anything; HEVC is
// materially smaller for a double-width side-by-side frame.
Codec Codec
// Audio and Subs narrow which tracks are carried into the output. Zero
// values keep every track the disc has, which is the default. Lossless
// audio dominates the output of a well-compressed conversion — on a clean
// CG feature the TrueHD track alone can be more than twice the video — so
// dropping the tracks you will never play is the largest saving available
// that costs no picture quality.
Audio TrackFilter
Subs TrackFilter
// DefaultAudio, when set, is the language whose first kept audio track
// is the default (else the first track is); DefaultSubs the language
// whose first full subtitle track (not forced, SDH only when there is
// no other) is the default (else none is, but a 3D film's first flat
// track). A film in another language is watched so: its own audio,
// subtitles in English.
DefaultAudio, DefaultSubs string
// KeepFallback keeps the lossy core embedded in a lossless stream — the
// AC-3 inside TrueHD, the DTS inside DTS-HD — instead of dropping it.
// It costs space for audio that duplicates the track beside it, and buys
// a fallback for a player that cannot decode the lossless one.
KeepFallback bool
// Remux writes the disc's own streams back out with no re-encoding, so
// the MVC video survives bit for bit and only the filtered-out tracks are
// lost. The output is an MPEG-2 transport stream, since that is what MVC
// travels in; nothing is decoded, stacked or encoded, so the encoder,
// codec, layout and CRF settings do not apply.
Remux bool
// CRF is the quality target. Lower is better; 18 is visually transparent
// for most sources. CRFAuto leaves it to the source: see sourceKind.
//
// It is not comparable across codecs: x265 at a given CRF is roughly a
// step higher quality — and larger — than x264 at the same number, so the
// same value yields a better-looking HEVC file rather than a smaller one.
// Nothing here adjusts it, because silently re-interpreting a number the
// operator typed is worse than documenting what it means.
CRF int
// Preset is the encoder's speed/efficiency trade-off. x264 and x265 take
// the same preset names.
Preset string
// Tune is what the built-in AV1 encoder leans toward: psnr (the
// default) or vmaf.
Tune string
// Color is the colour signalling the output states, set from a 2D
// source's (an HDR film's BT.2020 and PQ); nil states none.
Color *gpu.ColorInfo
// Decoder chooses how a 2D source's video is decoded: on a GPU when one
// can (DecoderAuto, the default), only on a GPU, or only with the
// H.264 decoder here (H.264 sources only). A 3D source always goes to
// the MVC decoder here: no GPU decodes MVC.
Decoder Decoder
// DVFEL is what a conversion does with a Dolby Vision full
// enhancement layer: compose it into the picture (FELCompose, the
// default; profile 8.1 out), keep it as a layer (FELKeep, rebuilt for
// the encoded base layer, or FELReencode, the source's re-encoded;
// profile 7 out), or leave it out (FELDrop, the HDR10 base layer as it
// is).
DVFEL FEL
// DVELCRF is the enhancement layer's quality when it is kept as a layer
// (0: CRF plus 12).
DVELCRF int
// Crop takes rows and columns off the picture's edges, and Scale fits
// what is left in a box (never larger), for a 2D conversion: see
// transform.go.
Crop Crop
Scale Scale
// ToneMap makes an HDR picture SDR (BT.709), after any crop and
// scaling: see tonemap.go.
ToneMap bool
// VideoSize, when set, is the video's size to aim at, in bytes: the
// CRF is found for it (see videosize.go).
VideoSize int64
// Trim converts part of the source (--start, --end): see trim.go.
Trim Trim
// SubsOCR reads each PGS subtitle track's pictures as text: a text
// track beside it (SRT in Matroska, tx3g in MP4).
SubsOCR bool
// SubsFiles are subtitle files (SRT, ASS, SSA, WebVTT) added to the
// output as tracks, after the source's.
SubsFiles []SubsFile
// TwoD converts the source as a 2D film: the picture, or a 3D source's
// base view (its left eye, or the right one where the disc says so),
// on its own. A source with no MVC dependent view is converted so in
// any case.
TwoD bool
// To3D converts a 2D source to 3D: each picture's depth estimated (a
// video depth network, DepthModel's weights, or Video Depth Anything
// Small's, downloaded once), the two eyes made from it, and the pair
// put out in the layout asked for, as a 3D source's would be. Depth3D
// scales the depth (0: DefaultDepth3D); Screen3D moves the whole of
// it nearer (positive) or farther, in percent of the width.
To3D bool
DepthModel string
Depth3D, Screen3D float64
// Curve3D, when not 0 or 1, bends the depth within each shot's range:
// its nearness (0 the shot's farthest, 1 its nearest) to this power
// (stereo.Shape.Curve); below 1 what lies between comes forward, as
// the rows of a crowd a depth network stacks away behind each other.
Curve3D float64
// ScreenSize3D, when not zero, is the screen's diagonal in inches:
// --to-3d keeps what is behind its screen short of the eyes'
// separation there (stereo.ScreenFar).
ScreenSize3D float64
// Shots3D is a file of stretches of the film graded by hand
// (shots3d.go).
Shots3D string
// Preview3D makes stills of --to-3d's pairs at a few places and
// depths, into Output, a directory, instead of converting.
Preview3D bool
// Grade3D, when set, is the address a live grading serves at
// (grade3d.go): the film converted as it plays, its depth turned by
// hand; Output is the --3d-shots file written.
Grade3D string
// Reference3D, with Grade3D, is the film's own 3D (a side-by-side or
// over-under file) to switch to beside the conversion, for comparison.
Reference3D string
// NoWindow3D leaves out the floating window: the black strips down a
// side of one eye that put the picture's edge in front of what comes
// out of the screen there.
NoWindow3D bool
// Refine3D is the depth refinement's weights, which correct the
// depth's shape (graded then as stereo.RefinedShape grades it): the
// built-in ones ("", the default when the network is not tuned), none
// ("none", the default when it is), or a file of tools/depthtrain's.
Refine3D string
// Fill3D is --3d-fill: the hole filler's weights, which fill what an
// eye saw nothing of: "" or "none" for the renderer's carried edge,
// else a file of tools/inpainttrain's.
Fill3D string
// Tune3D is the depth network's tail, learnt from the 3D discs
// (graded then as stereo.TunedShape grades it): the built-in one ("",
// the default, for Video Depth Anything Small), none ("none"), or a
// file of tools/depthtrain -tail's.
Tune3D string
// Subs3D is what becomes of the subtitles: kept as they are, drawn
// once for a player to place in 3D itself (Subs3DOff, the default);
// drawn into both halves of the frame at the depth the disc gives them,
// for players that show a side-by-side frame as it is (Subs3DOn); or
// both, the 3D track after its flat one (Subs3DBoth).
Subs3D Subs3D
// BurnSubs, when not 0, is the subtitle track drawn into the picture
// (--layout mvhevc, whose file carries no subtitle track), in each eye
// at the depth the disc gives it.
BurnSubs int
// InputLayout is how a 2D-coded source's frame holds two eyes: side
// by side or over-under, full or half (LayoutFullSBS, LayoutHalfSBS,
// LayoutFullOU, LayoutHalfOU); "" when it holds one picture, InputAuto
// to go by what a Matroska source says.
InputLayout Layout
// InputSwap says the framed source's right eye comes first.
InputSwap bool
// AudioTranscode is the codec a track an MP4 output cannot carry as it
// is (DTS, PCM) is coded in: "ac3" (the default) or "aac".
AudioTranscode string
// BitDepth is the output's: 8 (or 0), or 10 for HEVC (Main 10) and AV1.
// The source is 8-bit either way; at 10 the encoder predicts and
// quantises at finer precision, which shows as less banding in smooth
// gradients and, measured on NVENC HEVC, about 1.5% fewer bits at the
// same QP for 0.1 dB more PSNR. Every HEVC and AV1 decoder plays it.
BitDepth int
// VAAPIDevice is the render node for VAAPI encoding.
VAAPIDevice string
// SwapLR exchanges the eyes. Most discs put the left eye in the base view,
// but not all, and a swapped pair is unwatchable rather than subtly wrong.
// The decoder stacks the views the other way round, so no filter is
// involved and any encoder will do.
SwapLR bool
// SpatialFOV, SpatialBaseline and SpatialDisparity are what an MV-HEVC
// file (--layout mvhevc) says of its stereo pair: the horizontal field
// of view of each eye's picture in degrees, the distance between the
// cameras in millimetres, and a shift of the views in -1..1 of the
// width. Apple's Photos marks a file spatial only with a field of view
// and a baseline or disparity.
SpatialFOV float64
SpatialBaseline float64
SpatialDisparity float64
// AQ is the strength of the built-in encoder's adaptive quantisation
// (--layout mvc): each macroblock's quantiser moved by its energy, flat
// and dark ones lower, busy ones higher. Off (0) by default: measured
// on Gravity it costs about a VMAF point at equal size; 1 is x264's
// usual setting.
AQ float64
// DecodeThreads is how many pictures the decoder works on at once; 0 uses
// every CPU.
DecodeThreads int
// Playlist picks the title of a disc image or folder by its playlist
// ("00800" or "00800.mpls") instead of letting the playlists decide.
Playlist string
// GPUAPI says how a hardware encoder is driven: through its system
// library in process (the default; empty means it too), or ffmpeg.
GPUAPI GPUAPI
// NativeGPU is set by ResolveGPU when the hardware encoder runs in
// process.
NativeGPU bool
// contains filtered or unexported fields
}
Options configure a conversion.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns sensible starting settings. Nothing here varies by platform — the encoder is resolved separately, by what is installed.
func (Options) EncodesViaFFmpeg ¶
EncodesViaFFmpeg reports whether ffmpeg runs the encode: always for a hardware encoder, for software encoding that needs a filter, and for software AV1 when SvtAv1EncApp is not installed but ffmpeg (with its libsvtav1) is.
func (Options) NeedsFilters ¶
NeedsFilters reports whether the output requires a filter on the stacked frame, which is squeezing it to half width. (Exchanging the eyes is done by the decoder while stacking, so it needs none.)
It matters because neither x264 nor x265 has filters. Software encoding that needs one is therefore driven through ffmpeg's libx264 or libx265 instead of the standalone binary — the same encoder library, reached by a route that can filter — rather than being refused, which is what used to happen.
type Plan ¶
type Plan struct {
// Notes are said before the steps: what the run settles that the plan
// cannot know yet.
Notes []string
Steps []Step
// Intermediates are the files the steps create, for cleanup.
Intermediates []string
}
Plan is the full sequence for one conversion.
type Report ¶
Report is the result of a toolchain check.
func Detect ¶
Detect locates every tool required on this platform for enc.
A version string is best-effort: several of these programs exit non-zero when asked for one, so a tool that was found but would not report a version is still reported as present.
func DetectFor ¶
DetectFor locates the tools a run with these options needs. A GPU encoder reached through ffmpeg is also tried there, with a short encode: an ffmpeg can be present and still lack it (Alpine's has no NVENC), which would otherwise only show at the encode, after the demux.
type Reporter ¶
Reporter receives progress. A conversion runs for hours, so it has to say what it is doing; nil discards.
type Runner ¶
type Runner struct {
Opts Options
// GOOS is the platform whose toolchain and encoders apply.
GOOS string
// Report receives progress lines.
Report Reporter
// KeepTemp leaves the demuxed streams behind, for looking at a bad result
// without paying for the demux again.
KeepTemp bool
// Restart ignores what an interrupted run left in the work directory
// and encodes from the start.
Restart bool
// SwapLRSet records that the operator gave --swap-lr explicitly, which
// stops the disc's own base-view marking from overriding them.
SwapLRSet bool
// Explicit holds the options the operator gave (by flag name), so the
// report of the settings tells them apart from the defaults chosen.
Explicit map[string]bool
// Height is the source picture's height (one eye), known once the
// first picture is decoded: for naming the output.
Height int
// Version is bdtools' version, which the files written say made them.
Version string
// Selected records what the probe chose, readable once Run returns. A
// caller naming its output after the audio it got needs this: the codec
// is not known until the source has been probed.
Selected Selection
// contains filtered or unexported fields
}
Runner executes a conversion.
func (*Runner) ListSource ¶ added in v0.14.0
ListSource is ListTracks with the source's running time: a Matroska file's, a disc title's playlist's (0 when the source does not say).
func (*Runner) ListTracks ¶
ListTracks resolves the source and returns everything it contains, with no filter applied, so an operator can see what the track filters have to work with.
It reads the playlists and the first megabytes of the feature, wherever the source is: nothing is extracted.
func (*Runner) PictureTags ¶ added in v0.8.5
PictureTags names the high dynamic range a finished run's output carries, as release names do: DV (Dolby Vision, profile 8.1 or 7), HDR10+, HDR10 (a PQ picture), HLG. None for SDR, or for HDR the output could not carry (H.264 keeps no HDR metadata).
func (*Runner) Run ¶
Run performs the conversion: read the source in place, decode both views into stacked frames, encode those, and mux the result with the audio and subtitles the source carried — or, for a remux, copy the disc's streams.
The work directory is beside the output (or under --temp), named after it. A run that fails or is stopped leaves the video segments it finished there, and the same command run again picks up after them; a run that succeeds removes it.
type Scale ¶ added in v0.14.0
type Scale struct{ W, H int }
Scale is the box a picture is scaled to fit (--scale), keeping its shape; a picture that fits already stays as it is. Zero scales nothing.
func ParseScale ¶ added in v0.14.0
ParseScale reads --scale: "none" (or ""), a name (2160p, 1440p, 1080p, 720p, 576p, 480p) or WIDTHxHEIGHT.
type Selection ¶
Selection is the set of tracks a conversion will use.
func SelectTracks ¶
SelectTracks picks what the conversion needs from a listing.
Both views are required and each must appear exactly once: a source with no MVC track is not 3D, and one with several is something this does not understand well enough to guess at. Audio and subtitles are carried through in the order the source lists them, so the first audio track stays first.
func SelectTracks2D ¶ added in v0.7.0
SelectTracks2D picks what a 2D conversion needs: the main video (the first, which on a Blu-ray is the primary video, PID 0x1011; a 3D source's base view), whatever its codec, and the audio and subtitles. An MVC dependent view is left out; a Dolby Vision enhancement layer is taken as the dependent track.
func (Selection) Apply ¶
func (s Selection) Apply(audio, subs TrackFilter) (Selection, error)
Apply narrows a selection's audio and subtitle tracks.
A filter that matches nothing is an error rather than a silent pass or a silent drop. Either behaviour would be defensible in isolation and both are wrong here: carrying every track on when the operator asked for one defeats the request, and dropping all audio produces a film nobody can watch after hours of conversion. Saying so up front, with the tracks the disc actually has, lets the request be corrected before any work is done.
type Step ¶
type Step struct {
// Name is a short label for progress reporting.
Name string
// Argv is the program and its arguments, ready for exec. No shell is
// involved, so nothing here is quoted or escaped for one.
Argv []string
// PipeTo, when set, names the step this one's stdout feeds. The decoder
// streams raw frames to the encoder rather than writing an intermediate
// file, which for a feature film is hundreds of gigabytes saved.
PipeTo string
// Builtin marks a step that runs inside this process rather than as a
// program: the MVC decode. Its Argv is the equivalent mvcdec command,
// shown so a dry run still reads as a transcript.
Builtin bool
}
Step is one external command in the conversion.
type SubsFile ¶ added in v0.14.0
type SubsFile struct {
Path, Lang string
}
SubsFile is a subtitle file to add, with its language ("" to go by its name: film.en.srt, film.eng.forced.srt).
func ParseSubsFile ¶ added in v0.14.0
ParseSubsFile reads --subs-file: PATH, or LANG:PATH.
type Tool ¶
type Tool struct {
// Name is how this package and its messages refer to the tool.
Name string
// Binaries are candidate executable names in preference order. Windows
// builds are found through PATHEXT, so the bare name is enough there too.
Binaries []string
// Purpose says what the tool does in the pipeline, so a missing-tool
// report explains itself without the reader consulting the source.
Purpose string
// VersionArgs prints a version. Many of these tools exit non-zero when
// asked, so output is used whatever the exit status.
VersionArgs []string
// Install maps GOOS to a hint. A hint is a starting point, not a
// guarantee: several of these have no distribution package anywhere.
Install map[string]string
}
Tool is an external program the conversion depends on.
func Required ¶
Required returns the program needed on goos to produce codec with the given encoder through an external program: ffmpeg for a hardware encoder (or software half-SBS), else whichever of x264 / x265 matches the codec. The demux, decode and mux are built in and need nothing.
RequiredFor answers for any options, including a GPU encoding in process.
func RequiredFor ¶
RequiredFor returns the tools a run with these options needs: none for a remux or a GPU encoding in process, otherwise the encoder program.
func (Tool) InstallHint ¶
InstallHint returns the hint for goos, falling back to any other platform's so a reader on an unlisted OS still gets a starting point.
type Track ¶
type Track struct {
// ID identifies the track in its source: the PID of a Blu-ray stream,
// the track number of a Matroska one.
ID int
// Type is the human label ("H.264", "MVC", "AC3", "PGS").
Type string
// StreamID is the codec identifier ("V_MPEG4/ISO/AVC", "V_MPEG4/ISO/MVC",
// "A_AC3"), in tsMuxeR's spelling, which the track listing and the
// filters have always used.
StreamID string
// Info is the descriptive line, kept for reporting rather than parsed.
Info string
// Lang is the ISO-639 code, empty when the source does not say.
Lang string
// Name and Forced are the track's title and forced flag, when the source
// has them (a Matroska file does; a disc does not).
Name string
Forced bool
// Commentary is a Matroska track's commentary flag; IsCommentary also
// reads the track's name.
Commentary bool
// Height is a video track's picture height, when the source states it
// before decoding (a Matroska file does; a disc's playlist does not).
Height int
// Width and StereoMode are a video track's picture width and Matroska
// stereo mode (1 side by side, 3 over-under, the left eye first; 11
// and 2 the right first), when the source states them.
Width, StereoMode int
// contains filtered or unexported fields
}
Track is one stream of a source.
func (Track) IsCommentary ¶ added in v0.14.0
IsCommentary reports whether a track is a commentary: flagged so, or so named ("Commentary by the director", "Audio commentary").
func (Track) Kind ¶
Kind reports what the conversion does with this track.
The base and dependent views are told apart by stream ID rather than by order or track number: a disc is not obliged to put them in any particular order, and picking the wrong one as the base yields a stream that cannot decode at all.
type TrackFilter ¶
type TrackFilter struct {
// Langs are ISO-639-2 codes as the source gives them ("eng", "fra"). The
// special value "und" matches a track the source gave no language for,
// which is what Matroska already calls undetermined.
Langs []string
// Best keeps only the highest-quality track of those matching, of each
// language asked for (in their order; with no language, the one best),
// which is what "the best English track" means. Lossless beats lossy,
// then more channels, then higher bitrate. It applies after the language
// and codec filters, so the two compose: language eng plus Best is "the
// best English track", not "the best track, if it happens to be English",
// and eng,jpn the best English track and the best Japanese one.
Best bool
// NoCommentary leaves out commentaries (Track.IsCommentary).
NoCommentary bool
// Codecs are matched against the track's stream ID and its human type,
// case-insensitively, as substrings: "truehd" matches A_TRUEHD, and "dts"
// matches both A_DTS and DTS-HD Master Audio. A substring is the right
// shape here because the disc's own spelling varies and an operator
// should not have to know which form the source used.
Codecs []string
}
TrackFilter narrows which audio or subtitle tracks are carried into the output. A zero TrackFilter keeps everything, which is the default: a disc's tracks are the disc's business unless the operator says otherwise.
Languages and codecs are matched independently and both must pass, so `--audio-lang eng --audio-codec truehd` means "the English TrueHD track", not "anything English or anything TrueHD".
func (TrackFilter) Empty ¶
func (f TrackFilter) Empty() bool
Empty reports whether the filter would keep everything.
func (TrackFilter) Matches ¶
func (f TrackFilter) Matches(t Track) bool
Matches reports whether t survives the filter.
func (TrackFilter) None ¶ added in v0.14.0
func (f TrackFilter) None() bool
None reports whether the filter asks for no track at all (language "none").
func (TrackFilter) String ¶
func (f TrackFilter) String() string
String renders a filter the way it was asked for, for an error message.
Source Files
¶
- ac3transcode.go
- audiocode.go
- audioquality.go
- bluray.go
- builtinav1.go
- builtinavc.go
- builtinhevc.go
- compare.go
- cropdetect.go
- defaults.go
- devices.go
- dolbyvision.go
- drawou.go
- encode.go
- felcompose.go
- fellayers.go
- ffdecode.go
- filter.go
- framed.go
- godecode.go
- godemux.go
- gomux.go
- goremux.go
- gpu.go
- gputransform.go
- grade3d.go
- grade3dhud.go
- grade3dref.go
- grade3dtls.go
- holes.go
- join.go
- matroska.go
- mkvremux.go
- mp4mux.go
- mvcread.go
- mvcsink.go
- mvhevcpics.go
- mvhevcsink.go
- naming.go
- offsets.go
- pgs3d.go
- pgsburn.go
- pgscrop.go
- pgskodi.go
- picture.go
- pipe.go
- plan.go
- preview3d.go
- probe.go
- progress.go
- redepth.go
- resume.go
- run.go
- scale.go
- shots3d.go
- source.go
- subsocr.go
- textsubs.go
- to3d.go
- tonemap.go
- toolchain.go
- transform.go
- trim.go
- videosize.go
- x265enc.go