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

Need help to get timeline TC of certain effects #115

Open
RitaLee79 opened this issue Feb 18, 2023 · 1 comment
Open

Need help to get timeline TC of certain effects #115

RitaLee79 opened this issue Feb 18, 2023 · 1 comment

Comments

@RitaLee79
Copy link

RitaLee79 commented Feb 18, 2023

Hi, im trying to extract certain data from exported aaf. I need to know the timecode of certain effects, for example, stabilizations, motion fxs and fluid morphs. I already can discover the effects with this code, but i need help on how to get the timecode in timeline:

`
with aaf2.open(aaf_file, 'r') as f:

for mob in f.content.compositionmobs():
    if mob.usage and 'TopLevel' in mob.usage:
        timeline = mob
        for slot in timeline.slots:
            if slot.media_kind == 'Picture':
                for comp in slot.segment.property_entries.values():
                    if 'Components' in comp.name:
                        for item in comp.value:
                            if item.name == 'OperationGroup':
                                print(item.operation.name)
                            elif item.name == 'Transition':
                                for prop in item.property_entries.values():
                                    if prop.name == 'OperationGroup':
                                        print(prop.value.operation.name)

`

Thank you very much for your awesome work !!

@RitaLee79
Copy link
Author

I think I have resolved my problem, tomorrow I'll check and fix with a real aaf but for now I wrote this:

`

import aaf2
from collections import defaultdict
from pprint import pprint

aaf_file = 'test.aaf'

effect_report = defaultdict(list)
frame_rate = None
start_frame = None
frame_counter = 0

with aaf2.open(aaf_file, 'r') as f:

    for mob in f.content.compositionmobs():
        if mob.usage and 'TopLevel' in mob.usage:
            timeline = mob
            for prop in timeline.property_entries.values():
                if prop.name == 'MobAttributeList':
                    for val in prop:
                        if val.name == 'SEQUERNCE_FORMAT_STRING':
                            frame_rate = int(val.value.rsplit('/', 1)[1])
                            break
                    else:
                        continue
                    break

            for slot in timeline.slots:
                if not start_frame and slot.segment.name == 'Timecode'\
                        and slot.segment.fps == frame_rate:
                    start_frame = slot.segment.start
                if slot.media_kind == 'Picture':
                    for comp in slot.segment.components.value:
                        if comp.name == 'OperationGroup':
                            effect_report[comp.operation.name].append(frame_counter + start_frame)
                            frame_counter += comp.length
                        elif comp.name == 'Transition':
                            trans_name = comp.property_entries[6145].value.operation.name
                            center_frame = comp.length // 2
                            effect_report[trans_name].append(frame_counter + start_frame - center_frame)
                            frame_counter -= comp.length
                        else:
                            frame_counter += comp.length

pprint(effect_report)
print(frame_counter, frame_rate, start_frame)

`

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