Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue adding Markers #55

Open
ron-eyal opened this issue Oct 19, 2023 · 1 comment
Open

Issue adding Markers #55

ron-eyal opened this issue Oct 19, 2023 · 1 comment

Comments

@ron-eyal
Copy link

ron-eyal commented Oct 19, 2023

I've seen examples with this same code, but when I try to run it, it gives me an error.

I'm trying to add a marker to an AAF using this code:

with aaf2.open(destination, 'rw') as destination_aaf:
            destination_mob_toplevel = next(destination_aaf.content.toplevel(), None)
            ems = destination_aaf.create.EventMobSlot()
            ems['EditRate'].value = '24000/1001'
            ems['SlotID'].value = 1000
            ems['PhysicalTrackNumber'].value = 10
            sequence = destination_aaf.create.Sequence("DescriptiveMetadata") #  This is the line causing the error
            marker = destination_aaf.create.DescriptiveMarker()
            marker.media_kind = "DescriptiveMetadata"
            described_slots = set([1])
            marker['DescribedSlots'].value = described_slots
            marker['Position'].value = 100
            marker['Comment'].value = "This is a comment"
            marker['CommentMarkerUser'].value = "User Name"
            sequence.components.append(marker)
            ems.segment = sequence
            destination_mob_toplevel.slots.append(ems)

I get the following error:

line 183, in add_markers
    sequence = destination_aaf.create.Sequence("DescriptiveMetadata")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/file.py", line 63, in create_instance
    return self.from_name(self.class_name, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/file.py", line 54, in from_name
    obj.__init__(*args, **kwargs)
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/components.py", line 75, in __init__
    super(Sequence, self).__init__(media_kind, length)
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/components.py", line 21, in __init__
    self.media_kind = media_kind or 'picture'
    ^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/components.py", line 48, in media_kind
    self.datadef = self.root.dictionary.lookup_datadef(value)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/dictionary.py", line 239, in lookup_datadef
    return lookup_def(self, name, DataDef, 'DataDefinitions')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/dictionary.py", line 37, in lookup_def
    raise Exception("No Definition: %s" % str(name))
Exception: No Definition: descriptivemetadata

Oddly, if I change the line from "DescriptiveMetadata" to "Descriptive metadata" with a space like this:
sequence = destination_aaf.create.Sequence("Descriptive metadata")

it gets past that line but has an error on the next line:

in edit_aaf_main
    marker = destination_aaf.create.DescriptiveMarker()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/file.py", line 63, in create_instance
    return self.from_name(self.class_name, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/file.py", line 54, in from_name
    obj.__init__(*args, **kwargs)
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/components.py", line 339, in __init__
    super(Event, self).__init__(media_kind='DescriptiveMetadata')
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/components.py", line 21, in __init__
    self.media_kind = media_kind or 'picture'
    ^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/components.py", line 48, in media_kind
    self.datadef = self.root.dictionary.lookup_datadef(value)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/dictionary.py", line 239, in lookup_datadef
    return lookup_def(self, name, DataDef, 'DataDefinitions')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/X/.local/share/virtualenvs/X/lib/python3.11/site-packages/aaf2/dictionary.py", line 37, in lookup_def
    raise Exception("No Definition: %s" % str(name))
Exception: No Definition: descriptivemetadata
@ron-eyal
Copy link
Author

I think I figured out the cause of the issue. The destination_aaf that I was modifying had a dictionary with some differences to an empty AAF created using pyaaf2. Since there was no definition of "descriptivemetadata" in that dictionary, an error was happening on those lines. That dictionary did have a definition of "Descriptive Metadata" with a space, so it got through that first step with that change, but then would fail on creating the marker, which again is expecting "descriptivemetadata" in the dictionary.

Is there a way to add new entries to an AAF's dictionary to resolve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant