Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ its series' file in [changelog/](changelog/) when a newer one ships.

## [Unreleased]

### Added

- `Options.SignedCompositionOffsets` (`--signed-offsets` on `to-hls`,
`hls-segment`, `serve` and `serve-growing`): a reordered video's composition offsets are written signed,
with no composition shift and no video edit list. A player that ignores the
edit list showed the picture late by the reordering depth (84 ms on a
two-frame pyramid); it now shows it on time. Off by default.

### Changed

- The HLS/DASH init segment no longer carries the cover art (`RemuxToHLS`,
Expand Down
4 changes: 3 additions & 1 deletion cmd/mkvgo/commands/cli03_parity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func oldParseHLSFlags(args []string) hlsFlags {
f.skipUnsupported = true
case "--no-iframes":
f.noIFrames = true
case "--signed-offsets":
f.signedOffsets = true
case "--damage-bytes":
needValue(args, &i)
n, err := strconv.ParseInt(args[i], 10, 64)
Expand Down Expand Up @@ -231,7 +233,7 @@ func TestCLI03_HLSFlagsParity(t *testing.T) {
"--keep-tracks": {"1,2", "1, x"}, "--keep-lang": {"fre,ENG", " , "}, "--audio-lang": {"spa"}, "--sub-offset": {"-500", "x"},
"--damage-bytes": {"100", "0", "-1"}, "--source-access": {"auto", "local", "network", "nfs"}, "--audio-shift": {"2=500", "bad"},
}
bools := []string{"--single-file", "--chapter-markers", "--skip-unsupported", "-skip-unsupported", "--no-iframes", "--synthesize-index", "--cenc-inline-key"}
bools := []string{"--single-file", "--chapter-markers", "--skip-unsupported", "-skip-unsupported", "--no-iframes", "--signed-offsets", "--synthesize-index", "--cenc-inline-key"}
operands := []string{"in.mkv", "master.m3u8", "-", "--bogus", "-x"}
var flags []string
for k := range values {
Expand Down
8 changes: 4 additions & 4 deletions cmd/mkvgo/commands/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ var CmdUsage = map[string]string{
"track-ends": "mkvgo track-ends <file.mkv> [-json] (where each track's content really ends: statistics tags when they describe the file, else a bounded header-only tail walk; picture end and audio shortfall)",
"cue-health": "mkvgo cue-health <file.mkv> [-json] [-probe] (head-only seek-index triage: which tracks the cues reference; -probe looks inside each hole; exit 1 when unhealthy)",
"diagnose": "mkvgo diagnose <file.mkv|.mp4> [--deep-verify] [-json] (one-call triage with a remedy per finding; MKV: index health + audio delay + size coherence; MP4: box layout + edit-list delays; exit 1 on findings)",
"serve": "mkvgo serve <file.mkv> [-addr 127.0.0.1:8478] [--strict] [--direct | --auto [-target mse-generic]] [--window-cache <MiB>|off] [--window-bytes <MiB>|off] [--max-walks N] [--max-in-flight N] [--max-waiting N] [--memory-limit <MiB>] [--buffered] [--cors] [--source-access auto|local|network] (serve one file's on-demand HLS plan over HTTP, or the raw file for a direct-play client)",
"serve-growing": "mkvgo serve-growing <file.mkv> [-addr 127.0.0.1:8478] [-segment 6] [--cors] [--max-in-flight 64] [--max-waiting 1024] [--memory-limit <MiB>] (play while downloading: serve a still-growing file as HLS, EVENT playlist until it finishes)",
"serve": "mkvgo serve <file.mkv> [-addr 127.0.0.1:8478] [--strict] [--direct | --auto [-target mse-generic]] [--window-cache <MiB>|off] [--window-bytes <MiB>|off] [--max-walks N] [--max-in-flight N] [--max-waiting N] [--memory-limit <MiB>] [--buffered] [--cors] [--signed-offsets] [--source-access auto|local|network] (serve one file's on-demand HLS plan over HTTP, or the raw file for a direct-play client)",
"serve-growing": "mkvgo serve-growing <file.mkv> [-addr 127.0.0.1:8478] [-segment 6] [--cors] [--signed-offsets] [--max-in-flight 64] [--max-waiting 1024] [--memory-limit <MiB>] (play while downloading: serve a still-growing file as HLS, EVENT playlist until it finishes)",
"to-mp4": "mkvgo to-mp4 [--faststart] [--skip-unsupported] [--strict] [--flatten-subs] [--webvtt-native] [--mp3-container-delay] [--hash] <input.mkv|.mp4> <output.mp4> (an MP4/MOV input is rewritten fast start, sample for sample)",
"from-mp4": "mkvgo from-mp4 [--skip-unsupported] [--strict] [--mp3-container-delay] <input.mp4> <output.mkv>",
"to-webm": "mkvgo to-webm <input.mkv> <output.webm>",
"to-hls": "mkvgo to-hls <input.mkv> -o <dir> [-segment 6] [--skip-unsupported] [--strict] [--keep-tracks 1,2 | --keep-lang fre] [--sub-offset ms] [--audio-shift track=ms] [--chapter-markers] [--no-iframes] (fragmented-MP4 HLS; virtual track subset by ID or language; virtual subtitle/audio resync; opt-in chapter/ad-insertion markers)",
"hls-segment": "mkvgo hls-segment <input.mkv|url> <master|playlist|init|N|resource-name> [-o out] [-segment 6] [--keep-tracks 1,2 | --keep-lang fre] [--sub-offset ms] [--audio-shift track=ms] [--synthesize-index] [--chapter-markers] [--no-iframes] [--damage-bytes n] (build one HLS resource on demand; --synthesize-index serves a no-Cue source by walking it once)",
"to-hls": "mkvgo to-hls <input.mkv> -o <dir> [-segment 6] [--skip-unsupported] [--strict] [--keep-tracks 1,2 | --keep-lang fre] [--sub-offset ms] [--audio-shift track=ms] [--chapter-markers] [--no-iframes] [--signed-offsets] (fragmented-MP4 HLS; virtual track subset by ID or language; virtual subtitle/audio resync; opt-in chapter/ad-insertion markers)",
"hls-segment": "mkvgo hls-segment <input.mkv|url> <master|playlist|init|N|resource-name> [-o out] [-segment 6] [--keep-tracks 1,2 | --keep-lang fre] [--sub-offset ms] [--audio-shift track=ms] [--synthesize-index] [--chapter-markers] [--no-iframes] [--signed-offsets] [--damage-bytes n] (build one HLS resource on demand; --synthesize-index serves a no-Cue source by walking it once)",
"to-abr": "mkvgo to-abr -o <dir> <best.mkv> <lower.mkv> [...] [-segment 6] [--keep-tracks 1,2 | --keep-lang fre] [--sub-offset ms] [--chapter-markers] [--no-iframes] (multi-variant HLS master from pre-encoded qualities)",
"abr-segment": "mkvgo abr-segment <master.m3u8|v{k}/name> <best> <lower> [...] [-o out] [-segment 6] [--keep-tracks 1,2 | --keep-lang fre] [--sub-offset ms] [--chapter-markers] [--no-iframes] [--damage-bytes n] (build one ABR resource on demand)",
"cmaf-mpd": "mkvgo cmaf-mpd -o <manifest.mpd> [<rung-dir> ...] [--audio <dir>]... (DASH manifest over CMAF rungs an external encoder produced: each dir holds one rendition's init.mp4 + .m4s segments; rungs are checked segment-aligned first)",
Expand Down
33 changes: 18 additions & 15 deletions cmd/mkvgo/commands/hls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type hlsFlags struct {
subOffset int64
chapterMarkers bool
noIFrames bool
signedOffsets bool
damageBytes int64
skipUnsupported bool
sourceAccess mp4.SourceAccess
Expand Down Expand Up @@ -94,6 +95,7 @@ func parseHLSFlags(args []string) hlsFlags {
fl.Bool(&f.chapterMarkers, "--chapter-markers")
fl.Bool(&f.skipUnsupported, "--skip-unsupported", "-skip-unsupported")
fl.Bool(&f.noIFrames, "--no-iframes")
fl.Bool(&f.signedOffsets, "--signed-offsets")
fl.Func(damageBytesFlag(&f.damageBytes), "--damage-bytes")
fl.Func(func(v string) {
switch v {
Expand Down Expand Up @@ -240,21 +242,22 @@ func (f hlsFlags) options(src string) mp4.Options {
keep = resolveKeepLangs(src, f.keepLangs)
}
o := mp4.Options{
FS: sourceFS(src),
SegmentMs: f.segMs,
Encrypt: f.encrypt,
CENC: f.cenc,
SingleFile: f.singleFile,
KeepTracks: keep,
SubtitleOffsetMs: f.subOffset,
ChapterMarkers: f.chapterMarkers,
NoIFrames: f.noIFrames,
DamageBytes: f.damageBytes,
SkipUnsupported: f.skipUnsupported,
Strict: Strict,
SynthesizeIndex: f.synthIndex,
AudioPresentationShift: f.audioShift,
SourceAccess: f.sourceAccess,
FS: sourceFS(src),
SegmentMs: f.segMs,
Encrypt: f.encrypt,
CENC: f.cenc,
SingleFile: f.singleFile,
KeepTracks: keep,
SubtitleOffsetMs: f.subOffset,
ChapterMarkers: f.chapterMarkers,
NoIFrames: f.noIFrames,
SignedCompositionOffsets: f.signedOffsets,
DamageBytes: f.damageBytes,
SkipUnsupported: f.skipUnsupported,
Strict: Strict,
SynthesizeIndex: f.synthIndex,
AudioPresentationShift: f.audioShift,
SourceAccess: f.sourceAccess,
}
if f.prefix != "" {
prefix := f.prefix
Expand Down
6 changes: 6 additions & 0 deletions cmd/mkvgo/commands/sec08_serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestSEC08_ServeGrowingCORSOptIn(t *testing.T) {
if parseServeGrowingFlags([]string{"in.mkv"}).cors {
t.Error("serve-growing: CORS on by default")
}
if !parseServeGrowingFlags([]string{"in.mkv", "--signed-offsets"}).signed {
t.Error("serve-growing: --signed-offsets must set the option")
}
if !parseHLSFlags(parseServeFlags([]string{"in.mkv", "--signed-offsets"}).rest).options("in.mkv").SignedCompositionOffsets {
t.Error("serve: --signed-offsets must reach the plan's options")
}
if !parseServeGrowingFlags([]string{"in.mkv", "--cors"}).cors {
t.Error("serve-growing: --cors ignored")
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/mkvgo/commands/servegrowing.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func CmdServeGrowing(args []string) {
ctx, cancel := context.WithCancel(cliCtx)
defer cancel()

plan, err := mp4.PlanGrowingHLS(ctx, src, mp4.Options{SegmentMs: segMs})
plan, err := mp4.PlanGrowingHLS(ctx, src, mp4.Options{SegmentMs: segMs, SignedCompositionOffsets: cfg.signed})
if err != nil {
FatalErr(err)
}
Expand Down Expand Up @@ -99,6 +99,7 @@ type serveGrowingFlags struct {
addr string
segMs int64
cors bool
signed bool // --signed-offsets: mp4.Options.SignedCompositionOffsets
maxInFlight int // segments served at once (0 = no cap)
maxWaiting int // requests queued behind them before a 503
memoryLimit int64 // the Go runtime's soft memory limit in bytes (0 = left as GOMEMLIMIT sets it)
Expand All @@ -111,6 +112,7 @@ func parseServeGrowingFlags(args []string) serveGrowingFlags {
fl := newFlags("serve-growing")
fl.String(&cfg.addr, "-addr", "--addr")
fl.Bool(&cfg.cors, "-cors", "--cors")
fl.Bool(&cfg.signed, "--signed-offsets")
fl.Func(func(v string) { cfg.maxInFlight = countFlag(v, "--max-in-flight") }, "-max-in-flight", "--max-in-flight")
fl.Func(func(v string) { cfg.maxWaiting = countFlag(v, "--max-waiting") }, "-max-waiting", "--max-waiting")
fl.Func(func(v string) { cfg.memoryLimit = memoryLimitFlag(v) }, "-memory-limit", "--memory-limit")
Expand Down
9 changes: 5 additions & 4 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ Package a media file - **MKV/WebM or MP4/MOV** (sniffed from the first bytes)
Text subtitle tracks (SRT, WebVTT, ASS/SSA flattened to plain text) ride as segmented **WebVTT renditions** (`subN.m3u8` + `subN_*.vtt`), declared in the master playlist with their language/name/default/forced flags; bitmap subtitles (PGS/VOBSUB) are dropped with a reason. This is the CMAF "copy rung" of an HLS ladder - the packaging, not the encoding: bitrate variants (real adaptive streaming) still require a transcoder.

```
mkvgo to-hls <input.mkv> -o <dir> [-segment 6] [--skip-unsupported] [--strict] [--sub-offset <ms>] [--audio-shift <track>=<ms>] [--chapter-markers] [--no-iframes]
mkvgo to-hls <input.mkv> -o <dir> [-segment 6] [--skip-unsupported] [--strict] [--sub-offset <ms>] [--audio-shift <track>=<ms>] [--chapter-markers] [--no-iframes] [--signed-offsets]
```

Every track the presentation leaves out - a secondary video track (one video rendition is carried), a bitmap subtitle (PGS, VobSub), an unsupported codec under `--skip-unsupported`, an encrypted track - is printed on stderr as `dropped track N (codec): reason`, the exit code staying 0; `--strict` fails the packaging by name on any of them, whatever `--skip-unsupported` says (`serve` and the ABR commands take the same two flags). `tracks -json` says ahead of time, per track, whether `to-hls` and `serve` carry it (`to_hls`, `to_hls_refusal`).
Expand All @@ -1162,6 +1162,7 @@ Every track the presentation leaves out - a secondary video track (one video ren
| `--audio-shift` | Re-base an audio track in presentation (`track=ms`, repeatable; positive = the track's content starts late and is presented earlier - feed it `diagnose`'s per-track delay). The samples are copied verbatim and the media segments are byte-identical with or without the shift: only the init segment's edit list moves, so a constant A/V desync is cancelled in the served stream without touching the source. Over-shifts clamp to the presentation start. The persistent repair remains `mkvgo retime` |
| `--chapter-markers` | Opt-in: expose the source's chapters as `EXT-X-DATERANGE` lines in the video media playlist and a chapter `EventStream` in `manifest.mpd` - chapter navigation and ad-insertion cue points, no re-segmentation. See [streaming.md](streaming.md#chapter-markers-and-ad-insertion-points) |
| `--no-iframes` | Drop the trick-play I-frame stream: no `EXT-X-I-FRAME-STREAM-INF` in the master, no `iframe.m3u8` nor `iframeNNNNN.m4s` written or served (`hls-segment iframe` refuses it). For players that scrub with their own trickplay images. Segments and the other playlists are unchanged. Also on `hls-segment`, `to-abr`, `abr-segment`. See [streaming.md](streaming.md#trick-play-scrubbing) |
| `--signed-offsets` | Write a reordered video's composition offsets signed, with no composition shift and no video edit list (CMAF `cmf2` form): a player that ignores the edit list presents the picture on time instead of late by the reordering depth. Init and segments both change: use one setting per presentation. Also on `hls-segment`, `serve` and `serve-growing` |

```bash
mkvgo to-hls video.mkv -o stream/
Expand Down Expand Up @@ -1275,7 +1276,7 @@ and reading only that window - first-play latency is milliseconds and storage
cost is zero, whatever the file size.

```
mkvgo hls-segment <input.mkv|url> <master|playlist|init|N> [-o out] [-segment 6] [--sub-offset <ms>] [--audio-shift <track>=<ms>] [--synthesize-index] [--chapter-markers] [--no-iframes] [--damage-bytes <n>]
mkvgo hls-segment <input.mkv|url> <master|playlist|init|N> [-o out] [-segment 6] [--sub-offset <ms>] [--audio-shift <track>=<ms>] [--synthesize-index] [--chapter-markers] [--no-iframes] [--signed-offsets] [--damage-bytes <n>]
```

Without `-o` the resource goes to stdout (pipe it from a server handler).
Expand Down Expand Up @@ -1332,7 +1333,7 @@ mkvgo hls-segment https://nas/movie.mkv 3 # remote: reads only segment
Serve one file's on-demand HLS presentation over plain HTTP -- `hls-segment` wrapped in a long-running `net/http` server (`mkvhttp.Handler`), so a player can be pointed straight at it: nothing is written to disk, every resource is built the first time it is requested.

```
mkvgo serve <file.mkv|url> [-addr 127.0.0.1:8478] [-segment 6] [--keep-tracks 1,2 | --keep-lang fre] [--window-cache <MiB>|off] [--window-bytes <MiB>|off] [--max-walks N] [--max-in-flight N] [--max-waiting N] [--memory-limit <MiB>] [--cors]
mkvgo serve <file.mkv|url> [-addr 127.0.0.1:8478] [-segment 6] [--keep-tracks 1,2 | --keep-lang fre] [--window-cache <MiB>|off] [--window-bytes <MiB>|off] [--max-walks N] [--max-in-flight N] [--max-waiting N] [--memory-limit <MiB>] [--cors] [--signed-offsets]
mkvgo serve <file.mkv|url> [-addr 127.0.0.1:8478] --direct
mkvgo serve <file.mkv|url> [-addr 127.0.0.1:8478] --auto [-target mse-generic]
```
Expand Down Expand Up @@ -1374,7 +1375,7 @@ See `docs/library.md` (`mkvhttp.Handler`, `mkvhttp.FileHandler`) for the full ca
Play while downloading: serve a file that may still be growing (a download landing on disk) as HLS -- `mp4.PlanGrowingHLS` wrapped in the same long-running server `serve` uses. The media playlist is `EVENT`-typed and lengthens as new whole clusters land; once the source finishes (a Cues index appears, or the file simply stops growing and `Complete()` is signalled), it switches to `VOD` + `ENDLIST`.

```
mkvgo serve-growing <file.mkv> [-addr 127.0.0.1:8478] [-segment 6] [--max-in-flight N] [--max-waiting N] [--memory-limit <MiB>] [--cors]
mkvgo serve-growing <file.mkv> [-addr 127.0.0.1:8478] [-segment 6] [--max-in-flight N] [--max-waiting N] [--memory-limit <MiB>] [--cors] [--signed-offsets]
```

- `-addr` sets the listen address (default `127.0.0.1:8478`, this machine only, as for `serve`); `-segment` sets the target segment duration in seconds (default 6), like `serve`/`to-hls`.
Expand Down
2 changes: 1 addition & 1 deletion docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Memory use scales with the sample count, not the file size: sample data is strea
err := mp4.RemuxToHLS(ctx, "in.mkv", "stream/", mp4.Options{SegmentMs: 6000})
```

Writes a fragmented-MP4 / CMAF presentation into the output directory, served through two manifests over the same segments: HLS (`master.m3u8` + per-rendition media playlists) and DASH (`manifest.mpd`). Tracks are demuxed - the video rendition (`playlist.m3u8`, `init.mp4`, `seg00001.m4s` …) plus one rendition per audio track (`audio1.m3u8`, `init_a1.mp4`, `seg_a1_00001.m4s` …, an `EXT-X-MEDIA` AUDIO group / one MPD AdaptationSet each) - so multi-audio sources get native language selection. Each `.m4s` is `styp` + `moof` + `mdat`; each init is ftyp + moov with `mvex`/`trex` and empty sample tables (movie metadata - title and tags - rides on the video init; the cover art stays out of it, since a player downloads the init before its first frame). No transcoding - samples are copied verbatim, so the codec set matches `RemuxToMP4`.
Writes a fragmented-MP4 / CMAF presentation into the output directory, served through two manifests over the same segments: HLS (`master.m3u8` + per-rendition media playlists) and DASH (`manifest.mpd`). Tracks are demuxed - the video rendition (`playlist.m3u8`, `init.mp4`, `seg00001.m4s` …) plus one rendition per audio track (`audio1.m3u8`, `init_a1.mp4`, `seg_a1_00001.m4s` …, an `EXT-X-MEDIA` AUDIO group / one MPD AdaptationSet each) - so multi-audio sources get native language selection. Each `.m4s` is `styp` + `moof` + `mdat`; each init is ftyp + moov with `mvex`/`trex` and empty sample tables (movie metadata - title and tags - rides on the video init; the cover art stays out of it, since a player downloads the init before its first frame). `Options.SignedCompositionOffsets` writes a reordered video's composition offsets signed, with no composition shift and no video edit list (the CMAF `cmf2` form), for players that ignore the edit list and would show the picture late by the reordering depth; the default keeps non-negative offsets and the edit list. No transcoding - samples are copied verbatim, so the codec set matches `RemuxToMP4`.

Segments are cut on video keyframes at roughly `Options.SegmentMs` (default 6 s) and each is independently decodable, so a player seeks by fetching the segment plus `init.mp4`. Text subtitle tracks (SRT, WebVTT, ASS/SSA flattened) become segmented WebVTT renditions declared in the master playlist; bitmap subtitles are dropped (reported via `Options.OnDrop`). This is the CMAF *copy rung* of an HLS ladder - the packaging; bitrate variants (real ABR) remain a transcoder's job.

Expand Down
2 changes: 1 addition & 1 deletion mp4/composition_shift_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestFillFragTimingLateReorderKeepsEveryPTS(t *testing.T) {
samples = append(samples, fragSample{ptsMs: int64(30+4*g+k) * 1001 / 24})
}
}
_, _, _, shift := fillFragTimingTS(samples, nil, 42, movieTimescale, 0, nil, 2, false)
_, _, _, shift := fillFragTimingTS(samples, nil, 42, movieTimescale, 0, nil, 2, false, false)
if shift != 84 {
t.Fatalf("shift = %d, want 84 (two frames)", shift)
}
Expand Down
Loading
Loading