Author: tack
Date: Fri Mar 9 19:54:04 2007
New Revision: 2536
Modified:
trunk/metadata/src/core.py
trunk/metadata/src/fourcc.py
trunk/metadata/src/video/mkv.py
Log:
Improve fourcc/codec handling.
Modified: trunk/metadata/src/core.py
==============================================================================
--- trunk/metadata/src/core.py (original)
+++ trunk/metadata/src/core.py Fri Mar 9 19:54:04 2007
@@ -219,9 +219,9 @@
value = value.strip().rstrip().replace(u'\0', u'')
setattr(self, attr, value)
- if 'fourcc' in self._keys and 'codec' in self._keys and \
- self.codec is not None:
- # resolve fourcc
+ if 'fourcc' in self._keys and 'codec' in self._keys and self.codec is
not None:
+ # Codec may be a fourcc, in which case we resolve it to its actual
+ # name and set the fourcc attribute.
self.fourcc, self.codec = fourcc.resolve(self.codec)
Modified: trunk/metadata/src/fourcc.py
==============================================================================
--- trunk/metadata/src/fourcc.py (original)
+++ trunk/metadata/src/fourcc.py Fri Mar 9 19:54:04 2007
@@ -1,25 +1,42 @@
+import struct, string, re
+
__all__ = [ 'resolve' ]
def resolve(code):
"""
- Transform a twocc or fourcc code into a name.
+ Transform a twocc or fourcc code into a name. Returns a 2-tuple of (cc,
+ codec) where both are strings and cc is a string in the form '0xXX' if it's
+ a twocc, or 'ABCD' if it's a fourcc. If the given code is not a known
+ twocc or fourcc, the return value will be (None, 'Unknown'), unless the
+ code is otherwise a printable string in which case it will be returned as
+ the codec.
"""
- if isinstance(code, basestring) and code.startswith('0x'):
- code = int(code[2:], 16)
- if isinstance(code, (int, long)):
- if code in TWOCC:
- return u'0x%04x' % code, unicode(TWOCC[code])
- return u'0x%04x' % code, u'Unknown'
- if code.upper() in FOURCC:
- return unicode(code.upper()), unicode(FOURCC[code.upper()])
- if code.upper().startswith('MS'):
- code = code[2:]
- if len(code) > 2:
- return unicode(code), u'Unknown'
- code = (ord(code[0]) << 8) + ord(code[1])
- if code in TWOCC:
- return u'0x%04x' % code, unicode(TWOCC[code])
- return u'0x%04x' % code, u'Unknown'
+ if isinstance(code, basestring):
+ codec = u'Unknown'
+ # Check for twocc
+ if re.match(r'^0x[\da-f]{1,4}$', code, re.I):
+ # Twocc in hex form
+ return code, TWOCC.get(int(code, 16), codec)
+ elif code.isdigit() and 0 <= int(code) <= 0xff:
+ # Twocc in decimal form
+ return hex(int(code)), TWOCC.get(int(code), codec)
+ elif len(code) == 2:
+ code = struct.unpack('H', code)[0]
+ return hex(code), TWOCC.get(code, codec)
+ elif len(code) != 4 and len([ x for x in code if x not in
string.printable ]) == 0:
+ # Code is a printable string.
+ codec = unicode(code)
+
+ if code[:2] == 'MS' and code[2:].upper() in FOURCC:
+ code = code[2:]
+
+ if code.upper() in FOURCC:
+ return code.upper(), unicode(FOURCC[code.upper()])
+ return None, codec
+ elif isinstance(code, (int, long)):
+ return hex(code), TWOCC.get(code, u'Unknown')
+
+ return None, u'Unknown'
TWOCC = {
Modified: trunk/metadata/src/video/mkv.py
==============================================================================
--- trunk/metadata/src/video/mkv.py (original)
+++ trunk/metadata/src/video/mkv.py Fri Mar 9 19:54:04 2007
@@ -124,7 +124,11 @@
'A_PCM/INT/LIT': 0x0001,
'A_PCM/FLOAT/IEEE': 0x003,
'A_TTA1': 0x77a1,
- 'A_AAC/MPEG4/LC/SBR': 0x00ff
+ 'A_WAVPACK4': 0x5756,
+ 'A_VORBIS': 0x6750,
+ 'A_FLAC': 0xF1AC,
+ 'A_AAC': 0x00ff,
+ 'A_AAC/': 0x00ff
}
class EbmlEntity:
@@ -483,6 +487,8 @@
# http://haali.cs.msu.ru/mkv/codecs.pdf
if track.codec in FOURCCMap:
track.codec = FOURCCMap[track.codec]
+ elif '/' in track.codec and track.codec.split('/')[0] + '/' in
FOURCCMap:
+ track.codec = FOURCCMap[track.codec.split('/')[0] + '/']
elif track.codec.endswith('FOURCC') and len(codec_private_id) == 40:
track.codec = codec_private_id[16:20]
elif track.codec.startswith('V_REAL/'):
@@ -519,6 +525,8 @@
if track.codec in FOURCCMap:
track.codec = FOURCCMap[track.codec]
+ elif '/' in track.codec and track.codec.split('/')[0] + '/' in
FOURCCMap:
+ track.codec = FOURCCMap[track.codec.split('/')[0] + '/']
elif track.codec.startswith('A_'):
track.codec = track.codec[2:]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog