sofia

package module
v1.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2024 License: OSL-3.0 Imports: 7 Imported by: 0

README

sofia

And, in the dream, I knew that he was, going on ahead. He was fixin' to make a fire somewhere out there in all that dark and cold. And I knew that whenever I got there, he'd be there. And then I woke up.

No Country for Old Men (2007)

ISOBMFF

library for reading and writing MP4

prior art

  1. https://github.com/mozilla/mp4parse-rust/issues/415
  2. https://github.com/Eyevinn/mp4ff/issues/298
  3. https://github.com/alfg/mp4-rust/issues/132
  4. https://github.com/yapingcat/gomedia/issues/113
  5. https://github.com/alfg/mp4/issues/27
  6. https://github.com/abema/go-mp4/issues/13
  7. https://github.com/garden4hu/fmp4parser-go/issues/4
  8. https://github.com/eswarantg/mp4box/issues/3
  9. https://github.com/miquels/mp4/issues/2
  10. https://github.com/oikomi/gomp4/issues/2

the normal place to put the encryption information in the segments is in a senc box, and this is not the case in this file, but they seem to be placed in a [uuid] box instead. This is allowed, but not supported by mp4ff library at the moment. In principle the data can be put in any place given by the offset in the saio box

and:

If the Override TrackEncryptionBox parameters flag is set, then the SampleEncryptionBox specifies the AlgorithmID, IV_size, and KID parameters. If not present, then the default values from the TrackEncryptionBox SHOULD be used for this fragment.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioSampleEntry

type AudioSampleEntry struct {
	Entry SampleEntry
	S     struct {
		Reserved     [2]uint32
		ChannelCount uint16
		SampleSize   uint16
		PreDefined   uint16

		SampleRate uint32
		// contains filtered or unexported fields
	}
	Boxes            []*Box
	ProtectionScheme ProtectionSchemeInfoBox
}

Container: SampleDescriptionBox

class AudioSampleEntry(codingname) extends SampleEntry(codingname) {
   const unsigned int(32)[2] reserved = 0;
   unsigned int(16) channelcount;
   template unsigned int(16) samplesize = 16;
   unsigned int(16) pre_defined = 0;
   const unsigned int(16) reserved = 0 ;
   template unsigned int(32) samplerate = { default samplerate of media}<<16;
}

func (*AudioSampleEntry) Decode

func (a *AudioSampleEntry) Decode(r io.Reader) error

func (AudioSampleEntry) Encode

func (a AudioSampleEntry) Encode(w io.Writer) error

type Box

type Box struct {
	BoxHeader BoxHeader
	Payload   []byte
}

4.2.2 Object definitions

aligned(8) class Box (
   unsigned int(32) boxtype,
   optional unsigned int(8)[16] extended_type
) {
   BoxHeader(boxtype, extended_type);
   // the remaining bytes are the BoxPayload
}

func (*Box) Decode added in v1.1.2

func (b *Box) Decode(r io.Reader) error

func (Box) Encode

func (b Box) Encode(w io.Writer) error

type BoxHeader

type BoxHeader struct {
	BoxSize  uint32
	Type     [4]uint8
	UserType [16]uint8
}

4.2.2 Object definitions

aligned(8) class BoxHeader (
   unsigned int(32) boxtype,
   optional unsigned int(8)[16] extended_type
) {
   unsigned int(32) size;
   unsigned int(32) type = boxtype;
   if (size==1) {
      unsigned int(64) largesize;
   } else if (size==0) {
      // box extends to end of file
   }
   if (boxtype=='uuid') {
      unsigned int(8)[16] usertype = extended_type;
   }
}

func (BoxHeader) BoxPayload

func (b BoxHeader) BoxPayload(r io.Reader) io.Reader

func (BoxHeader) BoxType added in v1.0.7

func (b BoxHeader) BoxType() string

func (*BoxHeader) Decode

func (b *BoxHeader) Decode(r io.Reader) error

func (BoxHeader) Encode

func (b BoxHeader) Encode(w io.Writer) error

func (BoxHeader) ExtendedType added in v1.1.5

func (b BoxHeader) ExtendedType() string

