- if fourcc == "mdat" && size == 0 do
- # mdat with 0 size means "seek to the end" -- also, in that case the file is probably OK.
- acc = [
- {fourcc, pos, byte_size(bin) - pos, byte_size(bin) - pos,
- <<size::integer-big-size(4)-unit(8), fourcc::binary-size(4), rest::binary>>}
- | acc
- ]
-
- fix(<<>>, bin, byte_size(bin), acc)
- else
- full_size = size - 8
- <<data::binary-size(full_size), rest::binary>> = rest
-
- acc = [
- {fourcc, pos, pos + size, size,
- <<size::integer-big-size(4)-unit(8), fourcc::binary-size(4), data::binary>>}
- | acc
- ]
-
- fix(rest, bin, pos + size, acc)
- end
+ full_size = (size - 8) * 8
+ <<data::bits-size(full_size), rest::bits>> = rest
+
+ acc = [
+ {fourcc, pos, pos + size, size,
+ <<size::integer-big-size(32), fourcc::bits-size(32), data::bits>>}
+ | acc
+ ]
+
+ fix(rest, pos + size, got_moov || fourcc == "moov", got_mdat || fourcc == "mdat", acc)
+ end
+
+ defp fix(<<>>, _pos, _, _, acc) do
+ :lists.reverse(acc)