protected BaseAtom(MP4Document document, uint type, long size, long start) { Start = start; Size = size; Type = type; document.AddAtom(this); Document = document; }
public MP4Document Build(Movie movie) { if (Fragmenter == null) { Fragmenter = new TimeBasedFragmenter(); } Track2Sample = movie.Tracks.ToDictionary(x => x, y => y.Samples); Track2SampleSizes = movie.Tracks.ToDictionary(x => x, y => y.Samples.Select(x => x.Size).ToArray()); var meta = Variant.Get(); MP4Document doc = new MP4Document(meta); doc.AddAtom(CreateFileTypeBox(movie)); var chunks = movie.Tracks.ToDictionary(x => x, GetChunkSizes); var moov = CreateMovieBox(movie, chunks); doc.AddAtom(moov); var contentSize = moov.GetPath(TRAK, MDIA, MINF, STBL, STSZ).OfType <AtomSTSZ>().Sum(x => x.SampleSize); var mdat = new AtomMDAT(movie, chunks, contentSize); doc.AddAtom(mdat); /* * dataOffset is where the first sample starts. In this special mdat the samples always start * at offset 16 so that we can use the same offset for large boxes and small boxes */ uint dataOffset = mdat.DataOffset; foreach (var chunkOffsetBox in ChunkOffsetBoxes.Values) { for (var i = 0; i < chunkOffsetBox.Entries.Count; i++) { chunkOffsetBox.Entries[i] += dataOffset; } } foreach (var saio in SampleAuxiliaryInformationOffsetsBoxes) { long offset = saio.Size; // the calculation is systematically wrong by 4, I don't want to debug why. Just a quick correction --san 14.May.13 offset += 4 + 4 + 4 + 4 + 4 + 24; // size of all header we were missing otherwise (moov, trak, mdia, minf, stbl) object b = saio; do { BaseAtom current = (BaseAtom)b; b = current.Parent; offset += ((IBoxContainer)b).SubAtoms.TakeWhile(box => box != current).Sum(box => box.Size); } while (b is BoxAtom); long[] saioOffsets = saio.Offsets; for (int i = 0; i < saioOffsets.Length; i++) { saioOffsets[i] += offset; } } return(doc); }
public AtomFTYP(MP4Document document, long size, long start) : base(document, FTYP, size, start) { }
public AtomCTTS(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { Entries = new List <Entry>(); }
public AtomMetaField(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { }
public IgnoredAtom(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { }
public AtomDINF(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { }
protected HeaderAtom(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { }
protected VersionedBoxAtom(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { }
public AtomUDTA(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { }
public static bool ResolveCompleteMetadata(ref Variant metaData) { if (metaData[CONF_APPLICATION_EXTERNSEEKGENERATOR]) { return(false); } BaseMediaDocument pDocument; if (false) { } #if HAS_MEDIA_FLV else if ((string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_FLV || (string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_LIVE_OR_FLV) { pDocument = new FLVDocument(metaData); } #endif #if HAS_MEDIA_MP3 else if ((string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_MP3) { pDocument = new MP3Document(metaData); } #endif #if HAS_MEDIA_MP4 else if ((string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_MP4 || (string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_M4A || (string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_M4V || (string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_MOV || (string)metaData[META_MEDIA_TYPE] == MEDIA_TYPE_F4V) { pDocument = new MP4Document(metaData); } #endif #if HAS_MEDIA_NSV else if (metaData[Defines.META_MEDIA_TYPE] == Defines.MEDIA_TYPE_NSV) { pDocument = new NSVDocument(metaData); } #endif else { Logger.FATAL("File type not supported yet. Partial metadata:\n{0}", metaData.ToString()); return(false); } //2. Process the document metaData.Log().Info("Processing file {0}", metaData[META_SERVER_FULL_PATH]); if (!pDocument.Process()) { Logger.FATAL("Unable to process document"); //pDocument.Dispose(); if (metaData[CONF_APPLICATION_RENAMEBADFILES]) { File.Move((string)metaData[META_SERVER_FULL_PATH], metaData[META_SERVER_FULL_PATH] + ".bad"); } else { Logger.WARN("File {0} will not be renamed", metaData[META_SERVER_FULL_PATH]); } return(false); } //3. Get the medatada metaData = pDocument.MetaData; return(true); }
public AtomSTCO(MP4Document document, uint type, long size, long start) : base(document, STCO, size, start) { }
public AtomSTSC(MP4Document document, uint type, long size, long start) : base(document, type, size, start) { Entries = new List<Entry>(); }