如何获得MP4视频/音频的字节偏移的第二个偏移量?我能够为一个" webm"但不适用于MP4。以下代码输入视频/音频并输出包含(时间偏移,字节偏移)的元组。
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:
for 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 to import module %s' % mod_name)
except AttributeError:
parser.error('unable to import class %s from %s' % (cls_name, mod_name))
video_info = {}
video_info['filename'] = filename
video_info['total_size'] = os.stat(filename).st_size
video_info['clusters'] = []
with open(filename, 'rb') as stream:
doc = doc_cls(stream)
offset = 0
for 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
关于如何为MP4做这个的任何想法?