Skip to content

Commit

Permalink
Support parsing video stsd
Browse files Browse the repository at this point in the history
  • Loading branch information
kodawah committed Feb 27, 2017
1 parent a7ecf23 commit da6b48b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
27 changes: 25 additions & 2 deletions spatialmedia/mpeg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@
TAG_UUID = "uuid"
TAG_WAVE = "wave"

# Sound sample descriptions.
TAG_NONE = "NONE"
TAG_RAW_ = "raw "

# Video sample descriptions.
TAG_AVC1 = "avc1"
TAG_HVC1 = "hvc1"
TAG_HEV1 = "hev1"

# Sound sample descriptions.
TAG_TWOS = "twos"
TAG_SOWT = "sowt"
TAG_FL32 = "fl32"
Expand All @@ -57,6 +63,14 @@
TAG_LPCM = "lpcm"
TAG_MP4A = "mp4a"

VIDEO_SAMPLE_DESCRIPTIONS = frozenset([
TAG_NONE,
TAG_RAW_,
TAG_AVC1,
TAG_HVC1,
TAG_HEV1,
])

SOUND_SAMPLE_DESCRIPTIONS = frozenset([
TAG_NONE,
TAG_RAW_,
Expand All @@ -72,7 +86,7 @@
TAG_MP4A,
])

CONTAINERS_LIST = frozenset([
AUDIO_CONTAINERS_LIST = frozenset([
TAG_MDIA,
TAG_MINF,
TAG_MOOV,
Expand All @@ -83,3 +97,12 @@
TAG_WAVE,
]).union(SOUND_SAMPLE_DESCRIPTIONS)

VIDEO_CONTAINERS_LIST = frozenset([
TAG_MDIA,
TAG_MINF,
TAG_MOOV,
TAG_STBL,
TAG_STSD,
TAG_TRAK,
TAG_UDTA,
]).union(VIDEO_SAMPLE_DESCRIPTIONS)
16 changes: 15 additions & 1 deletion spatialmedia/mpeg/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def load(fh, position, end):
size = struct.unpack(">I", fh.read(4))[0]
name = fh.read(4)

is_box = name not in constants.CONTAINERS_LIST
is_box = False
if (name not in constants.AUDIO_CONTAINERS_LIST) and \
(name not in constants.VIDEO_CONTAINERS_LIST):
is_box = True
# Handle the mp4a decompressor setting (wave -> mp4a).
if name == constants.TAG_MP4A and size == 12:
is_box = True
Expand Down Expand Up @@ -75,6 +78,17 @@ def load(fh, position, end):
else:
print("Unsupported sample description version:",
sample_description_version)
if name in constants.VIDEO_SAMPLE_DESCRIPTIONS:
current_pos = fh.tell()
fh.seek(current_pos + 8)
sample_description_version = struct.unpack(">h", fh.read(2))[0]
fh.seek(current_pos)

if sample_description_version == 0:
padding = 78
else:
print("Unsupported sample description version:",
sample_description_version)

new_box = Container()
new_box.name = name
Expand Down

0 comments on commit da6b48b

Please sign in to comment.