func (BoxHeader) Size

func (b BoxHeader) Size() uint32

type ByteRange added in v1.1.8

type ByteRange struct {
	Start uint64
	End   uint64
}

type EncryptionSample

type EncryptionSample struct {
	InitializationVector uint64
	SubsampleCount       uint16
	Subsamples           []Subsample
}

func (*EncryptionSample) Decode

func (EncryptionSample) DecryptCenc added in v1.1.4

func (e EncryptionSample) DecryptCenc(sample, key []byte) error

github.com/Eyevinn/mp4ff/blob/v0.40.2/mp4/crypto.go#L101

func (EncryptionSample) Encode

type File

type File struct {
	Boxes         []Box
	MediaData     *MediaDataBox
	Movie         *MovieBox
	MovieFragment *MovieFragmentBox
	SegmentIndex  *SegmentIndexBox
}

func (*File) Decode

func (f *File) Decode(r io.Reader) error

func (File) Encode

func (f File) Encode(w io.Writer) error

KEEP THESE IN ORDER

type FullBoxHeader

type FullBoxHeader struct {
	Version  uint8
	RawFlags [3]byte
}

4.2.2 Object definitions

aligned(8) class FullBoxHeader(unsigned int(8) v, bit(24) f) {
   unsigned int(8) version = v;
   bit(24) flags = f;
}

func (*FullBoxHeader) Decode

func (f *FullBoxHeader) Decode(r io.Reader) error

func (FullBoxHeader) Encode

func (f FullBoxHeader) Encode(w io.Writer) error

func (FullBoxHeader) Flags

func (f FullBoxHeader) Flags() uint32

func (FullBoxHeader) Size added in v1.1.2

func (FullBoxHeader) Size() uint32

type MediaBox

type MediaBox struct {
	BoxHeader        BoxHeader
	Boxes            []Box
	MediaInformation MediaInformationBox
}

Container: TrackBox

aligned(8) class MediaBox extends Box('mdia') {
}

func (*MediaBox) Decode

func (m *MediaBox) Decode(r io.Reader) error

func (MediaBox) Encode

func (m MediaBox) Encode(w io.Writer) error

type MediaDataBox

type MediaDataBox struct {
	BoxHeader BoxHeader
	Data      [][]byte
}

Container: File

aligned(8) class MediaDataBox extends Box('mdat') {
   bit(8) data[];
}

func (*MediaDataBox) Decode

func (b *MediaDataBox) Decode(r io.Reader, t TrackRunBox) error

func (MediaDataBox) Encode

func (b MediaDataBox) Encode(w io.Writer) error

type MediaInformationBox

type MediaInformationBox struct {
	BoxHeader   BoxHeader
	Boxes       []Box
	SampleTable SampleTableBox
}

Container: MediaBox

aligned(8) class MediaInformationBox extends Box('minf') {
}

func (*MediaInformationBox) Decode

func (m *MediaInformationBox) Decode(r io.Reader) error

func (MediaInformationBox) Encode

func (m MediaInformationBox) Encode(w io.Writer) error

type MovieBox

type MovieBox struct {
	BoxHeader BoxHeader
	Boxes     []*Box
	Track     TrackBox
}

Container: File

aligned(8) class MovieBox extends Box('moov') {
}

func (*MovieBox) Decode

func (m *MovieBox) Decode(r io.Reader) error

func (MovieBox) Encode

func (m MovieBox) Encode(w io.Writer) error

type MovieFragmentBox

type MovieFragmentBox struct {
	BoxHeader     BoxHeader
	Boxes         []Box
	TrackFragment TrackFragmentBox
}

Container: File

aligned(8) class MovieFragmentBox extends Box('moof') {
}

func (*MovieFragmentBox) Decode

func (m *MovieFragmentBox) Decode(r io.Reader) error

func (MovieFragmentBox) Encode

func (m MovieFragmentBox) Encode(w io.Writer) error

type OriginalFormatBox added in v1.1.0

type OriginalFormatBox struct {
	BoxHeader  BoxHeader
	DataFormat [4]uint8
}

Container: ProtectionSchemeInfoBox

