public static VideoInfo TryReadVideoInfoViaAviHeader(string fileName) { var info = new VideoInfo { Success = false }; try { using (var rp = new RiffParser()) { if (rp.TryOpenFile(fileName) && rp.FileType == RiffParser.ckidAVI) { var dh = new RiffDecodeHeader(rp); dh.ProcessMainAVI(); info.FileType = RiffParser.FromFourCC(rp.FileType); info.Width = dh.Width; info.Height = dh.Height; info.FramesPerSecond = dh.FrameRate; info.TotalFrames = dh.TotalFrames; info.TotalMilliseconds = dh.TotalMilliseconds; info.TotalSeconds = info.TotalMilliseconds / TimeCode.BaseUnit; info.VideoCodec = dh.VideoHandler; info.Success = true; } } } catch { } return info; }
/// <summary> /// Non-thread-safe read a single int from the stream /// </summary> /// <param name="fourCc">Output int</param> public void ReadOneInt(out int fourCc) { try { var buffer = new byte[DWordSize]; int readsize = _stream.Read(buffer, 0, DWordSize); if (DWordSize != readsize) { throw new RiffParserException("Unable to read. Corrupt RIFF file " + FileName); } fourCc = RiffDecodeHeader.GetInt(buffer, 0); } catch (Exception ex) { throw new RiffParserException("Problem accessing RIFF file " + FileName, ex); } }