comments: containers MpegTs / IsoBmff Demux
This commit is contained in:
1 parent
a0a11af953
commit
facdf124a1
2 files changed
+5
-49
No files matched your search
@@ -1,10 +1,7 @@
|
||||
--!strict
|
||||
-- containers/IsoBmff/Demux: tracks and sample tables of an ISO BMFF / QuickTime file (ISO/IEC 14496-12 8.3 - 8.8):
|
||||
-- tkhd / mdhd / hdlr, sample descriptions (audio v0 / QuickTime v1 / v2, video, other) with the codec configuration
|
||||
-- (esds DecoderSpecificInfo, alac, dOps, dfLa, avcC, hvcC, av1C, vpcC, dac3, ...), stts / ctts / stsc / stsz / stz2 /
|
||||
-- stco / co64 / stss, edit lists (elst), and fragmented files (mvex / trex, moof / traf / tfhd / tfdt / trun).
|
||||
-- The per-sample tables are columnar arrays (offsets / sizes / dts / durations / cts / sync), offsets absolute in the
|
||||
-- reader's buffer. Never throws.
|
||||
-- containers/IsoBmff/Demux: tracks and sample tables of an ISO BMFF / QuickTime file (ISO/IEC 14496-12 8.3 - 8.8),
|
||||
-- edit lists and fragments (mvex / trex, moof / traf / tfhd / tfdt / trun). The per-sample tables are columnar arrays,
|
||||
-- offsets absolute in the reader's buffer. Never throws.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Box = require("@rosetta/containers/IsoBmff/Box")
|
||||
@@ -20,8 +17,6 @@ local Demux = {}
|
||||
|
||||
export type Edit = { duration: number, mediaTime: number, rate: number } -- duration in movie ticks, mediaTime in media ticks (-1 = empty)
|
||||
|
||||
-- a track: Types.Track (id, kind, codec, timescale, duration, width, height, sampleRate, channels, config) plus the
|
||||
-- sample tables and the ISO facts
|
||||
export type Track = {
|
||||
id: number,
|
||||
kind: "video" | "audio" | "subtitle" | "data",
|
||||
@@ -47,7 +42,6 @@ export type Track = {
|
||||
skip: number, -- media ticks to drop at the start (the first edit's media time: AAC priming)
|
||||
delay: number, -- movie ticks of an initial empty edit
|
||||
playDuration: number?, -- media ticks the edit list plays (nil: all)
|
||||
-- samples
|
||||
sampleCount: number,
|
||||
offsets: { number }, -- absolute offsets in the buffer
|
||||
sizes: { number },
|
||||
@@ -110,7 +104,6 @@ local function descLen(r: Bytes.Reader): number
|
||||
return n
|
||||
end
|
||||
|
||||
-- esds -> objectTypeIndication, DecoderSpecificInfo, avg bitrate
|
||||
function Demux.esds(b: buffer, box: Box.Box): (number?, buffer?, number?)
|
||||
local r = reader(b, box)
|
||||
r:skip(4) -- version / flags
|
||||
@@ -150,7 +143,6 @@ function Demux.esds(b: buffer, box: Box.Box): (number?, buffer?, number?)
|
||||
return oti, dsi, avg
|
||||
end
|
||||
|
||||
-- the sample entry `e` of a track with handler `handler`: fills the codec facts into t
|
||||
local function sampleEntry(b: buffer, e: Box.Box, handler: string, t: Track)
|
||||
local r = reader(b, e)
|
||||
r:skip(6)
|
||||
@@ -253,7 +245,6 @@ local function sampleEntry(b: buffer, e: Box.Box, handler: string, t: Track)
|
||||
end
|
||||
end
|
||||
|
||||
-- media handler / header / sample tables of one trak -> Track | nil, Err
|
||||
local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [number]: any }, o: Options): (Track?, Err.Err?)
|
||||
local tkhd = Box.child(trak, "tkhd")
|
||||
local mdia = Box.child(trak, "mdia")
|
||||
@@ -321,7 +312,6 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
if not stbl then
|
||||
return nil, Err.new(Err.CORRUPT, "track " .. t.id .. " has no sample table", mdia.start)
|
||||
end
|
||||
-- sample descriptions
|
||||
local stsd = Box.child(stbl, "stsd")
|
||||
if stsd and stsd.data + 8 <= stsd.stop then
|
||||
local entries = Box.list(b, stsd.data + 8, stsd.stop, "stsd")
|
||||
@@ -330,7 +320,6 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
end
|
||||
t.sampleEntries = entries
|
||||
end
|
||||
-- edit list
|
||||
local elst = Box.path(trak, "edts/elst")
|
||||
if elst then
|
||||
local r = reader(b, elst)
|
||||
@@ -373,7 +362,6 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
end
|
||||
end
|
||||
end
|
||||
-- sample sizes
|
||||
local maxSamples = o.maxSamples or 2 ^ 25
|
||||
local sizes = t.sizes
|
||||
local count = 0
|
||||
@@ -432,7 +420,6 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
end
|
||||
end
|
||||
end
|
||||
-- decode times
|
||||
local dts, durs = t.dts, t.durations
|
||||
local stts = Box.child(stbl, "stts")
|
||||
if stts and count > 0 then
|
||||
@@ -466,7 +453,6 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
dts[i], durs[i] = 0, 0
|
||||
end
|
||||
end
|
||||
-- composition offsets
|
||||
local ctts = Box.child(stbl, "ctts")
|
||||
if ctts and count > 0 then
|
||||
local r = reader(b, ctts)
|
||||
@@ -493,7 +479,6 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
t.cts = cts
|
||||
end
|
||||
end
|
||||
-- sync samples
|
||||
local stss = Box.child(stbl, "stss")
|
||||
if stss then
|
||||
local r = reader(b, stss)
|
||||
@@ -507,7 +492,6 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
t.sync = sync
|
||||
end
|
||||
end
|
||||
-- chunk offsets + sample-to-chunk -> sample offsets
|
||||
local stco = Box.child(stbl, "stco")
|
||||
local co64 = Box.child(stbl, "co64")
|
||||
local chunks: { number } = {}
|
||||
@@ -614,12 +598,10 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
||||
t.sampleDescription = nil
|
||||
end
|
||||
end
|
||||
-- fragment defaults
|
||||
t.trex = trex[t.id]
|
||||
return t, nil
|
||||
end
|
||||
|
||||
-- the movie fragments (moof) after the moov: appends their samples to the tracks
|
||||
local function fragments(b: buffer, fileBase: number, top: { Box.Box }, byId: { [number]: Track }, o: Options): Err.Err?
|
||||
local maxSamples = o.maxSamples or 2 ^ 25
|
||||
for _, moof in top do
|
||||
@@ -751,7 +733,6 @@ export type Movie = {
|
||||
fragmented: boolean,
|
||||
}
|
||||
|
||||
-- parse(r, opts) -> Movie | nil, Err: the box tree, ftyp, mvhd and every track (fragments included)
|
||||
function Demux.parse(r: Bytes.Reader, opts: Options?): (Movie?, Err.Err?)
|
||||
local o: Options = opts or {}
|
||||
local b = r.buf
|
||||
|
||||
Reference in new issue
Block a user