1# -*- coding: utf-8 -*- 2from __future__ import absolute_import 3import codecs 4 5from .base import Type 6 7 8class IsoBmff(Type): 9 """ 10 Implements the ISO-BMFF base type. 11 """ 12 def __init__(self, mime, extension): 13 super(IsoBmff, self).__init__( 14 mime=mime, 15 extension=extension 16 ) 17 18 def _is_isobmff(self, buf): 19 if len(buf) < 16 or buf[4:8] != b'ftyp': 20 return False 21 if len(buf) < int(codecs.encode(buf[0:4], 'hex'), 16): 22 return False 23 return True 24 25 def _get_ftyp(self, buf): 26 ftyp_len = int(codecs.encode(buf[0:4], 'hex'), 16) 27 major_brand = buf[8:12].decode() 28 minor_version = int(codecs.encode(buf[12:16], 'hex'), 16) 29 compatible_brands = [] 30 for i in range(16, ftyp_len, 4): 31 compatible_brands.append(buf[i:i+4].decode()) 32 33 return major_brand, minor_version, compatible_brands 34