Class IsoFormatParser
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
forReadingbooltrueto configure the parser for reading;falseto configure it for writing.
Properties
CurrentState
Gets the current state of the parser.
public IsoFormatParser.State CurrentState { get; }
Property Value
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
Duration
Gets the file duration in InternalTimescale timescale units.
public long Duration { get; }
Property Value
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
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
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
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
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
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
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
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
dataPacketVersatileBufferThe data packet to decode, or
nullto process buffered data only.positionintThe starting position within the data packet.
bytesToReadintThe number of bytes to read from the data packet.
filePositionlongThe file position corresponding to the data packet, or
long.MinValueif sequential.
Returns
- List<VersatileBuffer>
A list of decoded media sample buffers, or
nullif 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
dataPacketVersatileBufferThe data packet to decode, or
nullto process buffered data only.filePositionlongThe file position corresponding to the data packet, or
long.MinValueif sequential.
Returns
- List<VersatileBuffer>
A list of decoded media sample buffers, or
nullif 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
streamVersatileBufferStreamThe buffer stream containing data to decode, or
nullto process buffered data only.filePositionlongThe file position corresponding to the stream data, or
long.MinValueif sequential.
Returns
- List<VersatileBuffer>
A list of decoded media sample buffers, or
nullif 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
sampleVersatileBufferThe media sample buffer to encode and write.
streamIndexintThe 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
discontinuityboolA value indicating whether a discontinuity should be signaled in the stream.
fragmentSequenceNouintThe fragment sequence number to use when starting a new segment after a discontinuity.
baseMediaDecodeTimelongThe base media decode time for the new segment, or
long.MinValueto continue from the last timestamp.
GetOutputStream()
Gets the underlying output stream used by the writer.
public Stream GetOutputStream()
Returns
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
timestamplongThe 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
streamStreamThe 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
filePathstringThe path to the output file to create.