### Install mp4ff Command-Line Tools Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Install individual mp4ff command-line tools directly from the repository using 'go install'. Ensure you specify the tool's path within the cmd directory. ```bash go install github.com/Eyevinn/mp4ff/cmd/mp4ff-info@latest ``` ```bash go install github.com/Eyevinn/mp4ff/cmd/mp4ff-encrypt@latest ``` -------------------------------- ### Run mp4ff-crop with Open Source Cloud CLI Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Execute the mp4ff-crop command using the Open Source Cloud CLI. This example demonstrates processing a file from an S3 bucket and saving the output to another S3 bucket, specifying credentials and endpoint. ```bash % export OSC_ACCESS_TOKEN= % npx -y @osaas/cli@latest create eyevinn-mp4ff test \ -o awsAccessKeyId= \ -o awsSecretAccessKey= \ -o s3EndpointUrl=https://eyevinnlab-birme.minio-minio.auto.prod.osaas.io \ -o cmdLineArgs="mp4ff-crop s3://input/VINN.mp4 s3://output/VINN-crop2.mp4" ``` -------------------------------- ### Streaming with Custom Input File Source: https://github.com/eyevinn/mp4ff/blob/master/examples/stream-encrypt/README.md Start the HTTP server using a specified MP4 input file. The stream can then be accessed via curl. ```bash go run *.go -input /path/to/your/video.mp4 curl http://localhost:8080/enc.mp4 -o output.mp4 ``` -------------------------------- ### Conventional Commits Examples Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Follow the Conventional Commits specification for commit messages to maintain a consistent and readable project history. Examples include 'feat:', 'fix:', 'docs:', and 'chore:' prefixes. ```text feat: add support for VVC video codec ``` ```text fix: resolve memory leak in fragment processing ``` ```text docs: update API documentation for mp4.File ``` ```text chore: update dependencies to latest versions ``` -------------------------------- ### Read MP4 Mdat Data Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Provides methods to read or copy specific byte ranges of media data from an 'mdat' box when decoding in lazy mode. Requires the start offset, size, and an io.ReadSeeker for the file. ```go func (m *MdatBox) ReadData(start, size int64, rs io.ReadSeeker) ([]byte, error) ``` ```go func (m *MdatBox) CopyData(start, size int64, rs io.ReadSeeker, w io.Writer) (nrWritten int64, err error) ``` -------------------------------- ### Sample Numbering Convention Source: https://github.com/eyevinn/mp4ff/blob/master/CLAUDE.md Explains the convention for sample numbering in mp4ff, where external APIs use 1-based indexing while internal storage uses 0-based indexing. ```go // External APIs use 1-based sample numbers (sample 1 = first sample). // Internal slice storage is 0-based. ``` -------------------------------- ### Create MP4 Init Segment Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Initializes an empty MP4 structure and adds an empty track with specified parameters. Use this to set up the basic structure of your fragmented MP4 file. ```go init := mp4.CreateEmptyInit() init.AddEmptyTrack(timescale, mediatype, language) init.Moov.Trak.SetHEVCDescriptor("hvc1", vpsNALUs, spsNALUs, ppsNALUs) ``` -------------------------------- ### Basic Streaming with Go Source: https://github.com/eyevinn/mp4ff/blob/master/examples/stream-encrypt/README.md Run the HTTP server for basic MP4 streaming without encryption or refragmentation. Access the stream via curl. ```bash go run *.go curl http://localhost:8080/enc.mp4 -o output.mp4 ``` -------------------------------- ### Build and Test Commands for mp4ff Source: https://github.com/eyevinn/mp4ff/blob/master/CLAUDE.md Standard make commands for building CLI tools, running tests, performing quality checks, and generating coverage reports. Individual package testing is also supported. ```bash make build # Build all CLI tools and examples make test # go test ./... make check # Full quality check (prepare + pre-commit + codespell) make coverage # Generate coverage reports (HTML + text) go test ./mp4/ # Test a single package go test ./mp4/ -run TestName # Run a single test ``` -------------------------------- ### Box Implementation Pattern in mp4ff Source: https://github.com/eyevinn/mp4ff/blob/master/CLAUDE.md Illustrates the standard Go struct and method pattern for implementing MP4 boxes, including decoding and registration. This pattern ensures consistency across different box types. ```go // File: {boxname}.go // struct: {BoxName}Box // Required methods: Type(), Size(), Encode(io.Writer), EncodeSW(bits.SliceWriter), Info() // Decoding functions: Decode{BoxName}(hdr, startPos, r) and Decode{BoxName}SR(hdr, startPos, sr) // Registered in dispatch tables: decoders and decodersSR ``` -------------------------------- ### Run Specific Go Test Steps Source: https://github.com/eyevinn/mp4ff/blob/master/examples/stream-encrypt/README.md Execute individual test steps for the stream-encrypt project. Use these to isolate and test specific features like basic streaming, refragmentation, or encryption. ```bash go test -v -run TestStep1 # Basic streaming go test -v -run TestStep2 # Refragmentation go test -v -run TestStep3 # Encryption ``` -------------------------------- ### Accessing MP4 Fragment Boxes in Go Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Demonstrates how to access nested boxes within an MP4 fragment structure in Go. Use caution to check for nil pointers to prevent panics. ```go fragment.Moof.Traf.Trun ``` ```go fragment.Moof.Trafs[1].Trun[1] ``` -------------------------------- ### Go Test Suite Source: https://github.com/eyevinn/mp4ff/blob/master/examples/stream-encrypt/README.md Execute all integration tests for the stream-encrypt project. This verifies basic streaming, refragmentation, and encryption functionalities. ```bash go test -v ``` -------------------------------- ### Activate Virtual Environment for Committing Source: https://github.com/eyevinn/mp4ff/blob/master/CLAUDE.md Command to activate the Python virtual environment for enforcing commit conventions using commitlint. ```bash source venv/bin/activate ``` -------------------------------- ### Container Box Pattern with Children Source: https://github.com/eyevinn/mp4ff/blob/master/CLAUDE.md Demonstrates the pattern for container boxes in mp4ff, which include a slice of generic `Children []Box` and direct references to common child types. The `AddChild()` method ensures synchronization. ```go // Container boxes hold Children []Box plus direct references to common children (e.g., MoovBox has Trak *TrakBox and Traks []*TrakBox). // AddChild() updates both. ``` -------------------------------- ### Implement New Box Interface Methods Source: https://github.com/eyevinn/mp4ff/blob/master/README.md When implementing a new box, ensure the struct adheres to the Box interface by providing implementations for Type, Size, Encode, EncodeSW, and Info methods. This is crucial for proper box handling within the MP4 structure. ```go Type() Size() Encode(w io.Writer) EncodeSW(sw bits.SliceWriter) Info() ``` -------------------------------- ### Refragmentation with Go Source: https://github.com/eyevinn/mp4ff/blob/master/examples/stream-encrypt/README.md Configure the server to refragment MP4 files into smaller fragments, each containing 30 samples. Access the refragmented stream via curl. ```bash go run *.go -samples 30 curl http://localhost:8080/enc.mp4 -o refragmented.mp4 ``` -------------------------------- ### Dual Encoding/Decoding Paths in mp4ff Source: https://github.com/eyevinn/mp4ff/blob/master/CLAUDE.md Highlights the two parallel I/O paths used for encoding and decoding: the standard io.Reader/io.Writer and the performance-optimized SliceReader/SliceWriter. Both paths must be maintained. ```go // 1. io.Reader/io.Writer — standard, more flexible // 2. SliceReader/SliceWriter — preferred for performance (2-10x faster, far fewer allocations) ``` -------------------------------- ### Encryption and Refragmentation with Go Source: https://github.com/eyevinn/mp4ff/blob/master/examples/stream-encrypt/README.md Enable both encryption (CENC scheme) and refragmentation (30 samples per fragment) for MP4 streams. Requires key, key ID, and IV. Access the encrypted stream via curl. ```bash go run *.go \ -samples 30 \ -key 11223344556677889900aabbccddeeff \ -keyid 00112233445566778899aabbccddeeff \ -iv 00000000000000000000000000000000 \ -scheme cenc curl http://localhost:8080/enc.mp4 -o encrypted.mp4 ``` -------------------------------- ### Create and Encode MP4 Media Segment Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Creates a new media segment, adds a fragment, and populates it with full samples. The segment can then be encoded to an io.Writer or bits.SliceWriter. ```go seg := mp4.NewMediaSegment() frag := mp4.CreateFragment(uint32(segNr), mp4.DefaultTrakID) seg.AddFragment(frag) for _, sample := range samples { frag.AddFullSample(sample) } err := seg.Encode(w) ``` ```go err := seg.EncodeSW(sw) ``` -------------------------------- ### MP4 FullSample Definition Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Defines the structure for a full sample, including sample properties for the 'trun' box and decode time/data. This is used when all sample data is available before segment creation. ```go mp4.FullSample{ Sample: mp4.Sample{ Flags uint32 // Flag sync sample etc Dur uint32 // Sample duration in mdhd timescale Size uint32 // Size of sample data Cto int32 // Signed composition time offset }, DecodeTime uint64 // Absolute decode time (offset + accumulated sample Dur) Data []byte // Sample data } ``` -------------------------------- ### Decode Box with io.Reader Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Use DecodeBox for parsing MP4 boxes when SliceReader is not available or suitable. This method may have higher memory allocation overhead. ```go func DecodeBox(r io.Reader) (Box, error) ``` -------------------------------- ### Decode Box with SliceReader Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Use DecodeBoxSR for efficient parsing of MP4 boxes. This method is generally preferred over DecodeBox for better performance. ```go func DecodeBoxSR(sr bits.SliceReader) (Box, error) ``` -------------------------------- ### Decode TrunBox with io.Reader Source: https://github.com/eyevinn/mp4ff/blob/master/README.md The TrunBox also supports decoding using a standard io.Reader via the DecodeTrun method, though this may be less performant than using SliceReader. ```go func (t *TrunBox) DecodeTrun(r io.Reader) ``` -------------------------------- ### Streaming and Lazy Processing in mp4ff Source: https://github.com/eyevinn/mp4ff/blob/master/CLAUDE.md Details the mechanisms for streaming and lazy processing of MP4 data, including skipping `mdat` payload and incremental fragment processing with callbacks. `BoxSeekReader` is used for non-seekable streams. ```go // DecModeLazyMdat — skips reading mdat payload into memory // StreamFile / InitDecodeStream / ProcessFragments — incremental fragment processing with callbacks // BoxSeekReader — emulates seeking on non-seekable streams ``` -------------------------------- ### Decode TrunBox with SliceReader Source: https://github.com/eyevinn/mp4ff/blob/master/README.md The TrunBox provides a specific DecodeTrunSR method for efficient decoding using a SliceReader, in addition to the general DecodeBoxSR. ```go func (t *TrunBox) DecodeTrunSR(sr bits.SliceReader) ``` -------------------------------- ### Lazy MP4 Decoding Source: https://github.com/eyevinn/mp4ff/blob/master/README.md Decodes an MP4 file in lazy mode, deferring the reading of media data from 'mdat' boxes. Use this for memory efficiency when processing large files. ```go parsedMp4, err = mp4.DecodeFile(ifd, mp4.WithDecodeMode(mp4.DecModeLazyMdat)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.