Patches the enzyme lib to allow the detection of subtitles embedded into mp4/m4v files

This commit is contained in:
tcavallari 2014-07-06 12:02:02 +02:00
parent 88709225c9
commit 2c94f9dd82
2 changed files with 14 additions and 2 deletions

View File

@ -27,7 +27,7 @@ from exceptions import *
PARSERS = [('asf', ['video/asf'], ['asf', 'wmv', 'wma']),
('flv', ['video/flv'], ['flv']),
('mkv', ['video/x-matroska', 'application/mkv'], ['mkv', 'mka', 'webm']),
('mp4', ['video/quicktime', 'video/mp4'], ['mov', 'qt', 'mp4', 'mp4a', '3gp', '3gp2', '3g2', 'mk2']),
('mp4', ['video/quicktime', 'video/mp4'], ['mov', 'qt', 'mp4', 'mp4a', 'm4v', '3gp', '3gp2', '3g2', 'mk2']),
('mpeg', ['video/mpeg'], ['mpeg', 'mpg', 'mp4', 'ts']),
('ogm', ['application/ogg'], ['ogm', 'ogg', 'ogv']),
('real', ['video/real'], ['rm', 'ra', 'ram']),

View File

@ -300,6 +300,13 @@ class MPEG4(core.AVContainer):
trackinfo['length'] = mdhd[4] / mdhd[3]
if mdhd[5] in QTLANGUAGES:
trackinfo['language'] = QTLANGUAGES[mdhd[5]]
elif mdhd[5] == 0x7FF:
trackinfo['language'] = 'und'
elif mdhd[5] >= 0x400:
# language code detected as explained in:
# https://developer.apple.com/library/mac/documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-35103
language = bytearray([ ((mdhd[5] & 0x7C00) >> 10) + 0x60, ((mdhd[5] & 0x3E0) >> 5) + 0x60, (mdhd[5] & 0x1F) + 0x60])
trackinfo['language'] = str(language)
# mdhd[6] == quality
self.length = max(self.length, mdhd[4] / mdhd[3])
elif mdia[1] == 'minf':
@ -312,11 +319,13 @@ class MPEG4(core.AVContainer):
datasize += (mdia[0] - 8)
elif mdia[1] == 'hdlr':
hdlr = struct.unpack('>I4s4s', atomdata[pos + 8:pos + 8 + 12])
if hdlr[1] == 'mhlr':
if hdlr[1] == 'mhlr' or hdlr[1] == '\0\0\0\0':
if hdlr[2] == 'vide':
tracktype = 'video'
if hdlr[2] == 'soun':
tracktype = 'audio'
if hdlr[2] == 'subt' or hdlr[2] == 'sbtl' or hdlr[2] == 'subp' or hdlr[2] == 'text':
tracktype = 'subtitle'
elif mdia[1] == 'stsd':
stsd = struct.unpack('>2I', atomdata[pos + 8:pos + 8 + 8])
if stsd[1] > 0:
@ -369,6 +378,9 @@ class MPEG4(core.AVContainer):
if tracktype == 'audio':
info = core.AudioStream()
self.audio.append(info)
if tracktype == 'subtitle':
info = core.Subtitle()
self.subtitles.append(info)
if info:
for key, value in trackinfo.items():
setattr(info, key, value)