python - How to extract Second to Byte offset for a MP4? -
how second offset byte offset mp4 video/audio? able "webm" not mp4. following code takes input of video/audio , outputs tuples containing (time offset,byte offset).
from ebml.schema import ebmldocument, unknownelement, container, binary def fill_video_info(element, offset, video_info): if element.name == 'duration': video_info['duration'] = element.value if element.name == 'displaywidth': video_info['width'] = element.value if element.name == 'displayheight': video_info['height'] = element.value if element.name == 'cluster': video_info['clusters'].append({'offset': offset}) if element.name == 'timecode': video_info['clusters'][-1]['timecode'] = element.value if element.type == container: sub_el in element.value: fill_video_info(sub_el, offset + element.head_size, video_info) offset += sub_el.size import sys import json import os def getinfo(filename): mod_name, _, cls_name = 'ebml.schema.matroska.matroskadocument'.rpartition('.') try: doc_mod = __import__(mod_name, fromlist=[cls_name]) doc_cls = getattr(doc_mod, cls_name) except importerror: parser.error('unable import module %s' % mod_name) except attributeerror: parser.error('unable import class %s %s' % (cls_name, mod_name)) video_info = {} video_info['filename'] = filename video_info['total_size'] = os.stat(filename).st_size video_info['clusters'] = [] open(filename, 'rb') stream: doc = doc_cls(stream) offset = 0 el in doc.roots: fill_video_info(el, offset, video_info) offset += el.size return video_info if __name__ == '__main__': print json.dumps(getinfo(sys.argv[1])) pass
any idea on how mp4?
Comments
Post a Comment