#!/usr/bin/env fq -d mp4 -f

( first(.boxes[] | select(.type == "moov")?)
| first(.boxes[] | select(.type == "mvhd")?) as $mvhd
| { time_scale: $mvhd.time_scale,
    duration: ($mvhd.duration / $mvhd.time_scale),
    tracks:
      [ .boxes[]
      | select(.type == "trak")
      | [("mdhd", "stsd", "elst") as $t | first(grep_by(.type == $t))] as [$mdhd, $stsd, $elst]
      | { data_format: $stsd.boxes[0].type,
          media_scale: $mdhd.time_scale,
          edit_list:
            [ $elst.entries[]
            | { track_duration: (.segment_duration / $mvhd.time_scale),
                media_time: (.media_time / $mdhd.time_scale)
              }
            ]
        }
      ]
  }
)