Author: dmeyer
Date: Fri Dec 22 19:29:58 2006
New Revision: 2282
Modified:
trunk/metadata/src/video/flv.py
Log:
add basic metadata parser
Modified: trunk/metadata/src/video/flv.py
==============================================================================
--- trunk/metadata/src/video/flv.py (original)
+++ trunk/metadata/src/video/flv.py Fri Dec 22 19:29:58 2006
@@ -57,8 +57,26 @@
FLV_VIDEO_CODECID_MASK = 0x0f
FLV_VIDEO_CODECID = ( 'FLV1', 'MSS1', 'VP60') # wild guess
+FLV_DATA_TYPE_NUMBER = 0x00
+FLV_DATA_TYPE_BOOL = 0x01
+FLV_DATA_TYPE_STRING = 0x02
+FLV_DATA_TYPE_OBJECT = 0x03
+FLC_DATA_TYPE_CLIP = 0x04
+FLV_DATA_TYPE_REFERENCE = 0x07
+FLV_DATA_TYPE_ECMARRAY = 0x08
+FLV_DATA_TYPE_ENDOBJECT = 0x09
+FLV_DATA_TYPE_ARRAY = 0x0a
+FLV_DATA_TYPE_DATE = 0x0b
+FLV_DATA_TYPE_LONGSTRING = 0x0c
+
+FLVINFO = {
+ 'creator': 'copyright',
+}
class FlashVideo(core.AVContainer):
+
+ table_mapping = { 'FLVINFO' : FLVINFO }
+
def __init__(self,file):
core.AVContainer.__init__(self)
self.mime = 'video/flv'
@@ -106,7 +124,17 @@
elif chunk[0] == FLV_TAG_TYPE_META:
log.info('metadata %s', str(chunk))
- file.seek(size, 1)
+ metadata = file.read(size)
+ while metadata:
+ length, value = self._parse_value(metadata)
+ if isinstance(value, dict):
+ if value.get('duration'):
+ self.length = value.get('duration')
+ self._appendtable('FLVINFO', value)
+ if not length:
+ # parse error
+ break
+ metadata = metadata[length:]
else:
log.info('unkown %s', str(chunk))
@@ -114,4 +142,39 @@
file.seek(4, 1)
+ def _parse_value(self, data):
+ """
+ Parse the next metadata value.
+ """
+ if ord(data[0]) == FLV_DATA_TYPE_NUMBER:
+ value = struct.unpack('>d', data[1:9])[0]
+ return 9, value
+
+ if ord(data[0]) == FLV_DATA_TYPE_BOOL:
+ return 2, bool(data[1])
+
+ if ord(data[0]) == FLV_DATA_TYPE_STRING:
+ length = (ord(data[1]) << 8) + ord(data[2])
+ return length + 3, data[3:length+3]
+
+ if ord(data[0]) == FLV_DATA_TYPE_ECMARRAY:
+ init_length = len(data)
+ num = struct.unpack('>I', data[1:5])[0]
+ data = data[5:]
+ result = {}
+ for i in range(num):
+ length = (ord(data[0]) << 8) + ord(data[1])
+ key = data[2:length+2]
+ data = data[length + 2:]
+ length, value = self._parse_value(data)
+ if not length:
+ return 0, result
+ result[key] = value
+ data = data[length:]
+ return init_length - len(data), result
+
+ log.info('unknown code: %x. Stop metadata parser', ord(data[0]))
+ return 0, None
+
+
core.register( 'video/flv', ('flv',), FlashVideo )
-------------------------------------------------------------------------
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