private bool ReadTag() { if (_fileLength - _fileOffset < 11) { return(false); } // Read tag header var tagType = ReadUInt8(); var dataSize = ReadUInt24(); var timeStamp = ReadUInt24(); timeStamp |= ReadUInt8() << 24; ReadUInt24(); //streamID // Read tag data if (dataSize == 0) { return(true); } if (_fileLength - _fileOffset < dataSize) { return(false); } var mediaInfo = ReadUInt8(); dataSize -= 1; var data = ReadBytes((int)dataSize); if (tagType == 0x8) { // Audio if (_audioWriter == null) { _audioWriter = _extractAudio ? GetAudioWriter(mediaInfo) : new DummyAudioWriter(); ExtractedAudio = !(_audioWriter is DummyAudioWriter); } _audioWriter.WriteChunk(data, timeStamp); } else if (tagType == 0x9 && mediaInfo >> 4 != 5) { // Video if (_videoWriter == null) { _videoWriter = _extractVideo ? GetVideoWriter(mediaInfo) : new DummyVideoWriter(); ExtractedVideo = !(_videoWriter is DummyVideoWriter); } if (_timeCodeWriter == null) { var path = $@"{_outputPathBase}.txt"; _timeCodeWriter = new TimeCodeWriter(_extractTimeCodes && CanWriteTo(path) ? path : null); ExtractedTimeCodes = _extractTimeCodes; } _videoTimeStamps.Add(timeStamp); _videoWriter.WriteChunk(data, timeStamp, (int)((mediaInfo & 0xF0) >> 4)); _timeCodeWriter.Write(timeStamp); } return(true); }
private void CloseOutput(FractionUInt32?averageFrameRate, bool disposing) { if (_videoWriter != null) { _videoWriter.Finish(averageFrameRate ?? new FractionUInt32(25, 1)); if (disposing && _videoWriter.Path != null) { try { File.Delete(_videoWriter.Path); } catch { // ignored } } _videoWriter = null; } if (_audioWriter != null) { _audioWriter.Finish(); if (disposing && _audioWriter.Path != null) { try { File.Delete(_audioWriter.Path); } catch { // ignored } } _audioWriter = null; } if (_timeCodeWriter != null) { _timeCodeWriter.Finish(); if (disposing && _timeCodeWriter.Path != null) { try { File.Delete(_timeCodeWriter.Path); } catch { // ignored } } _timeCodeWriter = null; } }