-- video/avi tests: AVI files from ffmpeg (MJPEG + PCM s16 / u8 / IMA ADPCM, MPEG-1 + MP2, uncompressed BGR24 / BGRA / -- I420) read through the OpenDML indexes, idx1 alone, and a movi scan: tracks and every packet against ffprobe, -- frames against ffmpeg, audio through the api hook, seeking; our muxer (MJPEG + PCM) read back; a GIF converted to -- AVI. Fixtures: tools/fixtures/avi.py. local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@formats") local AviFormat = require("@formats/video/avi") local Bytes = require("@formats/core/Bytes") local Crc32 = require("@formats/core/Crc32") local Fx = require("@tests/gen/avi_cases") local t = T.suite("avi") t:eq(AviFormat.name, "avi", "name") t:eq(AviFormat.category, "video", "category") local EXACT_AUDIO = { pcm_s16le = true, pcm_u8 = true, adpcm_ima_wav = true } local byName = {} for _, c in Fx do byName[c.name] = c end for _, c in Fx do local label = c.name t:check(AviFormat.sniff(Bytes.reader(buffer.fromstring(c.data))) > 0, label .. ": sniff") local v, err = C.open(c.data) if c.truncated then t:check(v ~= nil or err ~= nil, label .. ": opens or fails cleanly") else t:check(v ~= nil, label .. ": open: " .. tostring(err)) if v then local dmx = v.demuxer t:eq(#dmx.tracks, #c.streams, label .. ": track count") C.packets(t, dmx, c, label) if c.rgba then v:reset() local n, bad = 0, 0 while true do local f = v:nextFrame() if not f then break end n += 1 if f.image.format ~= "rgba8" or Crc32.of(f.image.pixels) ~= c.rgba[n] then bad += 1 end end t:check(n == #c.rgba and bad == 0, label .. ": " .. n .. " rgba frames equal ffmpeg's (" .. bad .. " differ)") else C.frames(t, v, c, label) end local at = dmx:track("audio") if at then C.audio(t, v, c, label, EXACT_AUDIO[at.codec], 30) end C.seek(t, v, c, label, 0.5) end end end t:eq(C.open(byName["mjpeg_pcm.avi"].data).demuxer.meta.index, "idx1", "ffmpeg's AVI: idx1 used") t:eq(C.open(byName["odml.avi"].data).demuxer.meta.index, "odml", "OpenDML indexes used") t:eq(C.open(byName["idx1_only.avi"].data).demuxer.meta.index, "idx1", "idx1 used without OpenDML indexes") t:eq(C.open(byName["no_index.avi"].data).demuxer.meta.index, "scan", "movi scanned without indexes") -- our muxer: MJPEG copied + PCM, read back packet for packet do local v = C.open(byName["mjpeg_pcm.avi"].data) local out, err = F.save(v, nil, { format = "avi" }) t:check(out ~= nil, "mux avi: " .. tostring(err)) if out then local v2 = F.video.open(out) t:check(v2 ~= nil, "mux avi: reads back") if v2 then local a, b = v.demuxer, v2.demuxer local same = a:count(1) == b:count(1) for k = 1, a:count(1) do local p, q = a:get(1, k), b:get(1, k) if not q or buffer.tostring(p.data) ~= buffer.tostring(q.data) then same = false end end t:check(same, "mux avi: identical MJPEG packets") t:eq(v2.frameRate, 10, "mux avi: frame rate") C.audio(t, v2, byName["mjpeg_pcm.avi"], "mux avi", true) end end end -- fuzz local samples = {} for _, n in { "mjpeg_pcm.avi", "mjpeg_ima.avi", "idx1_only.avi", "i420.avi" } do local d = byName[n].data table.insert(samples, string.sub(d, 1, math.min(#d, 40000))) end t:fuzz("open", C.fuzzOpen(AviFormat), samples, { mutations = 6, garbage = 100 }) t:done()