PyObjC AVFoundation Framework

12.1 · active · verified Mon Apr 13

PyObjC-framework-AVFoundation provides Python wrappers for Apple's AVFoundation framework on macOS. It allows Python applications to interact with audio and video capture, playback, and processing capabilities. The library is actively maintained, generally seeing releases multiple times a year, often aligning with new macOS SDK updates and Python version changes. The current version is 12.1.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use AVFoundation to enumerate available audio and video capture devices on macOS, printing their names and capabilities to the console. It uses `AVCaptureDevice` from `AVFoundation` and `NSLog` from `Foundation` for output.

from AVFoundation import AVCaptureDevice
from Foundation import NSLog

def list_capture_devices():
    NSLog("\n--- Listing Available Capture Devices ---")
    devices = AVCaptureDevice.devices()
    if not devices:
        NSLog("No capture devices found.")
        return

    for i, device in enumerate(devices):
        name = device.localizedName()
        unique_id = device.uniqueID()
        has_video = device.hasMediaType('vide')
        has_audio = device.hasMediaType('soun')
        
        NSLog(f"  {i+1}. Name: {name}, UniqueID: {unique_id}")
        if has_video: NSLog("     - Supports video capture")
        if has_audio: NSLog("     - Supports audio capture")
    NSLog("-----------------------------------------")

if __name__ == "__main__":
    # Note: For full GUI apps, you would typically run an NSApplication event loop.
    # For simple scripts, direct calls often work, but some operations might require
    # a run loop for asynchronous callbacks or permissions.
    list_capture_devices()

view raw JSON →