aligned(8) class OriginalFormatBox(codingname) extends Box('frma') {
   unsigned int(32) data_format = codingname;
   // format of decrypted, encoded data (in case of protection)
   // or un-transformed sample entry (in case of restriction
   // and complete track information)
}

func (*OriginalFormatBox) Decode added in v1.1.0

func (b *OriginalFormatBox) Decode(r io.Reader) error

func (OriginalFormatBox) Encode added in v1.1.0

func (b OriginalFormatBox) Encode(w io.Writer) error

type ProtectionSchemeInfoBox added in v1.1.0

type ProtectionSchemeInfoBox struct {
	BoxHeader      BoxHeader
	Boxes          []Box
	OriginalFormat OriginalFormatBox
}

Container: Protected Sample Entry

aligned(8) class ProtectionSchemeInfoBox(fmt) extends Box('sinf') {
   OriginalFormatBox(fmt) original_format;
   SchemeTypeBox scheme_type_box; // optional
   SchemeInformationBox info; // optional
}

func (*ProtectionSchemeInfoBox) Decode added in v1.1.0

func (p *ProtectionSchemeInfoBox) Decode(r io.Reader) error

func (ProtectionSchemeInfoBox) Encode added in v1.1.0

func (p ProtectionSchemeInfoBox) Encode(w io.Writer) error

type Reference added in v1.0.7

type Reference [3]uint32

func (*Reference) Decode added in v1.0.7

func (r *Reference) Decode(src io.Reader) error

func (Reference) Encode added in v1.0.7

func (r Reference) Encode(dst io.Writer) error

func (Reference) ReferencedSize added in v1.1.5

func (r Reference) ReferencedSize() uint32

this is the size of the fragment, typically `moof` + `mdat`

func (Reference) SetReferencedSize added in v1.1.5

func (r Reference) SetReferencedSize(v uint32)

func (Reference) Size added in v1.1.2

func (Reference) Size() uint32

type SampleDescriptionBox

type SampleDescriptionBox struct {
	BoxHeader     BoxHeader
	FullBoxHeader FullBoxHeader
	EntryCount    uint32
	AudioSample   *AudioSampleEntry
	VisualSample  *VisualSampleEntry
}

Container: SampleTableBox

aligned(8) class SampleDescriptionBox() extends FullBox('stsd', version, 0) {
   int i ;
   unsigned int(32) entry_count;
   for (i = 1 ; i <= entry_count ; i++){
      SampleEntry(); // an instance of a class derived from SampleEntry
   }
}

func (*SampleDescriptionBox) Decode

func (s *SampleDescriptionBox) Decode(r io.Reader) error

func (SampleDescriptionBox) Encode

func (s SampleDescriptionBox) Encode(w io.Writer) error

type SampleEncryptionBox

type SampleEncryptionBox struct {
	BoxHeader     BoxHeader
	FullBoxHeader FullBoxHeader
	SampleCount   uint32
	Samples       []EncryptionSample
}

Container: TrackFragmentBox

if the version of the SampleEncryptionBox is 0 and the flag senc_use_subsamples is set, UseSubSampleEncryption is set to 1

aligned(8) class SampleEncryptionBox extends FullBox(
   'senc', version, flags
) {
   unsigned int(32) sample_count;
   {
      unsigned int(Per_Sample_IV_Size*8) InitializationVector;
      if (UseSubSampleEncryption) {
         unsigned int(16) subsample_count;
         {
            unsigned int(16) BytesOfClearData;
            unsigned int(32) BytesOfProtectedData;
         } [subsample_count ]
      }
   }[ sample_count ]
}

func (*SampleEncryptionBox) Decode

func (b *SampleEncryptionBox) Decode(r io.Reader) error

func (SampleEncryptionBox) Encode

func (b SampleEncryptionBox) Encode(w io.Writer) error

func (SampleEncryptionBox) SencUseSubsamples added in v1.1.5

func (b SampleEncryptionBox) SencUseSubsamples() bool

senc_use_subsamples: flag mask is 0x000002.

type SampleEntry

type SampleEntry struct {
	BoxHeader          BoxHeader
	Reserved           [6]uint8
	DataReferenceIndex uint16
}

