A bundle keeps a timeline together with its media, so it can be moved as one item. It is
a folder with the extension .otiod, or the same content in a ZIP file with
the extension .otioz.
Layout
| Entry | In .otiod | In .otioz | Meaning |
|---|---|---|---|
content.otio | Yes | Yes, compressed | A normal OTIO file holding the cut. |
version.txt | Yes in the current C++ source; the bundle documentation says no | Yes, compressed | The bundle version and nothing else, 1.0.0 (the library constant). The current library source (bundle.cpp) writes it into both the .otiod folder and the .otioz archive. |
media/ | Yes | Yes, uncompressed | The media files. |
Rules for content.otio
Each media reference is either a MissingReference, or an
ExternalReference whose target_url is a relative path into the
media folder, or (in the current C++ library) an
ImageSequenceReference whose target_url_base is
media/. Only the images the writer copied are in the media folder: with a
frame_step above 1 that is every frame_step-th image of the sequence, not all
of them (see the media folder).
Reading a bundle needs content.otio; version.txt is never read. The error
messages differ by version.
- Current main (C++,
bundle.cpp): the input of a.otiozread must be a regular file (“input '…' is not a file”) and the input of a.otiodread a folder (“input '…' is not a directory”). A.otiozwithout the entry fails with “'…' is missing content.otio”, and a.otiodfolder without that file fails with “'…' is missing a timeline file”. An existing extract folder fails with “output directory '…' already exists”. - Released v0.18.1 (Python,
otioz.py,otiod.py): a.otiozthat is not a ZIP file fails with “Not a zipfile: …”. A ZIP withoutcontent.otiofails with Python’szipfileKeyErrorfromZipFile.read, not an OTIO message. The.otiodreader makes no folder check: it readscontent.otioinside the path it is given, so a missing folder or file fails inside the generic JSON file reader (otio_json, not read here), with no bundle-specific message. The extract messages are in Read options.
Rules for the media folder
- It is flat, with no sub-folders.
- It holds every file that an
ExternalReferenceincontent.otiopoints to (in the released v0.18.1 Python writer, only the active reference of each clip is looked at; in the current C++ writer every reference inmedia_referencesis). - Each file must have a unique base name. In the current C++ writer (
bundle.cpp,register_bundle_file) the base names are compared ignoring case, but the “would overwrite” error is raised only when the two files are in different parent folders. Two names that differ only in case in the same folder (Shot.MOVandshot.mov) pass the check and are both copied under their own names, so such a bundle cannot be unpacked on a case-insensitive file system. The same file referenced twice is fine. The released Python writer (v0.18.1,file_bundle_utils.py) is different: it compares base names exactly (case-sensitive), for any two different files whatever their folders. - In the current C++ writer an
ImageSequenceReferencecontributes not every image. It walks the image numbers 0,frame_step, 2 ×frame_stepand so on up to the number of images (bundle.cpp,process_media_references), although the image numbers are already counted in steps (image number n has file numberstart_frame+ n ×frame_step). Withframe_step1 every image is copied; withframe_stepabove 1 only everyframe_step-th image is copied. The reference’starget_url_baseis changed tomedia/all the same, so the images that were skipped are missing from the bundle. The released v0.18.1 library has no image-sequence copying at all. - Any codec or container is allowed, since OTIO does not decode media.
When writing a bundle
The source target_url values may be absolute, as
file:///path/to/some/file, or relative to the working directory. The
media_policy option says what happens to references that do not point to a
file.
| Policy | Meaning |
|---|---|
ErrorIfNotFile | Default. Raise an error if a reference does not point at a file. |
MissingIfNotFile | Replace such references with MissingReference, keeping the original in metadata. |
AllMissing | Replace all references with MissingReference, keeping the originals in metadata. No media is copied. |
In the current C++ writer (bundle.cpp, process_media_references) the policy
applies to every media reference that is not a MissingReference and is not a
file, in every entry of media_references. A reference counts as a file only if it is
an ExternalReference whose target_url names a file, or an
ImageSequenceReference whose image addresses do. Every other kind has no file, so a
GeneratorReference (or an unknown reference class) is an error under
ErrorIfNotFile and is replaced under MissingIfNotFile; the
MissingReference made for it has no original_target_url key, because there is no
address to keep. A reference that already is a MissingReference is never touched by the
policy.
The released v0.18.1 Python writer treats only the clip’s active reference
(media_reference), and only an ExternalReference: a reference without a
target_url (a generator, or a missing reference) is skipped and left as it is (under every policy except AllMissing). AllMissing
replaces the active reference of every clip, and its helper reads target_url from the old
reference to keep it, so an active reference that has none fails with an attribute error (read from the
code, not run).
Under ErrorIfNotFile the errors read, in current main, “media reference '<name>' is not
a file”; in v0.18.1, “The <OTIOZ or OTIOD> adapter only works with media reference target_url attributes
that begin with 'file:'. Got a target_url of: '…'” for a scheme other than file or
empty, and the bare file path as the message for a path that is missing or not a file.
What counts as a file
The C++ file_from_url (bundle.cpp) decides whether a
target_url (or an image’s address) names a file.
- A string that does not start with
file://(compared ignoring case) and has no://in it is a bare path, used as written (relative to the working directory, or to therelative_media_base_dirwrite option when that is set). - A string with
://and a scheme other thanfile(such ashttp://) is not a file: the media policy then applies. - For
file://: the part after the first/following the prefix is the path; anything from?or#on is dropped; the path is percent-decoded (only%followed by two hex digits; any other%stays as it is). The host part before the path then gives: a drive letter (file://C:/x) becomesC:/x; a path of the form/C:/xafter a host becomesC:/x; any other host exceptlocalhostgives a UNC path//host/path; an empty host orlocalhostgives the path alone. Backslashes become/.
The MissingReference that a policy makes
The new MissingReference keeps the old reference’s name and all of its
metadata, and adds two keys to that metadata. The old available range is not kept. The
texts and the rules for the second key differ by version.
- Current main (
bundle.cpp,create_missing_reference,process_media_references):missing_reference_becauseis'missing_if_not_file' specified as the MediaReferencePolicyor'all_missing' specified as the MediaReferencePolicy(the quotes are part of the text).original_target_urlis present only when there is an address to keep. For anExternalReferenceit is thetarget_urlas it was, which is also what it is underMissingIfNotFile, because the address is only changed tomedia/…for a reference that is a file. For anImageSequenceReferenceit is the file path (not afile:address) of image number 0, and there is a catch. Whether the sequence “is a file” is decided from the last image the writer walked, and a sequence with no images walked is not a file. UnderMissingIfNotFilesuch a sequence has itstarget_url_baseset tomedia/before the key is read, sooriginal_target_urlis then amedia/…path, not the sequence’s original address. If image 0 itself names no file the key is left out. - Released v0.18.1 (
file_bundle_utils.py,reference_cloned_and_missing): the keymissing_reference_becauseholds one of three texts:AllMissing specified as the MediaReferencePolicy(the policy name as written in the Python class, with no quotes),target_url is not a file scheme url (start with url:)(atarget_urlwhose scheme is neitherfilenor empty, underMissingIfNotFile) ortarget_url target is not a file or does not exist(a path that does not exist or is not a file, underMissingIfNotFile).original_target_urlis always the oldtarget_url.
Write options
The Python adapters otiod and otioz take the same write options as each
other. The released library (v0.18.1) and the current main branch differ, so each option is marked.
dryrun (both versions) returns a size instead of writing, and the size differs. In v0.18.1
(_total_file_size_of) it is the total size of the media files that would be copied. In current
main (dry_run in bundle.cpp) it also adds the size of version.txt
and the size of the content.otio JSON text that would be written.
media_policy(C++policy): the three policies above. Both versions.relative_media_base_dir: the folder a relative media path is resolved against before it is copied. Current main only; v0.18.1 resolves relative paths against the working directory and has no such option.target_schema_versions(current main only; the v0.18.1 adapters have no such option and always write the current versions): a map from schema name to version, for example one of theOTIO_COREversion maps;content.otiois then written at those older versions, so older libraries can read it (-A target_schema_versions="{'Marker':2}"onotioconvert). If it is not given, the environment variableOTIO_DEFAULT_TARGET_VERSION_FAMILY_LABELis used when set.indent(C++, current main only): spaces of JSON indentation incontent.otio; default 4. It is a C++ option; the Python adapters do not pass it.
Writing fails if the output path already exists. In v0.18.1 the parent folder of an .otiod
must also exist; the folder itself is then made together with media/.
What is written, by version
- Current main (C++ writer): an
.otiozholds, in this order,version.txt,content.otio, then the media files sorted by source path; an.otiodfolder holdsversion.txt,content.otioandmedia/. (bundle.cpp,write_otioz,write_otiod.) - Released v0.18.1 (Python writer): an
.otiozholdsversion.txt,content.otioand then the media files, in the order of the file-path map built from the clips. An.otiodholds onlycontent.otioandmedia/: noversion.txt. - In both versions the entry names and the media addresses in
content.otiouse/as the separator, on every platform (the adapters convert withas_posix()), so a bundle is portable between Windows and Unix. A bundle written by v0.18.1 has no image-sequence copying, and its media addresses are plain relative paths of the formmedia/<name>, with nofile:scheme (url_from_filepathinurl_utils.pyfalls back to a path with an empty scheme for a relative path).
Read options and extraction
extract_to_directory(Python adapter,.otiozonly;extract_pathin C++): unpack the bundle into this folder. Current main: the folder must not already exist (it is created); a failed extraction removes what it wrote. Released v0.18.1: the opposite for the folder: it must already exist, and only itsmedia/sub-folder must not exist; entries are then extracted with Python’sextractalland there is no clean-up on failure. Its messages are “Directory '…' does not exist, cannot unpack otioz there.” and “Error: '…/media' already exists on disk, cannot overwrite while unpacking OTIOZ file '…'.” Without this option onlycontent.otiois read, in both.absolute_media_reference_paths(the.otiodadapter only in the Python API; the.otiozPython adapter has no such argument): turns every relativetarget_urlinto an absolute path under the bundle folder. In v0.18.1 this changes the clip’s active reference only and looks for atarget_url(an image sequence has none). In current main the C++ library does it for every entry ofmedia_referencesand also rewrites image-sequencetarget_url_basevalues; its.otiozreader accepts the option only together with an extract folder.
Extraction (bundle.cpp) refuses an archive entry whose output path would fall outside
the extract folder (a .. component or an absolute path, the “zip slip” attack), and refuses
any entry that is a symbolic link: either one makes the whole read fail.
A default read parses only content.otio. The ZIP is made with Python’s
zipfile library in the released Python code, and by the C++ library
(minizip-ng) in the current source, which stores the files under media/
uncompressed and the other entries deflated.