Skip to content
A Python library for reading, modifying and writing Quicktime files
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
qtatoms.py add and document metadata helper method Jan 28, 2013
qtdump.py add and document metadata helper method Jan 28, 2013
qtfile.py
qtknife.py added qtknife, movie modification tool Jan 24, 2013

README.md

PyQTFile

Author: Niklas Aldergren niklas@aldergren.com

A Python library for reading, modfying and writing QuickTime movies.

A QuickTime movie consists of a list of atoms. An atom can contain other atoms, allowing for complex data structures.

All atoms have a type, and the structure of atom data is specific to each type. By registering additional atom classes, this data can then be deserialized, modified and serialized as needed.

When reading an existing movie and no atom class is found for a type, the PassthroughAtom class is used. This lazily passes through the source data, which allows manipulation of a movie with only partial understanding of the atoms it contains.

Usage

>>> import qtfile
>>> import qtatoms
>>> for atom in qtfile.QuickTimeFile('miryumyum.mov', atom_modules=[qtatoms]):
>>>		print atom, atom.fields

Advanced Usage

Find all metadata key-value pairs in a movie:

# Find all the metadata atoms.
for meta in qt.find("meta"):
	# Grab the atom containing all the metadata keys.
	keys = meta.find("keys")[0]

	# Loop through the all the keys, using the helper method to get the value.
	for namespace, key in keys["keys"]:
		print namespace, key, "=", keys.find_metadata_value(namespace, key)

Find any color parameters in a movie, and modify the field values:

for colr in qt.find("colr"):
	colr["primaries"] = 2
	colr["transfer_func"] = 2
	colr["matrix"] = 2

Find the compressor used for each video track:

# Find all the handler descriptions, looking for video.
for hdlr in qt.find("hdlr"):
	if hdlr["handler_type"] == "vide":
		# Step up one level in the tree, find the sample description.
		for stsd in hdlr.parent.find("stsd"):
			# Print the compressor for the first video sample description.
			print stsd[0]["compressor"]

Find the chunk offsets for timecode track, and print the first timecode sample:

# Find all the handler descriptions, looking for timecode.
for hdlr in qt.find("hdlr"):
	if hdlr["handler_type"] == "tmcd":
		# Step up one level in the tree, find the chunk offsets.
		for stco in hdlr.parent.find("stco"):
			# Seek to the first offset. We assume "stream" here is
			# the open file object.
			stream.seek(stco["table"][0])
			# Unpack and print the frame number.
			print struct.unpack(">I", stream.read(4))
You can’t perform that action at this time.