Table of Contents

Class IsoFormatParser

Namespace
VAST.File.ISO
Assembly
VAST.File.ISO.dll

Provides parsing and writing capabilities for the ISO base media file format (ISOBMFF/MP4). Supports reading media samples from MP4 files and writing media samples to MP4 files, including fragmented MP4 (fMP4) segments.

public class IsoFormatParser : IDisposable
Inheritance
IsoFormatParser
Implements
Inherited Members

Constructors

IsoFormatParser(bool)

Initializes a new instance of the IsoFormatParser class.

public IsoFormatParser(bool forReading)

Parameters

forReading bool

true to configure the parser for reading; false to configure it for writing.

Properties

CurrentState

Gets the current state of the parser.

public IsoFormatParser.State CurrentState { get; }

Property Value

IsoFormatParser.State

DesiredFilePosition

Gets the desired file position that the reader needs to seek to, or long.MinValue if no seek is required.

public long DesiredFilePosition { get; }

Property Value

long

Duration

Gets the file duration in InternalTimescale timescale units.

public long Duration { get; }

Property Value

long

ExtendedStreamDescriptor

Gets the extended stream descriptors including sample DTS timestamps and clean point (keyframe) information for each stream. Returns null if the parser is not in the ParsingMedia or Eof state.

public List<NewStreamEventArgs> ExtendedStreamDescriptor { get; }

Property Value

List<NewStreamEventArgs>

FileSize

Gets or sets the total file size in bytes. Used to determine when the end of the file has been reached.

public long FileSize { get; set; }

Property Value

long

ModificationTime

Gets the most recent modification time across all tracks and the movie header in the file. Returns MinValue if no movie box is available.

public DateTime ModificationTime { get; }

Property Value

DateTime

NtpTime

Gets or sets the NTP time stored in the VAST general metadata box. Returns MinValue if no VAST general box is present.

public DateTime NtpTime { get; set; }

Property Value

DateTime

Parameters

Gets or sets the parsing parameters that control the behavior of the parser and writer. When set, copies the initial parameters from the provided value and ensures PreserveNals is true when reading.

public ParsingParameters Parameters { get; set; }

Property Value

ParsingParameters

StreamDescriptor

Gets the list of media type descriptors for each stream in the file, or sets the stream descriptors to initialize the writer. Returns null if the parser is not in the ParsingMedia or Eof state.

public List<MediaType> StreamDescriptor { get; set; }

Property Value

List<MediaType>

WritingState

Gets or sets the current writing state of the file. Returns Undetermined if no VAST general box is present.

public WritingState WritingState { get; set; }

Property Value

WritingState

Methods

CloneShallow()

Creates a shallow copy of this parser instance for concurrent reading from the same source. Only supported for reader instances. The shallow copy shares the movie box and stream metadata but creates independent media data box copies.

public IsoFormatParser CloneShallow()

Returns

IsoFormatParser

A new IsoFormatParser instance that is a shallow copy of this parser.

Decode(VersatileBuffer, int, int, long)

Decodes media samples from a portion of the specified data packet.

public List<VersatileBuffer> Decode(VersatileBuffer dataPacket, int position, int bytesToRead, long filePosition = -9223372036854775808)

Parameters

dataPacket VersatileBuffer

The data packet to decode, or null to process buffered data only.

position int

The starting position within the data packet.

bytesToRead int

The number of bytes to read from the data packet.

filePosition long

The file position corresponding to the data packet, or long.MinValue if sequential.

Returns

List<VersatileBuffer>

A list of decoded media sample buffers, or null if no samples are available yet.

Decode(VersatileBuffer, long)

Decodes media samples from the specified data packet.

public List<VersatileBuffer> Decode(VersatileBuffer dataPacket, long filePosition = -9223372036854775808)

Parameters

dataPacket VersatileBuffer

The data packet to decode, or null to process buffered data only.

filePosition long

The file position corresponding to the data packet, or long.MinValue if sequential.

Returns

List<VersatileBuffer>

A list of decoded media sample buffers, or null if no samples are available yet.

Decode(VersatileBufferStream, long)

Decodes media samples from the specified buffer stream.

public List<VersatileBuffer> Decode(VersatileBufferStream stream, long filePosition = -9223372036854775808)

Parameters

stream VersatileBufferStream

The buffer stream containing data to decode, or null to process buffered data only.

filePosition long

The file position corresponding to the stream data, or long.MinValue if sequential.

Returns

List<VersatileBuffer>

A list of decoded media sample buffers, or null if no samples are available yet.

Dispose()

Releases all resources used by this IsoFormatParser instance, including readers, writers, boxes, streams, and sample buffers.

public void Dispose()

Encode(VersatileBuffer, int)

Encodes and writes a media sample to the output stream for the specified stream index. Handles H.264/H.265 bitstream format conversion from Annex B to AVC format as needed.

public void Encode(VersatileBuffer sample, int streamIndex)

Parameters

sample VersatileBuffer

The media sample buffer to encode and write.

streamIndex int

The zero-based index of the stream to write the sample to.

Flush()

Flushes all pending data to the output stream without discontinuity.

public void Flush()

Flush(bool, uint, long)

Flushes all pending data to the output stream, optionally starting a new segment with the specified discontinuity and timing parameters.

public void Flush(bool discontinuity, uint fragmentSequenceNo, long baseMediaDecodeTime)

Parameters

discontinuity bool

A value indicating whether a discontinuity should be signaled in the stream.

fragmentSequenceNo uint

The fragment sequence number to use when starting a new segment after a discontinuity.

baseMediaDecodeTime long

The base media decode time for the new segment, or long.MinValue to continue from the last timestamp.

GetOutputStream()

Gets the underlying output stream used by the writer.

public Stream GetOutputStream()

Returns

Stream

The output Stream, or null if no writer is configured.

Reset()

Resets the parser to its initial state, disposing all parsed boxes and clearing stream information. Allows reusing the parser instance for a new file.

public void Reset()

Seek(long)

Seeks to the specified timestamp within the file. The timestamp must be within the range of zero to Duration.

public void Seek(long timestamp)

Parameters

timestamp long

The target timestamp in InternalTimescale units.

SetOutputStream(Stream)

Sets the output stream to the specified stream, disposing the previous writer if present.

public void SetOutputStream(Stream stream)

Parameters

stream Stream

The output stream to write to.

SetOutputStream(string)

Sets the output stream to a file at the specified path, creating it with read/write access.

public void SetOutputStream(string filePath)

Parameters

filePath string

The path to the output file to create.