PyObjC CoreMedia Framework
PyObjC-framework-CoreMedia provides Python wrappers for Apple's CoreMedia framework on macOS. It is part of the larger PyObjC project, which creates a bidirectional bridge between Python and Objective-C. The library is actively maintained with frequent releases, often coinciding with new macOS SDKs and Python versions. It is currently at version 12.1 and requires Python 3.10 or newer.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9. PyObjC 11.0 dropped support for Python 3.8. Users must update their Python environment to Python 3.10 or later.
- breaking Behavior for methods in the 'init' family changed in PyObjC 11.1 to correctly model that they steal a reference to `self` and return a new reference, aligning with `clang`'s Automatic Reference Counting documentation. This may affect custom initializers written in Python.
- gotcha Several low-level C functions in CoreMedia, such as `CMBlockBufferAccessDataBytes` and `CMBlockBufferGetDataPointer`, are not directly usable from Python. Alternative functions like `CMBlockBufferCopyDataBytes` should be used instead.
- gotcha When using `CMBlockBufferCreateWithMemoryBlock`, `CMBlockBufferCreateContiguous`, or `CMBlockBufferAppendMemoryBlock`, the `customBlockSource` argument *must* be `None` from Python. Providing a custom block source is not supported.
- gotcha From PyObjC 12.1, Key-Value Observing (KVO) usage is automatically disabled for subclasses of `NSProxy` defined in Python. This prevents potential `SystemError` issues.
- gotcha In PyObjC 10.3, support for calling `__init__` when a class or its superclass had a user-implemented `__new__` was temporarily removed, causing breaking changes for some projects. Version 10.3.1 reinstated this functionality.
Install
-
pip install pyobjc-framework-coremedia
Imports
- CoreMedia
import CoreMedia
- CMTime
from CoreMedia import CMTime
Quickstart
import CoreMedia
# Create a CMTime object representing 10 seconds at a 600 timescale
# CMTimeMake(value, timescale) -> CMTime
time_value = CoreMedia.CMTimeMake(10 * 600, 600)
print(f"CMTime object: {time_value}")
print(f"Value: {time_value.value}")
print(f"Timescale: {time_value.timescale}")
print(f"Seconds: {CoreMedia.CMTimeGetSeconds(time_value)}")