Created
November 30, 2020 09:44
-
-
Save tin2tin/924b48b2c6dcb5a7c67cb49b9acb475c to your computer and use it in GitHub Desktop.
Otio export example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import opentimelineio as otio | |
timeline = otio.schema.Timeline('Project 1', metadata={"fcp_xml": { | |
"@id": "sequence-1", | |
"media": { | |
"audio": { | |
"format": { | |
"samplecharacteristics": { | |
"depth": "16", | |
"samplerate": "48000" | |
} | |
}, | |
"numOutputChannels": "2", | |
"outputs": { | |
"group": [ | |
{ | |
"channel": { | |
"index": "1" | |
}, | |
"downmix": "0", | |
"index": "1", | |
"numchannels": "1" | |
}, | |
{ | |
"channel": { | |
"index": "2" | |
}, | |
"downmix": "0", | |
"index": "2", | |
"numchannels": "1" | |
} | |
] | |
} | |
}, | |
"video": { | |
"format": { | |
"samplecharacteristics": { | |
"anamorphic": "FALSE", | |
"codec": { | |
"appspecificdata": { | |
"appmanufacturer": "Apple Inc.", | |
"appname": "Final Cut Pro", | |
"appversion": "7.0", | |
"data": { | |
"qtcodec": { | |
"codecname": "Apple ProRes 422", | |
"codectypecode": "apcn", | |
"codectypename": "Apple ProRes 422", | |
"codecvendorcode": "appl", | |
"datarate": "0", | |
"keyframerate": "0", | |
"spatialquality": "1024", | |
"temporalquality": "0" | |
} | |
} | |
}, | |
"name": "Apple ProRes 422" | |
}, | |
"colordepth": "24", | |
"fielddominance": "none", | |
"height": "1080", | |
"pixelaspectratio": "square", | |
"rate": { | |
"ntsc": "FALSE", | |
"timebase": "25" | |
}, | |
"width": "1920" | |
} | |
} | |
} | |
}, | |
"rate": { | |
"ntsc": "FALSE", | |
"timebase": "25" | |
}, | |
"timecode": { | |
"displayformat": "NDF", | |
"rate": { | |
"ntsc": "FALSE", | |
"timebase": "25" | |
} | |
} | |
}}) | |
video_track_1 = otio.schema.Track(kind=otio.schema.track.TrackKind.Video, name="V1") | |
audio_track_1 = otio.schema.Track(kind=otio.schema.track.TrackKind.Audio, name="A1", metadata={ | |
"fcp_xml": { | |
"@premiereTrackType": "Stereo", | |
"outputchannelindex": "1", | |
"@currentExplodedTrackIndex": "0", | |
"@totalExplodedTrackCount": "2", | |
} | |
}) | |
timeline.tracks.extend([video_track_1]) | |
timeline.tracks.append(audio_track_1) | |
video_clip_1 = otio.schema.ExternalReference( | |
target_url="P:/Photo/Raw/2020/Vlogs/05 May 01/C0001.mp4", | |
available_range=otio.opentime.TimeRange( | |
start_time=otio.opentime.RationalTime(value=0, rate=25), | |
duration=otio.opentime.RationalTime(value=1000, rate=25) | |
), | |
metadata={"fcp_xml": { | |
"masterclipid": "masterclip-1", | |
"@id": "file-1", | |
"media": { | |
"audio": { | |
"channelcount": "2", | |
"samplecharacteristics": { | |
"depth": "16", | |
"samplerate": "48000" | |
} | |
}, | |
"video": { | |
"samplecharacteristics": { | |
"anamorphic": "FALSE", | |
"fielddominance": "none", | |
"height": "1080", | |
"pixelaspectratio": "square", | |
"rate": { | |
"ntsc": "FALSE", | |
"timebase": "25" | |
}, | |
"width": "1920" | |
} | |
} | |
}, | |
"rate": { | |
"ntsc": "FALSE", | |
"timebase": "25" | |
}, | |
"timecode": { | |
"displayformat": "NDF", | |
"rate": { | |
"ntsc": "FALSE", | |
"timebase": "25" | |
} | |
} | |
}} | |
) | |
video_cut_1 = otio.schema.Clip( | |
name='C0001', | |
media_reference=video_clip_1, | |
source_range=otio.opentime.TimeRange( | |
start_time=otio.opentime.RationalTime(value=112, rate=25), | |
duration=otio.opentime.RationalTime(value=40, rate=25) | |
), | |
metadata={"fcp_xml": { | |
"@id": "clipitem-1", | |
"link": [ | |
{ | |
"clipindex": "1", | |
"linkclipref": "clipitem-1", | |
"mediatype": "video", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "1", | |
"groupindex": "1", | |
"linkclipref": "clipitem-3", | |
"mediatype": "audio", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "1", | |
"groupindex": "1", | |
"linkclipref": "clipitem-5", | |
"mediatype": "audio", | |
"trackindex": "2" | |
} | |
], | |
"masterclipid": "masterclip-1", | |
"pixelaspectratio": "square", | |
}} | |
) | |
video_cut_2 = otio.schema.Clip( | |
name='C0001', | |
media_reference=video_clip_1, | |
source_range=otio.opentime.TimeRange( | |
start_time=otio.opentime.RationalTime(value=112, rate=25), | |
duration=otio.opentime.RationalTime(value=40, rate=25) | |
), | |
metadata={"fcp_xml": { | |
"@id": "clipitem-2", | |
"link": [ | |
{ | |
"clipindex": "2", | |
"linkclipref": "clipitem-2", | |
"mediatype": "video", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "2", | |
"groupindex": "1", | |
"linkclipref": "clipitem-4", | |
"mediatype": "audio", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "2", | |
"groupindex": "1", | |
"linkclipref": "clipitem-6", | |
"mediatype": "audio", | |
"trackindex": "2" | |
} | |
], | |
"masterclipid": "masterclip-1" | |
}} | |
) | |
audio_cut_1 = otio.schema.Clip( | |
name='C0001', | |
media_reference=video_clip_1, | |
source_range=otio.opentime.TimeRange( | |
start_time=otio.opentime.RationalTime(value=112, rate=25), | |
duration=otio.opentime.RationalTime(value=40, rate=25) | |
), | |
metadata={ | |
"fcp_xml": { | |
"@id": "clipitem-3", | |
"@premiereChannelType": "stereo", | |
"link": [ | |
{ | |
"clipindex": "1", | |
"linkclipref": "clipitem-1", | |
"mediatype": "video", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "1", | |
"groupindex": "1", | |
"linkclipref": "clipitem-3", | |
"mediatype": "audio", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "1", | |
"groupindex": "1", | |
"linkclipref": "clipitem-5", | |
"mediatype": "audio", | |
"trackindex": "2" | |
} | |
], | |
"masterclipid": "masterclip-1", | |
"sourcetrack": { | |
"mediatype": "audio", | |
"trackindex": "1" | |
} | |
} | |
} | |
) | |
audio_cut_2 = otio.schema.Clip( | |
name='C0001', | |
media_reference=video_clip_1, | |
source_range=otio.opentime.TimeRange( | |
start_time=otio.opentime.RationalTime(value=112, rate=25), | |
duration=otio.opentime.RationalTime(value=40, rate=25) | |
), | |
metadata={ | |
"fcp_xml": { | |
"@id": "clipitem-4", | |
"@premiereChannelType": "stereo", | |
"link": [ | |
{ | |
"clipindex": "2", | |
"linkclipref": "clipitem-2", | |
"mediatype": "video", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "2", | |
"groupindex": "1", | |
"linkclipref": "clipitem-4", | |
"mediatype": "audio", | |
"trackindex": "1" | |
}, | |
{ | |
"clipindex": "2", | |
"groupindex": "1", | |
"linkclipref": "clipitem-6", | |
"mediatype": "audio", | |
"trackindex": "2" | |
} | |
], | |
"masterclipid": "masterclip-1", | |
"sourcetrack": { | |
"mediatype": "audio", | |
"trackindex": "1" | |
} | |
} | |
} | |
) | |
video_track_1.extend([ | |
video_cut_1, | |
video_cut_2 | |
]) | |
audio_track_1.extend([audio_cut_1, audio_cut_2]) | |
result = otio.adapters.write_to_string( | |
timeline, | |
"fcp_xml" | |
) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment