Skip to content

The Python SDK is missing backup codec support that is available in the JavaScript SDK #511

@mc4future

Description

@mc4future

Description

The Python SDK is missing backup codec support that is available in the JavaScript SDK. The BackupCodecPolicy enum exists at the protocol level, but the high-level publish_track() API doesn't expose it to developers.

Current Behavior

# Python SDK - backup codec NOT supported
publication = await room.local_participant.publish_track(track, options)
# No way to specify backup codec or policy

Expected Behavior

# Python SDK - should support backup codec like JS SDK
publication = await room.local_participant.publish_track(
    track,
    options,
    backup_codec_policy=rtc.BackupCodecPolicy.PREFER_REGRESSION,
    backup_codec="h264"
)

JavaScript SDK Comparison

The JavaScript SDK already supports this feature:

await room.localParticipant.publishTrack(track, {
  videoCodec: 'vp8',
  backupCodec: { codec: 'h264' },
});

Impact

Without backup codec support, Python developers cannot:

  • Specify codec fallback behavior for better compatibility
  • Handle cases where the primary codec isn't supported by all participants
  • Match the functionality available in other SDKs

Investigation

I've confirmed that:

  • TrackInfo (protocol level) has backup_codec_policy field
  • BackupCodecPolicy enum exists with values: PREFER_REGRESSION (0), SIMULCAST (1), REGRESSION (2)
  • TrackPublishOptions (high-level API) doesn't expose these fields to developers

Proposed Solution

I've created a PR that adds this functionality: #510

The changes:

  1. Import and export BackupCodecPolicy enum from livekit.protocol.models
  2. Extend LocalParticipant.publish_track() with two new optional parameters:
    • backup_codec_policy: Optional[int] - Accepts BackupCodecPolicy enum values
    • backup_codec: Optional[str] - Accepts codec name (e.g., "vp8", "h264")
  3. Includes graceful fallback if FFI protocol doesn't support the fields
  4. Fully backward compatible

Request

Could the team please review PR #510 and consider merging it? This would bring the Python SDK to feature parity with the JavaScript SDK and enable codec fallback support for Python developers.

Happy to make any adjustments based on feedback!

Environment

  • LiveKit Python SDK: 1.0.16
  • Python: 3.11+
  • Platform: All platforms

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions