{"id":5408,"library":"pyobjc-framework-coremedia","title":"PyObjC CoreMedia Framework","description":"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.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objective-c","coremedia","media","pyobjc","bindings"],"install":[{"cmd":"pip install pyobjc-framework-coremedia","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core runtime for the PyObjC bridge, essential for all PyObjC framework wrappers.","package":"pyobjc-core","optional":false},{"reason":"Often used alongside CoreMedia for applications, provides fundamental Cocoa classes like NSObject and NSApplication. While not strictly a direct dependency of *this specific wrapper*, it's a common practical dependency for many PyObjC applications that use media frameworks.","package":"pyobjc-framework-Cocoa","optional":true}],"imports":[{"note":"The CoreMedia framework bindings are accessed directly via the 'CoreMedia' package name.","symbol":"CoreMedia","correct":"import CoreMedia"},{"symbol":"CMTime","correct":"from CoreMedia import CMTime"}],"quickstart":{"code":"import CoreMedia\n\n# Create a CMTime object representing 10 seconds at a 600 timescale\n# CMTimeMake(value, timescale) -> CMTime\ntime_value = CoreMedia.CMTimeMake(10 * 600, 600)\n\nprint(f\"CMTime object: {time_value}\")\nprint(f\"Value: {time_value.value}\")\nprint(f\"Timescale: {time_value.timescale}\")\nprint(f\"Seconds: {CoreMedia.CMTimeGetSeconds(time_value)}\")\n","lang":"python","description":"This example demonstrates importing the CoreMedia framework and creating a basic CMTime object, which is a fundamental structure for representing time in CoreMedia. It then prints some of its properties and converts it to seconds."},"warnings":[{"fix":"Upgrade Python to 3.10 or newer (current version 12.1 requires >=3.10).","message":"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.","severity":"breaking","affected_versions":"11.0, 12.0"},{"fix":"Review custom `init` methods for correct reference handling according to ARC semantics, particularly if porting from older PyObjC versions.","message":"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.","severity":"breaking","affected_versions":">=11.1"},{"fix":"Consult PyObjC's API Notes for CoreMedia to identify unsupported C functions and their Python-compatible alternatives.","message":"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.","severity":"gotcha","affected_versions":"All"},{"fix":"Always pass `None` for `customBlockSource` when calling these specific `CMBlockBuffer` creation/modification functions.","message":"When using `CMBlockBufferCreateWithMemoryBlock`, `CMBlockBufferCreateContiguous`, or `CMBlockBufferAppendMemoryBlock`, the `customBlockSource` argument *must* be `None` from Python. Providing a custom block source is not supported.","severity":"gotcha","affected_versions":"All"},{"fix":"Be aware that KVO will not function for `NSProxy` subclasses implemented in Python. Adjust design or use alternative observation mechanisms if this behavior is critical.","message":"From PyObjC 12.1, Key-Value Observing (KVO) usage is automatically disabled for subclasses of `NSProxy` defined in Python. This prevents potential `SystemError` issues.","severity":"gotcha","affected_versions":">=12.1"},{"fix":"Ensure you are using PyObjC 10.3.1 or later if your code relies on `__init__` being called after a custom `__new__` implementation.","message":"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.","severity":"gotcha","affected_versions":"10.3 (fixed in 10.3.1)"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}