8.5.2 Sample description box

aligned(8) abstract class SampleEntry(
   unsigned int(32) format
) extends Box(format) {
   const unsigned int(8)[6] reserved = 0;
   unsigned int(16) data_reference_index;
}

func (*SampleEntry) Decode added in v1.1.0

func (s *SampleEntry) Decode(r io.Reader) error

func (*SampleEntry) Encode added in v1.1.0

func (s *SampleEntry) Encode(w io.Writer) error

type SampleTableBox

type SampleTableBox struct {
	BoxHeader         BoxHeader
	Boxes             []Box
	SampleDescription SampleDescriptionBox
}

Container: MediaInformationBox

aligned(8) class SampleTableBox extends Box('stbl') {
}

func (*SampleTableBox) Decode

func (s *SampleTableBox) Decode(r io.Reader) error

func (SampleTableBox) Encode

func (s SampleTableBox) Encode(w io.Writer) error

type SegmentIndexBox added in v1.0.7

type SegmentIndexBox struct {
	BoxHeader                BoxHeader
	FullBoxHeader            FullBoxHeader
	ReferenceId              uint32
	Timescale                uint32
	EarliestPresentationTime []byte
	FirstOffset              []byte
	Reserved                 uint16
	ReferenceCount           uint16
	Reference                []Reference
}

Container: File

aligned(8) class SegmentIndexBox extends FullBox('sidx', version, 0) {
   unsigned int(32) reference_ID;
   unsigned int(32) timescale;
   if (version==0) {
      unsigned int(32) earliest_presentation_time;
      unsigned int(32) first_offset;
   } else {
      unsigned int(64) earliest_presentation_time;
      unsigned int(64) first_offset;
   }
   unsigned int(16) reserved = 0;
   unsigned int(16) reference_count;
   for(i=1; i <= reference_count; i++) {
      bit (1) reference_type;
      unsigned int(31) referenced_size;
      unsigned int(32) subsegment_duration;
      bit(1) starts_with_SAP;
      unsigned int(3) SAP_type;
      unsigned int(28) SAP_delta_time;
   }
}

func (*SegmentIndexBox) Append added in v1.1.8

func (s *SegmentIndexBox) Append(size uint32)

func (*SegmentIndexBox) Decode added in v1.0.7

func (s *SegmentIndexBox) Decode(r io.Reader) error

func (SegmentIndexBox) Encode added in v1.0.7

func (s SegmentIndexBox) Encode(w io.Writer) error

func (*SegmentIndexBox) New added in v1.1.8

func (s *SegmentIndexBox) New()

func (SegmentIndexBox) Ranges added in v1.1.8

func (s SegmentIndexBox) Ranges(start uint64) []ByteRange

size will always fit inside 31 bits: unsigned int(31) referenced_size but range-start and range-end can both exceed 32 bits, so we must use 64 bit

func (SegmentIndexBox) Size added in v1.1.2

func (s SegmentIndexBox) Size() uint32

type Subsample

type Subsample struct {
	BytesOfClearData     uint16
	BytesOfProtectedData uint32
}

func (*Subsample) Decode

func (s *Subsample) Decode(r io.Reader) error

func (Subsample) Encode

func (s Subsample) Encode(w io.Writer) error

type TrackBox

type TrackBox struct {
	BoxHeader BoxHeader
	Boxes     []Box
	Media     MediaBox
}

Container: MovieBox

aligned(8) class TrackBox extends Box('trak') {
}

func (*TrackBox) Decode

func (t *TrackBox) Decode(r io.Reader) error

func (TrackBox) Encode

func (t TrackBox) Encode(w io.Writer) error

type TrackFragmentBox

type TrackFragmentBox struct {
	BoxHeader        BoxHeader
	Boxes            []Box
	TrackRun         TrackRunBox
	SampleEncryption SampleEncryptionBox
}

Container: MovieFragmentBox

aligned(8) class TrackFragmentBox extends Box('traf') {
}

func (*TrackFragmentBox) Decode

func (t *TrackFragmentBox) Decode(r io.Reader) error

