Example #1
0
def getDashFragmentInfo(url):
	req = urllib2.Request(url, headers={'Range': 'bytes=0-65535'})
	d = urllib2.urlopen(req).read()
	atoms = mp4_utils.parseAtoms(d, 0, len(d))
	sidxAtom = mp4_utils.getAtomData(d, atoms, 'sidx')
	if sidxAtom[0] == '\0':
		startPts = struct.unpack('>L', sidxAtom[12:16])[0]
	else:
		startPts = struct.unpack('>Q', sidxAtom[12:20])[0]
		
	trunAtom = mp4_utils.getAtomData(d, atoms, 'moof.traf.trun')
	timingInfo = getTimingInfoFromTrunAtom(trunAtom, startPts)

	urlInfo = url.split('fragment-')[-1]
	segIndex, fileIndex, streamId = urlInfo.split('-')[:3]
	return [(url, int(segIndex), streamId, fileIndex, timingInfo)]
Example #2
0
def getMssFragmentInfo(url):
	urlInfo = url.split('QualityLevels(', 1)[-1]
	if 'video' in urlInfo:
		streamId = 'v1'
	elif 'audio' in urlInfo:
		streamId = 'a1'
	else:
		return []
	bitrate = int(urlInfo.split(')')[0])
	fileIndex = 'f%s' % ((((bitrate) >> 5) & 0x1F) + 1)
	timestamp = int(url.split('=')[-1].split(')')[0])
	segIndex = timestamp / SEGMENT_DURATION

	req = urllib2.Request(url, headers={'Range': 'bytes=0-65535'})
	d = urllib2.urlopen(req).read()
	atoms = mp4_utils.parseAtoms(d, 0, len(d))

	# get the start pts
	uuidAtoms = mp4_utils.getAtom(atoms, 'moof.traf')[3]['uuid']
	for uuidAtom in uuidAtoms:
		curAtomData = d[(uuidAtom[0] + uuidAtom[1]):uuidAtom[2]]
		if not curAtomData.startswith('6d1d9b0542d544e680e2141daff757b2'.decode('hex')):
			continue
		startPts = struct.unpack('>Q', curAtomData[20:28])[0]
	
	trunAtom = mp4_utils.getAtomData(d, atoms, 'moof.traf.trun')
	timingInfo = getTimingInfoFromTrunAtom(trunAtom, startPts)
	return [(url, int(segIndex), streamId, fileIndex, timingInfo)]
def getDashFragmentInfo(url):
	req = urllib2.Request(url, headers={'Range': 'bytes=0-65535'})
	d = urllib2.urlopen(req).read()
	atoms = mp4_utils.parseAtoms(d, 0, len(d))
	sidxAtom = mp4_utils.getAtomData(d, atoms, 'sidx')
	if sidxAtom[0] == '\0':
		startPts = struct.unpack('>L', sidxAtom[12:16])[0]
	else:
		startPts = struct.unpack('>Q', sidxAtom[12:20])[0]
		
	trunAtom = mp4_utils.getAtomData(d, atoms, 'moof.traf.trun')
	timingInfo = getTimingInfoFromTrunAtom(trunAtom, startPts)

	urlInfo = url.split('fragment-')[-1]
	segIndex, fileIndex, streamId = urlInfo.split('-')[:3]
	return [(url, int(segIndex), streamId, fileIndex, timingInfo)]
def getMssFragmentInfo(url):
	urlInfo = url.split('QualityLevels(', 1)[-1]
	if 'video' in urlInfo:
		streamId = 'v1'
	elif 'audio' in urlInfo:
		streamId = 'a1'
	else:
		return []
	bitrate = int(urlInfo.split(')')[0])
	fileIndex = 'f%s' % ((((bitrate) >> 5) & 0x1F) + 1)
	timestamp = int(url.split('=')[-1].split(')')[0])
	segIndex = timestamp / SEGMENT_DURATION

	req = urllib2.Request(url, headers={'Range': 'bytes=0-65535'})
	d = urllib2.urlopen(req).read()
	atoms = mp4_utils.parseAtoms(d, 0, len(d))

	# get the start pts
	uuidAtoms = mp4_utils.getAtom(atoms, 'moof.traf')[3]['uuid']
	for uuidAtom in uuidAtoms:
		curAtomData = d[(uuidAtom[0] + uuidAtom[1]):uuidAtom[2]]
		if not curAtomData.startswith('6d1d9b0542d544e680e2141daff757b2'.decode('hex')):
			continue
		startPts = struct.unpack('>Q', curAtomData[20:28])[0]
	
	trunAtom = mp4_utils.getAtomData(d, atoms, 'moof.traf.trun')
	timingInfo = getTimingInfoFromTrunAtom(trunAtom, startPts)
	return [(url, int(segIndex), streamId, fileIndex, timingInfo)]
