comments: containers Avi / Zip
This commit is contained in:
1 parent
24cbddaafa
commit
9c096a6331
2 files changed
+11
-60
No files matched your search
@@ -1,16 +1,7 @@
|
||||
--!strict
|
||||
-- containers/Avi: the AVI RIFF form (Microsoft AVI 1.0 + the OpenDML 1.02 extensions). New in rosetta.
|
||||
-- Reading: hdrl (avih, strl: strh / strf / strn / indx), every RIFF piece (RIFF AVI + RIFF AVIX ...), and the chunk
|
||||
-- index of every stream: from the OpenDML super index (indx -> ix## standard / field indexes), else idx1 (offsets
|
||||
-- relative to the movi list or absolute, detected), else a linear scan of the movi lists (LIST rec included).
|
||||
-- Writing: AVI 1.0 (avih, strl, LIST movi, idx1) with an OpenDML odml / dmlh header, chunks interleaved as given.
|
||||
--
|
||||
-- local avi, err = Avi.read(buf, base, limit)
|
||||
-- avi.streams[i] = { type = "vids" | "auds" | ..., handler, scale, rate, start, length, sampleSize, strf
|
||||
-- (buffer), name, chunks = { { offset, size, key } } } -- offsets of the chunk data, absolute
|
||||
-- local w = Avi.writer({ streams = {...}, avih = {...} }); w:chunk(streamIndex, data, key); local file = w:finish()
|
||||
-- local bi = Avi.bitmapInfo(strf) -- a BITMAPINFOHEADER: size, depth, FourCC, palette (also Matroska VFW)
|
||||
--
|
||||
-- containers/Avi: the AVI RIFF form (Microsoft AVI 1.0 + OpenDML 1.02), read and written. New in rosetta. The chunk
|
||||
-- index comes from the OpenDML super index (indx -> ix##), else idx1 (movi-relative or absolute, detected), else a
|
||||
-- scan of the movi lists. Writing: AVI 1.0 (avih, strl, LIST movi, idx1) with an odml / dmlh header.
|
||||
-- Never throws: malformed data returns nil, Err (a damaged index falls back to scanning).
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -48,8 +39,6 @@ local function u32(b: buffer, o: number): number
|
||||
return readu32(b, o)
|
||||
end
|
||||
|
||||
-- chunk walker over [p, limit): calls fn(id, dataOffset, size, listType?) for each chunk (LIST bodies are not
|
||||
-- entered); returns where it stopped
|
||||
local function walk(b: buffer, p: number, limit: number, fn: (id: string, data: number, size: number, ltype: string?) -> boolean?): number
|
||||
while p + 8 <= limit do
|
||||
local id = readstring(b, p, 4)
|
||||
@@ -193,7 +182,6 @@ local function readIndex(b: buffer, d: number, n: number, s: Stream, limit: numb
|
||||
return false
|
||||
end
|
||||
|
||||
-- read(buf, base, limit) -> File | nil, Err
|
||||
function Avi.read(b: buffer, base: number, limit: number): (File?, Err.Err?)
|
||||
if limit - base < 12 or readstring(b, base, 4) ~= "RIFF" or readstring(b, base + 8, 4) ~= "AVI " then
|
||||
return nil, Err.new(Err.CORRUPT, "not an AVI file", base)
|
||||
@@ -342,7 +330,6 @@ function Avi.read(b: buffer, base: number, limit: number): (File?, Err.Err?)
|
||||
return file, nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ writing
|
||||
export type WStream = {
|
||||
type: string, -- "vids" | "auds"
|
||||
handler: string, -- fccHandler (4 chars)
|
||||
@@ -364,7 +351,6 @@ export type WOptions = {
|
||||
software: string?,
|
||||
}
|
||||
|
||||
-- write(opts, chunks) -> buffer: chunks = { { stream (1-based), data: buffer, key: boolean } } in file order
|
||||
function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
||||
local ns = #opts.streams
|
||||
local lengths = table.create(ns, 0)
|
||||
@@ -397,7 +383,6 @@ function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
||||
local riffSize = w:tell()
|
||||
w:u32le(0)
|
||||
w:string("AVI ")
|
||||
-- hdrl
|
||||
w:string("LIST")
|
||||
local hdrlSize = w:tell()
|
||||
w:u32le(0)
|
||||
@@ -475,7 +460,6 @@ function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
||||
w:u32le(4)
|
||||
w:u32le(frames)
|
||||
w:setU32le(hdrlSize, w:tell() - hdrlSize - 4)
|
||||
-- INFO
|
||||
local sw = (opts.software or "rosetta") .. "\0"
|
||||
if #sw % 2 == 1 then
|
||||
sw ..= "\0"
|
||||
@@ -486,7 +470,6 @@ function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
||||
w:string("ISFT")
|
||||
w:u32le(#sw)
|
||||
w:string(sw)
|
||||
-- movi
|
||||
w:string("LIST")
|
||||
local moviSize = w:tell()
|
||||
w:u32le(0)
|
||||
@@ -508,7 +491,6 @@ function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
||||
table.insert(index, { id, if key then 0x10 else 0, at - moviBase, n })
|
||||
end
|
||||
w:setU32le(moviSize, w:tell() - moviSize - 4)
|
||||
-- idx1
|
||||
w:string("idx1")
|
||||
w:u32le(#index * 16)
|
||||
for _, e in index do
|
||||
@@ -521,7 +503,6 @@ function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
||||
return w:finish()
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ BITMAPINFO
|
||||
export type BitmapInfo = {
|
||||
width: number,
|
||||
height: number, -- signed: > 0 = bottom-up rows
|
||||
@@ -531,9 +512,8 @@ export type BitmapInfo = {
|
||||
extra: buffer?, -- the bytes after the 40-byte header (palette included), nil when none
|
||||
}
|
||||
|
||||
-- bitmapInfo(f) -> the BITMAPINFOHEADER facts of an AVI video strf (or a Matroska V_MS/VFW/FOURCC CodecPrivate) |
|
||||
-- nil when shorter than 40 bytes. The palette is the last (2^bits) * 4 bytes after the header (B, G, R, x entries;
|
||||
-- a trailing "BottomUp" tag is skipped), as the VfW codecs store it.
|
||||
-- BITMAPINFOHEADER: the palette is the last (2^bits) * 4 bytes after the header (B, G, R, x; a trailing "BottomUp"
|
||||
-- tag skipped), as the VfW codecs store it
|
||||
function Avi.bitmapInfo(f: buffer): BitmapInfo?
|
||||
local n = buffer.len(f)
|
||||
if n < 40 then
|
||||
|
||||
Reference in new issue
Block a user