readVideoInfo function

VideoInfo? readVideoInfo(
  1. List<int> bytes
)

Dimensions, duration, frame rate and codec of an MP4 or QuickTime file, or null if bytes is neither.

Null means "not a container this can read", which is a fact about the file and not a verdict on it — the caller turns it into a message naming the path, exactly as it does for readImageInfo's null.

Implementation

VideoInfo? readVideoInfo(List<int> bytes) {
  final container = _container(bytes);
  if (container == null) {
    return null;
  }

  final moov = _findBox(bytes, 0, bytes.length, 'moov');
  if (moov == null) {
    // A file whose `moov` sits after the media data and was truncated, or one
    // that is not really an ISO base media file behind an `ftyp` this
    // recognised. Either way there is nothing to read.
    return null;
  }

  final movie = _readMvhd(bytes, moov);
  final track = _findVideoTrack(bytes, moov);
  if (movie == null || track == null) {
    return null;
  }

  return VideoInfo(
    width: track.width,
    height: track.height,
    duration: movie,
    frameRate: track.frameRate,
    codec: track.codec,
    container: container,
    fileSize: bytes.length,
    audioChannels: _readAudioChannels(bytes, moov),
  );
}