sofia

package module
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: OSL-3.0 Imports: 7 Imported by: 1

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/311
  3. https://github.com/alfg/mp4-rust/issues/132
  4. https://github.com/yapingcat/gomedia/issues/115
  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

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 {
	SampleEntry SampleEntry
	Extends     struct {
		ChannelCount uint16
		SampleSize   uint16
		PreDefined   uint16

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

ISO/IEC 14496-12

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;
}

type Box

type Box struct {
	BoxHeader BoxHeader
	Payload   []byte
}

ISO/IEC 14496-12

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
}

type BoxHeader

type BoxHeader struct {
	Size     uint32
	Type     Type
	UserType UUID
}

ISO/IEC 14496-12

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;
   }
}

type EncryptionSample

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

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

type File

type File struct {
	Boxes         []Box
	MediaData     *MediaData
	Movie         *Movie
	MovieFragment *MovieFragment
	SegmentIndex  *SegmentIndex
}

ISO/IEC 14496-12

func (*File) Read added in v1.2.6

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

func (File) Write added in v1.2.6

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

type FullBoxHeader

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

ISO/IEC 14496-12

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

type Media added in v1.2.3

type Media struct {
	BoxHeader        BoxHeader
	Boxes            []Box
	MediaInformation MediaInformation
}

ISO/IEC 14496-12

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

type MediaData added in v1.2.3

type MediaData struct {
	Box Box
}

ISO/IEC 14496-12

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

func (MediaData) Data added in v1.2.3

func (m MediaData) Data(run TrackRun) [][]byte

type MediaInformation added in v1.2.3

type MediaInformation struct {
	BoxHeader   BoxHeader
	Boxes       []Box
	SampleTable SampleTable
}

ISO/IEC 14496-12

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

type Movie added in v1.2.3

type Movie struct {
	BoxHeader  BoxHeader
	Boxes      []*Box
	Protection []ProtectionSystemSpecificHeader
	Track      Track
}

ISO/IEC 14496-12

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

func (Movie) Widevine added in v1.2.9

func (m Movie) Widevine() ([]uint8, bool)

dashif.org/identifiers/content_protection

type MovieFragment added in v1.2.3

type MovieFragment struct {
	BoxHeader     BoxHeader
	Boxes         []Box
	TrackFragment TrackFragment
}

ISO/IEC 14496-12

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

type OriginalFormat added in v1.2.3

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

ISO/IEC 14496-12

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)
}

type ProtectionSchemeInfo added in v1.2.3

type ProtectionSchemeInfo struct {
	BoxHeader         BoxHeader
	Boxes             []Box
	OriginalFormat    OriginalFormat
	SchemeInformation SchemeInformation
}

ISO/IEC 14496-12

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

type ProtectionSystemSpecificHeader added in v1.2.3

type ProtectionSystemSpecificHeader struct {
	BoxHeader     BoxHeader
	FullBoxHeader FullBoxHeader
	SystemId      UUID
	DataSize      uint32
	Data          []uint8
}

ISO/IEC 23001-7

aligned(8) class ProtectionSystemSpecificHeaderBox extends FullBox(
   'pssh', version, flags=0,
) {
   unsigned int(8)[16] SystemID;
   if (version > 0) {
      unsigned int(32) KID_count;
      {
         unsigned int(8)[16] KID;
      } [KID_count];
   }
   unsigned int(32) DataSize;
   unsigned int(8)[DataSize] Data;
}

type Reference added in v1.0.7

type Reference [3]uint32

func (Reference) ReferencedSize added in v1.1.5

func (r Reference) ReferencedSize() uint32

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

type RunSample added in v1.2.3

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

type SampleDescription added in v1.2.3

type SampleDescription struct {
	BoxHeader     BoxHeader
	FullBoxHeader FullBoxHeader
	EntryCount    uint32
	Boxes         []Box
	AudioSample   *AudioSampleEntry
	VisualSample  *VisualSampleEntry
}

