comments: containers IsoBmff Mux / Meta, Iso9660

This commit is contained in:
4DBug committed 2026-11-01 01:57:14 -05:00
1 parent 3cda652143
commit 24cbddaafa
3 files changed
+8 -44

No files matched your search

+1 -10
View File
@@ -32,7 +32,6 @@ local function uint(r: Bytes.Reader, size: number): number
return 0
end
-- ------------------------------------------------------------------------------------------------ HEIF items
export type Property = { type: string, box: Box.Box, [string]: any }
export type Item = {
id: number,
@@ -103,7 +102,6 @@ local function property(b: buffer, box: Box.Box): Property
return p
end
-- items(buf, meta) -> Items | nil, Err (meta: a top-level 'meta' box)
function Meta.items(b: buffer, meta: Box.Box): (Items?, Err.Err?)
local out: Items = { items = {}, order = {}, properties = {} }
local pitm = Box.child(meta, "pitm")
@@ -253,8 +251,6 @@ function Meta.items(b: buffer, meta: Box.Box): (Items?, Err.Err?)
return out, nil
end
-- itemData(buf, base, limit, items, id) -> buffer | nil, Err: the item's bytes (extents concatenated); base / limit
-- bound the file in the buffer
function Meta.itemData(b: buffer, base: number, limit: number, items: Items, id: number): (buffer?, Err.Err?)
local it = items.items[id]
if not it then
@@ -296,7 +292,6 @@ function Meta.itemData(b: buffer, base: number, limit: number, items: Items, id:
return out, nil
end
-- ------------------------------------------------------------------------------------------------ iTunes tags
-- ilst item -> standard tag name
local TAG: { [string]: string } = {
["\169nam"] = "title", ["\169ART"] = "artist", aART = "albumartist", ["\169alb"] = "album", ["\169day"] = "date",
@@ -330,7 +325,6 @@ local GENRES = {
export type Picture = { mime: string, data: buffer }
-- tags(buf, ilst) -> Tags, { Picture }
function Meta.tags(b: buffer, ilst: Box.Box?): ({ [string]: string }, { Picture })
local tags: { [string]: string } = {}
local pics: { Picture } = {}
@@ -396,7 +390,6 @@ function Meta.tags(b: buffer, ilst: Box.Box?): ({ [string]: string }, { Picture
return tags, pics
end
-- ------------------------------------------------------------------------------------------------ ilst writer
local function box(w: Bytes.Writer, typ: string, body: (Bytes.Writer) -> ())
local start = w:tell()
w:u32be(0)
@@ -426,8 +419,6 @@ local function num(s: string?): number
return math.clamp(math.floor(v), 0, 65535)
end
-- writeIlst(w, tags, pictures?): an ilst box with the tags (standard names -> iTunes atoms; unknown names -> '----'
-- freeform com.apple.iTunes items) and cover pictures
function Meta.writeIlst(w: Bytes.Writer, tags: { [string]: string }, pictures: { Picture }?)
box(w, "ilst", function()
local keys = {}
@@ -506,7 +497,7 @@ function Meta.writeIlst(w: Bytes.Writer, tags: { [string]: string }, pictures: {
end)
end
-- writeUdta(w, tags, pictures?): udta / meta (hdlr mdir) / ilst
-- udta / meta (hdlr mdir) / ilst
function Meta.writeUdta(w: Bytes.Writer, tags: { [string]: string }, pictures: { Picture }?)
box(w, "udta", function()
box(w, "meta", function()
+3 -8
View File
@@ -1,9 +1,7 @@
--!strict
-- containers/IsoBmff/Mux: writes a progressive (non-fragmented) ISO BMFF / MP4 / M4A file: ftyp, moov (mvhd, one trak
-- per track with tkhd / edts / mdia / mdhd / hdlr / minf / [sv]mhd / dinf / stbl), the samples interleaved in chunks
-- in one mdat, and udta / meta / ilst tags. moov goes first ("fast start"); co64 replaces stco past 4 GB. Sample
-- entries: audio (mp4a + esds, alac, Opus + dOps, fLaC + dfLa, ...) and video (avc1 / hvc1 / av01 / vp09 / ... +
-- their configuration box), plus any raw child boxes. Never throws: bad specs return nil, Err.ARG.
-- containers/IsoBmff/Mux: writes a progressive ISO BMFF / MP4 / M4A file (ISO/IEC 14496-12): ftyp, moov first ("fast
-- start"), the samples interleaved in chunks in one mdat, udta / meta / ilst tags; co64 past 4 GB. Audio and video
-- sample entries with their configuration box, plus raw child boxes. Never throws: bad specs return nil, Err.ARG.
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Meta = require("@rosetta/containers/IsoBmff/Meta")
@@ -154,7 +152,6 @@ end
type Chunk = { track: number, first: number, count: number, time: number, offset: number }
-- runs of equal values: { { count, value } }
local function runs(n: number, value: (number) -> number): { { number } }
local out = {}
for i = 1, n do
@@ -381,7 +378,6 @@ local function moov(w: Bytes.Writer, spec: MuxSpec, prep: { Prepared }, co64: bo
end)
end
-- mux(spec) -> buffer | nil, Err
function Mux.mux(spec: MuxSpec): (buffer?, Err.Err?)
if type(spec) ~= "table" or type(spec.tracks) ~= "table" or #spec.tracks == 0 then
return nil, Err.new(Err.ARG, "mux: expected { tracks = { ... } }")
@@ -476,7 +472,6 @@ function Mux.mux(spec: MuxSpec): (buffer?, Err.Err?)
end
end
local co64 = mdatSize > 4294967295 - 2 ^ 24
-- ftyp
local w = Bytes.writer(mdatSize + 4096)
box(w, "ftyp", function()
w:string(spec.brand or "isom")