def getHdsFragmentInfo(url):
    d = urllib2.urlopen(url).read()
    atoms = mp4_utils.parseAtoms(d, 0, len(d))
    mdatAtom = mp4_utils.getAtomData(d, atoms, 'mdat')
    curPos = 0
    dtss = {}
    ptss = {}
    while curPos < len(mdatAtom):
        # parse the adobe mux packet header
        tagType = ord(mdatAtom[curPos])
        dataSize = parse24be(mdatAtom[(curPos + 1):(curPos + 4)])
        dts = parse24be(mdatAtom[(curPos + 4):(curPos + 7)])
        dtsExt = ord(mdatAtom[curPos + 7])
        dts |= dtsExt << 24
        if tagType == 9:
            streamId = 'v1'
            ptsDelay = parse24be(mdatAtom[(curPos + 13):(curPos + 16)])
            realFrame = ord(mdatAtom[curPos + 12]) == 1
        elif tagType == 8:
            streamId = 'a1'
            ptsDelay = 0
            realFrame = ord(mdatAtom[curPos + 12]) == 1
        else:
            realFrame = False
        curPos += 11 + dataSize + 4
        if not realFrame:
            continue
        dtss.setdefault(streamId, [])
        dtss[streamId].append(dts)
        ptss.setdefault(streamId, [])
        ptss[streamId].append(dts + ptsDelay)

    urlFilename = url.rsplit('/', 1)[-1]
    urlFilename = urlFilename.replace('-v1', '').replace('-a1', '').replace(
        '-Seg1-Frag', '-')
    _, fileIndex, segIndex = urlFilename.split('-')
    return getFragmentInfoFromDtssPtss(url, segIndex, fileIndex, dtss, ptss)
def getHdsFragmentInfo(url):
	req = urllib2.Request(url, headers=headers)
	d = urllib2.urlopen(req).read()
	atoms = mp4_utils.parseAtoms(d, 0, len(d))
	mdatAtom = mp4_utils.getAtomData(d, atoms, 'mdat')
	curPos = 0
	dtss = {}
	ptss = {}
	while curPos < len(mdatAtom):
		# parse the adobe mux packet header
		tagType = ord(mdatAtom[curPos])
		dataSize = parse24be(mdatAtom[(curPos + 1):(curPos + 4)])
		dts = parse24be(mdatAtom[(curPos + 4):(curPos + 7)])
		dtsExt = ord(mdatAtom[curPos + 7])
		dts |= dtsExt << 24
		if tagType == 9:
			streamId = 'v1'
			ptsDelay = parse24be(mdatAtom[(curPos + 13):(curPos + 16)])
			realFrame = ord(mdatAtom[curPos + 12]) == 1
		elif tagType == 8:
			streamId = 'a1'
			ptsDelay = 0
			realFrame = ord(mdatAtom[curPos + 12]) == 1
		else:
			realFrame = False
		curPos += 11 + dataSize + 4
		if not realFrame:
			continue
		dtss.setdefault(streamId, [])
		dtss[streamId].append(dts)
		ptss.setdefault(streamId, [])
		ptss[streamId].append(dts + ptsDelay)
		
	urlFilename = url.rsplit('/', 1)[-1]
	urlFilename = urlFilename.replace('-v1', '').replace('-a1', '').replace('-Seg1-Frag', '-')
	_, fileIndex, segIndex = urlFilename.split('-')
	return getFragmentInfoFromDtssPtss(url, segIndex, fileIndex, dtss, ptss)