ISO/IEC 14496-12

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 (SampleDescription) Protection added in v1.3.1

func (s SampleDescription) Protection() (*ProtectionSchemeInfo, bool)

enca encv

sinf

func (SampleDescription) SampleEntry added in v1.3.2

func (s SampleDescription) SampleEntry() (*SampleEntry, bool)

stsd

enca
encv

type SampleEncryption added in v1.2.3

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

ISO/IEC 23001-7

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 ]
}

type SampleEntry

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

ISO/IEC 14496-12

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;
}

type SampleTable added in v1.2.3

type SampleTable struct {
	BoxHeader         BoxHeader
	Boxes             []Box
	SampleDescription SampleDescription
}

ISO/IEC 14496-12

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

type SchemeInformation added in v1.3.0

type SchemeInformation struct {
	BoxHeader       BoxHeader
	TrackEncryption TrackEncryption
}

ISO/IEC 14496-12

aligned(8) class SchemeInformationBox extends Box('schi') {
   Box scheme_specific_data[];
}

type SegmentIndex added in v1.2.3

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

ISO/IEC 14496-12

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 (*SegmentIndex) Append added in v1.2.3

func (s *SegmentIndex) Append(size uint32)

func (*SegmentIndex) New added in v1.2.3

func (s *SegmentIndex) New()

type Subsample

type Subsample struct {
	BytesOfClearData     uint16
	BytesOfProtectedData uint32
}

type Track added in v1.2.3

type Track struct {
	BoxHeader BoxHeader
	Boxes     []Box
	Media     Media
}

ISO/IEC 14496-12

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

type TrackEncryption added in v1.3.0

type TrackEncryption struct {
	BoxHeader     BoxHeader
	FullBoxHeader FullBoxHeader
	Extends       struct {
		DefaultIsProtected     uint8
		DefaultPerSampleIvSize uint8
		// contains filtered or unexported fields
	}
	DefaultKid UUID
}

ISO/IEC 23001-7

aligned(8) class TrackEncryptionBox extends FullBox('tenc', version, flags=0) {
   unsigned int(8) reserved = 0;
   if (version==0) {
      unsigned int(8) reserved = 0;
   } else { // version is 1 or greater
      unsigned int(4) default_crypt_byte_block;
      unsigned int(4) default_skip_byte_block;
   }
   unsigned int(8) default_isProtected;
   unsigned int(8) default_Per_Sample_IV_Size;
   unsigned int(8)[16] default_KID;
   if (default_isProtected ==1 && default_Per_Sample_IV_Size == 0) {
      unsigned int(8) default_constant_IV_size;
      unsigned int(8)[default_constant_IV_size] default_constant_IV;
   }
}

type TrackFragment added in v1.2.3

type TrackFragment struct {
	BoxHeader        BoxHeader
	Boxes            []Box
	SampleEncryption *SampleEncryption
	TrackRun         TrackRun
}

ISO/IEC 14496-12

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

type TrackRun added in v1.2.3

type TrackRun struct {
	BoxHeader        BoxHeader
	FullBoxHeader    FullBoxHeader
	SampleCount      uint32
	DataOffset       int32
	FirstSampleFlags uint32
	Sample           []RunSample
}

ISO/IEC 14496-12

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 ]
}

type Type added in v1.2.7

type Type [4]uint8

func (Type) MarshalText added in v1.3.6

func (t Type) MarshalText() ([]byte, error)

func (Type) String added in v1.2.7

func (t Type) String() string

type UUID added in v1.2.7

type UUID [16]uint8

func (UUID) String added in v1.2.7

func (u UUID) String() string

type VisualSampleEntry

type VisualSampleEntry struct {
	SampleEntry SampleEntry
	Extends     struct {
		Width           uint16
		Height          uint16
		HorizResolution uint32
		VertResolution  uint32

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

ISO/IEC 14496-12

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
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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