Comments (2)
A quick translate of the older code is below.
With my example AAF (glad to send)
SourceClip.walk() dead ends in pyaaf2 components line 149 trying to call Sequence.component_at_time
So... I did a little workaround below replacing the walk and sequence_component_at_time methods.
Also assume encounting a TimelineMobSlot at top and grabbed the edit_rate from it. That's NOT the right way to do it though. The editrate should come from the mob at the end of the chain.
Hope that's useful!
import aaf2
import sys
import aaf2.components
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, edit_rate):
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 len(slot.segment.components) == 1:
timecode = slot.segment.components[0]
if isinstance(timecode, aaf2.components.Timecode):
tc = frames_to_timecode(timecode['Start'].value + offset, edit_rate)
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, aaf2.components.Timecode):
if position + component.length > offset:
diff = offset - position
tc = frames_to_timecode(diff + component['Start'].value, edit_rate)
timecode_list.append(tc)
break
return timecode_list
def sequence_component_at_time(segment, start):
if len(segment.components) == 1:
# handle the easy case (might still be wrong)
return segment.components[0]
else:
# anticipated functionality ;-)
return segment.component_at_time(start)
def walker(self):
if not self.slot:
return
segment = self.slot.segment
if isinstance(segment, aaf2.components.SourceClip):
yield segment
for item in walker(segment):
yield item
elif isinstance(segment, aaf2.components.Sequence):
try:
clip = sequence_component_at_time(segment, self.start)
except AttributeError as e:
print(e)
else:
if isinstance(clip, aaf2.components.SourceClip):
yield clip
for item in walker(clip):
yield item
else:
raise NotImplementedError("Sequence returned {} not "
"implemented".format(
type(segment)))
elif isinstance(segment, aaf2.components.EssenceGroup):
yield segment
elif isinstance(segment, aaf2.components.Filler):
yield segment
else:
raise NotImplementedError("Walking {} not implemented".format(
type(segment)))
def get_timecode(slot):
edit_rate = int(slot.edit_rate)
if isinstance(slot.segment, aaf2.components.Sequence):
clip = slot.segment.components[0]
else:
clip = slot.segment
mobs = [clip.mob]
start = clip.start
timecode_list = []
# walk down the reference chain until you reach the
# last clip with a NULL reference
for c in walker(clip):
print 'walking', c.name, c.start
start += c.start
if c.mob:
mobs.append(c.mob)
# the last mob in the chain has the timecode
timecode_list.extend(mob_timecode(mobs[-1], start, edit_rate))
return timecode_list
if __name__ == "__main__":
#f = aaf2.open(sys.argv[1])
f = aaf2.open('..\\..\\..\\tests\\data\\ml603_0p.aaf')
for mob in f.content.mastermobs():
print mob.name
print " ", get_timecode(mob.slot_at(1))
from pyaaf2.
Its definitely possible. Here is a rough example of how to get the start timecode of source clip in pyaaf1. It should be fairly similar to do it pyaaf2
markreidvfx/pyaaf#44 (comment)
I'll try and port a example to pyaaf2 when I get a chance.
from pyaaf2.
Related Issues (20)
- Error on walk() with returned Sequence HOT 2
- Creating AAF using WAV file HOT 5
- export must be in mono not in stéréo. HOT 2
- Exporting embedded essence AAFs are tricky to open in other software HOT 3
- Confused on how to add a new track HOT 4
- Destructive (in-place) change of MXF files HOT 3
- AAF create timeline of cuts with group clip HOT 1
- How to preserve link to source files after downloading an aaf from the server? HOT 1
- Create video essence from image sequence HOT 1
- Combining segments from two AAF-files to create a new single AAF-file HOT 1
- I cant get this code to work - any tips would be appreciated: HOT 1
- Need help to get timeline TC of certain effects HOT 1
- Simple Timeline Example (with linked MXFs) HOT 1
- Creating AAF with OperationGroup of type AudioWarp HOT 1
- Difference between group clips and sequences - both are composition mobs HOT 4
- packing signed/unsigned HOT 1
- Get Source Clip and put into new Timeline
- Manipulate an existing AAF's sequence timing HOT 1
- Changing creation time in aaf and creating empty sequence file HOT 4
- Error when opening aaf file HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyaaf2.