Permalink
Browse files

Add basic mp4 file handler and testing file.

  • Loading branch information...
1 parent 049b5a9 commit cbfd3e8a5e3add37dc4d0e9f6e8a2efacb19f2fa @SteveMarshall committed Dec 22, 2010
Showing with 48 additions and 0 deletions.
  1. +20 −0 mp4file.py
  2. +28 −0 test.py
View
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+__author__ = "Steve Marshall (steve@nascentguruism.com)"
+__copyright__ = "Copyright (c) 2008 Steve Marshall"
+__license__ = "Python"
+
+from atom import Atom
+import os
+
+class Mp4File(list):
+ def __init__(self, file):
+ fh = open(file)
+ size = os.stat(file).st_size
+ while fh.tell() < size:
+ root_atom = Atom( stream=fh, offset=fh.tell() )
+ root_atom.seek( 0, os.SEEK_END )
+ self.append( root_atom )
+
+
View
28 test.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+import os, glob
+from mp4file import Mp4File
+from atom import Atom
+
+def print_atom(a, indent=' '):
+ children = []
+ if 1 < len(a):
+ for child in a:
+ if type(child) is Atom:
+ children.append( print_atom( child, indent=indent + ' ' ) )
+ return """{indent}{atom.type}: [
+{children}
+{indent}]""".format(
+ atom=a,
+ indent=indent,
+ children=',\n'.join( children )
+ )
+ return "%s%s" % (indent, a)
+
+path = './'
+for mp4 in glob.glob( os.path.join(path, '*.mp4') ):
+ print os.path.basename(mp4)
+ mp4file = Mp4File( mp4 )
+ for a in mp4file:
+ print print_atom( a ) + ','

0 comments on commit cbfd3e8

Please sign in to comment.