func (TrackFragmentBox) Encode

func (t TrackFragmentBox) Encode(w io.Writer) error

type TrackRunBox

type TrackRunBox struct {
	BoxHeader        BoxHeader
	FullBoxHeader    FullBoxHeader
	SampleCount      uint32
	DataOffset       int32
	FirstSampleFlags uint32
	Sample           []TrackRunSample
}

Container: TrackFragmentBox

If the data-offset is present, it is relative to the base-data-offset established in the track fragment header.

aligned(8) class TrackRunBox extends FullBox('trun', version, tr_flags) {
   unsigned int(32) sample_count;
   signed int(32) data_offset; // 0x000001, assume present
   unsigned int(32) first_sample_flags; // 0x000004
   {
      unsigned int(32) sample_duration; // 0x000100
      unsigned int(32) sample_size; // 0x000200, assume present
      unsigned int(32) sample_flags // 0x000400
      if (version == 0) {
         unsigned int(32) sample_composition_time_offset; // 0x000800
      } else {
         signed int(32) sample_composition_time_offset; // 0x000800
      }
   }[ sample_count ]
}

func (*TrackRunBox) Decode

func (t *TrackRunBox) Decode(r io.Reader) error

func (TrackRunBox) Encode

func (t TrackRunBox) Encode(w io.Writer) error

func (TrackRunBox) FirstSampleFlagsPresent added in v1.1.5

func (t TrackRunBox) FirstSampleFlagsPresent() bool

0x000004 first-sample-flags-present

func (TrackRunBox) SampleCompositionTimeOffsetsPresent added in v1.1.5

func (t TrackRunBox) SampleCompositionTimeOffsetsPresent() bool

0x000800 sample-composition-time-offsets-present

func (TrackRunBox) SampleDurationPresent added in v1.1.5

func (t TrackRunBox) SampleDurationPresent() bool

0x000100 sample-duration-present

func (TrackRunBox) SampleFlagsPresent added in v1.1.5

func (t TrackRunBox) SampleFlagsPresent() bool

0x000400 sample-flags-present

func (TrackRunBox) SampleSizePresent added in v1.1.5

func (t TrackRunBox) SampleSizePresent() bool

0x000200 sample-size-present

type TrackRunSample

type TrackRunSample struct {
	Duration              uint32
	Size                  uint32
	Flags                 uint32
	CompositionTimeOffset [4]byte
}

func (*TrackRunSample) Decode

func (s *TrackRunSample) Decode(r io.Reader, t *TrackRunBox) error

func (TrackRunSample) Encode

func (s TrackRunSample) Encode(w io.Writer, t TrackRunBox) error

type VisualSampleEntry

type VisualSampleEntry struct {
	Entry SampleEntry
	S     struct {
		PreDefined uint16
		Reserved   uint16

		Width           uint16
		Height          uint16
		HorizResolution uint32
		VertResolution  uint32

		FrameCount     uint16
		CompressorName [32]uint8
		Depth          uint16
		// contains filtered or unexported fields
	}
	Boxes            []*Box
	ProtectionScheme ProtectionSchemeInfoBox
}

Container: SampleDescriptionBox

class VisualSampleEntry(codingname) extends SampleEntry(codingname) {
   unsigned int(16) pre_defined = 0;
   const unsigned int(16) reserved = 0;
   unsigned int(32)[3] pre_defined = 0;
   unsigned int(16) width;
   unsigned int(16) height;
   template unsigned int(32) horizresolution = 0x00480000; // 72 dpi
   template unsigned int(32) vertresolution = 0x00480000; // 72 dpi
   const unsigned int(32) reserved = 0;
   template unsigned int(16) frame_count = 1;
   uint(8)[32] compressorname;
   template unsigned int(16) depth = 0x0018;
   int(16) pre_defined = -1;
   // other boxes from derived specifications
   CleanApertureBox clap; // optional
   PixelAspectRatioBox pasp; // optional
}

func (*VisualSampleEntry) Decode

func (v *VisualSampleEntry) Decode(r io.Reader) error

func (VisualSampleEntry) Encode

func (v VisualSampleEntry) Encode(w io.Writer) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL