Keyframe Pro 2 Documentation
Python Client API Examples
The examples provided below detail common actions that can be performed using the Python Client API.
The Python Client API can be downloaded from the Keyframe Pro 2 main page.
Hello World
The following example demonstrates how to connect with and initialize Keyframe Pro 2 for communication using the client API.
After the initialization has been completed successufully all of the commands in the Python Client API are available for use in scripts.
from keyframe_pro_2_client_api import KeyframePro2ClientApi
kpro2_client = KeyframePro2ClientApi()
if kpro2_client.connect():
if kpro2_client.initialize():
print(kpro2_client.echo("Hello World!"))
else:
print("Failed to initialize Keyframe Pro 2 Client.")
else:
print("Failed to connect to Keyframe Pro 2.")
Importing a Source
The following example creates a new empty project and imports a single source file.
from keyframe_pro_2_client_api import KeyframePro2ClientApi
kpro2_client = KeyframePro2ClientApi()
if kpro2_client.connect() and kpro2_client.initialize():
kpro2_client.new_project(empty=True)
kpro2_client.import_file('E:/big_buck_bunny_720p_h264.mov')
Constructing a Timeline
The following example creates an empty project and imports three source files. It then adds a new timeline to the project and inserts each source into the timeline. Finally, the new timeline is set active in the primary viewer.
from keyframe_pro_2_client_api import KeyframePro2ClientApi
kpro2_client = KeyframePro2ClientApi()
if kpro2_client.connect() and kpro2_client.initialize():
kpro2_client.new_project(empty=True)
paths = [
'E:/clip_01.mp4',
'E:/clip_02.mp4',
'E:/clip_03.mp4',
]
# Import sources
sources = []
for path in paths:
sources.append(kpro2_client.import_file(path))
# Create a new timeline
timeline = kpro2_client.add_timeline('My Timeline')
for source in sources:
kpro2_client.insert_element_in_timeline(source['id'], timeline['id'])
# Make the timeline active in viewer A
kpro2_client.set_active_in_viewer(timeline['id'], 0)
Exporting to a File
The following example exports the active timeline (in viewer A). It then waits until the process is finished.
from keyframe_pro_2_client_api import KeyframePro2ClientApi
kpro2_client = KeyframePro2ClientApi()
if kpro2_client.connect() and kpro2_client.initialize():
# Start the export process
if kpro2_client.queue_export("E:/final", "api_export", "mp4", 1280, 720):
print("Export queued")
# Query for export completion (query will timeout if not finished)
results = kpro2_client.query_export(show_poll_timeout_errors=False)
if results:
# results is a tuple - success (boolean) and error messages (if any)
if(results[0]):
print("Export completed successfully")
else:
print(results[1])
else:
print("Export timed out")