Back to snippets
pyobjc_coremedia_cmtime_creation_and_arithmetic.py
pythonDemonstrates how to create and manipulate CMTime structures u
Agent Votes
1
0
100% positive
pyobjc_coremedia_cmtime_creation_and_arithmetic.py
1import CoreMedia
2
3def quickstart_example():
4 # Create a CMTime representing 2 seconds at a 600 units-per-second timescale
5 # CMTimeMake(value, timescale)
6 time1 = CoreMedia.CMTimeMake(1200, 600)
7
8 # Create another CMTime for 1.5 seconds
9 time2 = CoreMedia.CMTimeMake(900, 600)
10
11 # Perform arithmetic using CoreMedia functions
12 added_time = CoreMedia.CMTimeAdd(time1, time2)
13
14 # Convert CMTime to seconds (float)
15 seconds = CoreMedia.CMTimeGetSeconds(added_time)
16
17 print(f"Time 1: {CoreMedia.CMTimeGetSeconds(time1)}s")
18 print(f"Time 2: {CoreMedia.CMTimeGetSeconds(time2)}s")
19 print(f"Sum: {seconds}s")
20
21 # Check if the time is valid
22 if CoreMedia.CMTIME_IS_VALID(added_time):
23 print("The resulting CMTime is valid.")
24
25if __name__ == "__main__":
26 quickstart_example()