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

Get the correct startTime from TimelineMobSlot #44

Closed
ilansr opened this issue Jan 11, 2018 · 4 comments
Closed

Get the correct startTime from TimelineMobSlot #44

ilansr opened this issue Jan 11, 2018 · 4 comments

Comments

@ilansr
Copy link

ilansr commented Jan 11, 2018

Hi

I've added Auxiliary Timecode on my aaf file via Avid.
How can i access the Auxiliary Timecode via code?
Thanks!

@markreidvfx
Copy link
Owner

it should be the origin property

TimecodeSlot.origin

@ilansr
Copy link
Author

ilansr commented Jan 13, 2018

Thanks for replying!
If you don't mind taking a look at my aaf file: (zipped so i can upload it here)
SequenceNameInAvid.aaf.zip

and the way i see it on Avid:
20180110_205309

Per screenshot, column "Auxiliary TC1" contains timecodes for each row.
However, I am unable to find this data via code.

Any further assist would be appreciated.

@markreidvfx
Copy link
Owner

Oh thats what your looking for! Thanks for the aaf file, and the photo, it really helps! Its a little tricky. Its something that needs to be calculated by starting at on the MasterMob and walking down the reference chain until hit the mob at the bottom of the chain. This SourceMob normally has a tape descriptor on in (it's name also happens to be the tape name). This mob has the timecode tracks on it we're looking for. You need to calculate a offset using the start_time of each component in the reference chain and add this to value of the timecode in theses tracks. Its not fun stuff to think about :p.

Not heavily tested, and assumes 25fps, but the following should work on your sample.

import aaf
import sys
import aaf.component

def frames_to_timecode(frames, fps):
    s, f = divmod(frames, fps)
    m, s = divmod(s, 60)
    h, m = divmod(m, 60)
    d, h = divmod(h, 24)
    return '{0:02d}:{1:02d}:{2:02d}:{3:02d}:{4:02d}'.format(d, h,m,s,f)

def mob_timecode(mob, offset):
    timecode_list = []
    # search the slots for timecode segments
    # NOTE: PhysicalTrackNumber of the slots tells you the type of
    # timecode is its main, AUX etc, see aafeditprotocol spec
    for slot in mob.slots():
        if slot.segment.media_kind == 'Timecode':
            if slot.segment.count == 1:
                timecode = slot.segment.components()[0]

                if isinstance(timecode, aaf.component.Timecode):
                    tc = frames_to_timecode(timecode['Start'].value + offset, 25)
                    timecode_list.append(tc)
            else:
                # If the timecode track has a sequence of Timecode objects,
                # you calculate the timecode by finding the Timecode object
                # that covers the specified offset in the track and add to
                # its starting timecode the difference between the specified
                # offset and the starting position of the Timecode object in the track.
                for index, position, component in slot.segment.positions():
                    if isinstance(component, aaf.component.Timecode):
                        if position + component.length > offset:
                            diff = offset - position
                            tc = frames_to_timecode(diff + component['Start'].value , 25)
                            timecode_list.append(tc)
                            break

    return timecode_list

def get_timecode(slot):

    if isinstance(slot.segment, aaf.component.Sequence):
        clip = slot.segment.components()[0]
    else:
        clip = slot.segment

    mobs = [clip.resolve_ref()]
    start = clip.start_time
    timecode_list = []

    # walk down the refence chain until you reach the
    # last clip with a NULL reference
    for c in clip.walk():
        mob = c.resolve_ref()
        start += c.start_time
        if mob:
            mobs.append(mob)

    # the last mob in the chain has the timecode
    timecode_list.extend(mob_timecode(mobs[-1], start))

    return timecode_list

if __name__ == "__main__":
    f = aaf.open(sys.argv[1])

    for mob in f.storage.master_mobs():
        print mob.name
        print "  ",get_timecode(mob.slot_at(1))

@ilansr
Copy link
Author

ilansr commented Jan 14, 2018

Wow, this is great.
Thanks for detailed reply!

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

2 participants