Skip to content

Commit

Permalink
Add is_qvtr utility function
Browse files Browse the repository at this point in the history
`is_qtvr` will return if the movie is an object, panorama or none of the
above.
  • Loading branch information
rvanlaar committed Sep 13, 2023
1 parent bce407e commit 61d68f0
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions mr_quicktime.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,20 @@ class moovAtom(ContainerAtom):
CHUNK_MAP.update(MAPPING)


T = TypeVar("T")



class QuickTime(ContainerAtom):
CHUNK_MAP = mrcdict()
MAPPING = {
FourCC(b"mdat"): mdatAtom,
FourCC(b"moov"): moovAtom,
FourCC(b"free"): freeAtom,
}
CHUNK_MAP.update(MAPPING)

T = TypeVar("T")

def get_atoms(atom, atom_kls: type[T]) -> list[T]:
atoms = []
if isinstance(atom, atom_kls):
Expand All @@ -557,14 +568,23 @@ def get_atoms(atom, atom_kls: type[T]) -> list[T]:
atoms.extend(get_atoms(parent_atom, atom_kls))
return atoms

def get_atom(atom, atom_kls: type[T]) -> T:
from enum import IntEnum, auto

def get_atom(atom: mrc.Block, atom_kls: type[T]) -> T:
atoms = get_atoms(atom, atom_kls)
assert len(atoms) == 1
return atoms[0]

class QuickTime(ContainerAtom):
CHUNK_MAP = mrcdict()
MAPPING = {FourCC(b"mdat"): mdatAtom,
FourCC(b"moov"): moovAtom,
FourCC(b"free"): freeAtom}
CHUNK_MAP.update(MAPPING)

class QTVRType(IntEnum):
PANORAMA = auto()
OBJECT = auto()

def is_qtvr(atom: mrc.Block) -> QTVRType | None:
ctyp = get_atom(atom, ctypAtom)
controller_id = FourCCB(ctyp.obj.id)
if controller_id == b"stna":
return QTVRType.OBJECT
if controller_id in (b"stpn", b"STpn"):
return QTVRType.PANORAMA
return None

0 comments on commit 61d68f0

Please sign in to comment.