diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-09-15 00:17:33 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-09-15 00:17:33 +0200 |
| commit | 3e9123b430e0592023213395f822b3aae9769199 (patch) | |
| tree | 76cbc0078ac80addd76fa1ac85d26ee25d4a7390 | |
| parent | 5ad3b94e1d6a503decc3f0d0b8fe940a21e35ed8 (diff) | |
| download | mp4-3e9123b430e0592023213395f822b3aae9769199.tar.gz mp4-3e9123b430e0592023213395f822b3aae9769199.zip | |
docs: add progressive clipping example
| -rw-r--r-- | README.md | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -69,10 +69,11 @@ list of samples. Each sample carries its byte offset, size, decode and presentation timestamps, and sync (keyframe) flag. ```go -tracks, duration, err := track.ParseTracks(moovBuf) +tracks, movieTimescale, duration, err := track.ParseTracks(moovBuf) if err != nil { log.Fatal(err) } +fmt.Printf("movie: timescale=%d duration=%d\n", movieTimescale, duration) for _, t := range tracks { fmt.Printf("track %d: codec=%s samples=%d\n", t.ID, t.Codec(), len(t.Samples)) @@ -85,6 +86,37 @@ for _, t := range tracks { } ``` +### Clipping a progressive MP4 + +The `clip` package copies a time range into a new progressive MP4 without +re-encoding. A video cut includes the preceding keyframe for decoding and uses +an edit list so presentation still begins at the requested time. + +```go +src, err := os.Open("video.mp4") +if err != nil { + log.Fatal(err) +} +defer src.Close() + +info, err := src.Stat() +if err != nil { + log.Fatal(err) +} + +dst, err := os.Create("clip.mp4") +if err != nil { + log.Fatal(err) +} +defer dst.Close() + +result, err := clip.Cut(dst, src, info.Size(), 30, 45) +if err != nil { + log.Fatal(err) +} +fmt.Printf("wrote %.1fs clip (%d bytes)\n", result.Duration, result.Size) +``` + ### Fragmenting to fMP4 The `fragment` package reads a standard MP4 file and produces an init segment |
