-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomotio.py
executable file
·130 lines (94 loc) · 3.79 KB
/
randomotio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /usr/bin/env python
# Populate OpenTimelineIO timeline with randomly generated clips.
# Export to common NLE formats.
# igor at hdead.com
import opentimelineio as otio
from random import randint, choice
import sys
import os
import string
import datetime
def _rand_string(r=10):
letters = string.ascii_lowercase
randString = ''.join(choice(letters) for i in range(r))
return randString
def make_otio(trkCount, clpCount):
otiort = otio.opentime.RationalTime
# Create timeline instance and name it.
timeline = otio.schema.Timeline()
timeline.name = 'Generated with randomotio.py'
# Set global start hour
seconds = hr * 60**2
hourOneFrames = otio.opentime.to_frames(otiort(value=seconds), rate=fps)
timeline.global_start_time = otiort(hourOneFrames, fps)
# Add some metadata to the timeline.
timeline.metadata['Random OTIO'] = {'version': '0.1.0'}
# Make a list containing video tracks.
tracks = [otio.schema.Track() for _t in range(trkCount)]
# Iterate video tracks and populate with clips.
for trkIdx, trk in enumerate(tracks):
# Set track name
trk.name = 'V' + str(trkIdx + 1)
# Add this track to the timeline.
timeline.tracks.append(trk)
# Make a list cotaining video clips for this track.
clips = [otio.schema.Clip() for _c in range(clpCount)]
# Iterate video clips.
for clp in clips:
# Crate a random string for the clip name.
clpName = _rand_string()
clp.name = clpName
# Set clip source range to random timecode in and duration.
minDur = 1
maxDur = int(10 * fps) # Maximum clip duration in seconds.
maxTC = hourOneFrames
tcIn = randint(0, maxTC)
dur = randint(minDur, maxDur)
clp.source_range = otio.opentime.TimeRange(
start_time=otiort(tcIn, fps),
duration=otiort(dur, fps)
)
# Add fake media reference.
randPath1 = _rand_string(8)
randPath2 = _rand_string(4)
url = os.path.join(
'/Volumes', 'FakeProject', randPath1, randPath2, clpName + '.mov'
)
clp.media_reference = otio.schema.ExternalReference(
target_url=url,
available_range = otio.opentime.TimeRange(
start_time=otiort(0, fps),
duration=otiort(86400, fps)
)
)
# Add some metadata to clips.
timestamp = datetime.datetime.now()
clp.metadata['Random OTIO'] = {
'Creation Time': str(timestamp),
'Generated By': 'randomotio.py'
}
# Add this clip to this track.
trk.append(clp)
# Make gaps half of the time
if randint(0,1) == 1:
gap = otio.schema.Gap()
gap.source_range = otio.opentime.TimeRange(
duration=otio.opentime.RationalTime(dur, fps)
)
gap.name = 'Black'
trk.append(gap)
# Set track start timecode to match the global start time.
trk.source_range = otio.opentime.TimeRange(otiort(-hourOneFrames, 24), trk.duration())
# Write OTIO file.
otio.adapters.write_to_file(timeline, 'random.otio')
# Uncomment to write other types of files.
# otio.adapters.write_to_file(timeline, 'random.xml')
# if trkCount == 1:
# otio.adapters.write_to_file(timeline, 'random.edl')
if __name__=='__main__':
trkCount = int(input('How many tracks? '))
clpCount = int(input('How many clips per track? '))
# Hardcode frame rate and start hour.
fps = 23.976
hr = 1
make_otio(trkCount, clpCount)