# Encoded frames

Encoded video and audio frames an [`webrtc.RTCRtpScriptTransformer`](../interfaces/rtc_rtp_script_transform.md#webrtc.interfaces.rtc_rtp_script_transform.RTCRtpScriptTransformer) reads and writes, with their metadata.

### *class* webrtc.models.rtc_encoded_frame.RTCEncodedFrameMetadata(synchronization_source=None, payload_type=None, contributing_sources=None, rtp_timestamp=None, receive_time=None, capture_time=None, sender_capture_time_offset=None, mime_type=None)

The metadata shared by encoded video and audio frames. A member the frame lacks is [`None`](https://docs.python.org/3/builtins/constants.html#None).

* **Parameters:**
  * **synchronization_source** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The SSRC of the RTP stream the frame belongs to.
  * **payload_type** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The RTP payload type of the frame.
  * **contributing_sources** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The CSRCs of the frame.
  * **rtp_timestamp** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The RTP timestamp of the frame.
  * **receive_time** ([`float`](https://docs.python.org/3/builtins/functions.html#float), optional) – For a received frame, when its first packet arrived, in
    milliseconds since the Unix epoch.
  * **capture_time** ([`float`](https://docs.python.org/3/builtins/functions.html#float), optional) – When the frame was captured, in milliseconds since the Unix epoch.
    A received frame uses the clock of the remote peer.
  * **sender_capture_time_offset** ([`float`](https://docs.python.org/3/builtins/functions.html#float), optional) – For a received frame, the offset between the clock of
    the capturing system and that of the sender, in milliseconds.
  * **mime_type** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), optional) – The codec of the frame, such as `'video/VP8'`.

### *class* webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrameMetadata(synchronization_source=None, payload_type=None, contributing_sources=None, rtp_timestamp=None, receive_time=None, capture_time=None, sender_capture_time_offset=None, mime_type=None, frame_id=None, dependencies=None, width=None, height=None, spatial_index=None, temporal_index=None, timestamp=None)

The metadata of an [`RTCEncodedVideoFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrame). It adds to the members of [`RTCEncodedFrameMetadata`](#webrtc.models.rtc_encoded_frame.RTCEncodedFrameMetadata).

See [MDN: RTCEncodedVideoFrame/getMetadata](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedVideoFrame/getMetadata).

* **Parameters:**
  * **frame_id** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The identifier of the frame, which `dependencies` of later frames
    refer to.
  * **dependencies** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The `frame_id` values of the frames this one
    depends on.
  * **width** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The width of the frame, in pixels.
  * **height** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The height of the frame, in pixels.
  * **spatial_index** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The spatial layer of the frame.
  * **temporal_index** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The temporal layer of the frame.
  * **timestamp** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The presentation timestamp of the frame, in microseconds.

### *class* webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrameMetadata(synchronization_source=None, payload_type=None, contributing_sources=None, rtp_timestamp=None, receive_time=None, capture_time=None, sender_capture_time_offset=None, mime_type=None, sequence_number=None, audio_level=None)

The metadata of an [`RTCEncodedAudioFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrame). It adds to the members of [`RTCEncodedFrameMetadata`](#webrtc.models.rtc_encoded_frame.RTCEncodedFrameMetadata).

See [MDN: RTCEncodedAudioFrame/getMetadata](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedAudioFrame/getMetadata).

* **Parameters:**
  * **sequence_number** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The RTP sequence number of a received frame.
  * **audio_level** ([`float`](https://docs.python.org/3/builtins/functions.html#float), optional) – The audio level of the frame, from 0 (silence) to 1 (0 dBov).

### *class* webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrameOptions(metadata=None)

The options for copying an [`RTCEncodedVideoFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrame).

See [MDN: RTCEncodedVideoFrame/RTCEncodedVideoFrame](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedVideoFrame/RTCEncodedVideoFrame).

* **Parameters:**
  **metadata** ([`RTCEncodedVideoFrameMetadata`](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrameMetadata), optional) – Metadata for the copy. Each member that isn’t
  [`None`](https://docs.python.org/3/builtins/constants.html#None) replaces that of the original frame.

### *class* webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrameOptions(metadata=None)

The options for copying an [`RTCEncodedAudioFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrame).

See [MDN: RTCEncodedAudioFrame/RTCEncodedAudioFrame](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedAudioFrame/RTCEncodedAudioFrame).

* **Parameters:**
  **metadata** ([`RTCEncodedAudioFrameMetadata`](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrameMetadata), optional) – Metadata for the copy. Each member that isn’t
  [`None`](https://docs.python.org/3/builtins/constants.html#None) replaces that of the original frame.

### *class* webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrame(original_frame, options=None)

An encoded video frame, read from an [`webrtc.RTCRtpScriptTransformer`](../interfaces/rtc_rtp_script_transform.md#webrtc.interfaces.rtc_rtp_script_transform.RTCRtpScriptTransformer) and written back to it.

The constructor copies a frame with its payload and metadata. A copy belongs to no sender or receiver, so writing it
to a transformer drops it.

See [MDN: RTCEncodedVideoFrame](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedVideoFrame).

* **Parameters:**
  * **original_frame** ([`RTCEncodedVideoFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrame)) – The frame to copy.
  * **options** ([`RTCEncodedVideoFrameOptions`](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrameOptions), optional) – Metadata overriding that of the original.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If `original_frame` isn’t an [`RTCEncodedVideoFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrame).
  * [**webrtc.DataCloneError**](../exceptions.md#webrtc.exceptions.DataCloneError) – If `original_frame` was written.

#### *property* type *: [EncodedVideoChunkType](../enums.md#webrtc.enums.EncodedVideoChunkType)*

Whether it’s a key frame or a delta frame.

See [MDN: RTCEncodedVideoFrame/type](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedVideoFrame/type).

* **Type:**
  [`webrtc.EncodedVideoChunkType`](../enums.md#webrtc.enums.EncodedVideoChunkType)

#### get_metadata()

Returns the metadata of the frame.

See [MDN: RTCEncodedVideoFrame/getMetadata](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedVideoFrame/getMetadata).

* **Returns:**
  [`RTCEncodedVideoFrameMetadata`](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrameMetadata) – A copy, so changing it doesn’t change the frame.
* **Return type:**
  [*RTCEncodedVideoFrameMetadata*](#webrtc.models.rtc_encoded_frame.RTCEncodedVideoFrameMetadata)

### *class* webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrame(original_frame, options=None)

An encoded audio frame, read from an [`webrtc.RTCRtpScriptTransformer`](../interfaces/rtc_rtp_script_transform.md#webrtc.interfaces.rtc_rtp_script_transform.RTCRtpScriptTransformer) and written back to it.

The constructor copies a frame with its payload and metadata. A copy belongs to no sender or receiver, so writing it
to a transformer drops it.

See [MDN: RTCEncodedAudioFrame](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedAudioFrame).

* **Parameters:**
  * **original_frame** ([`RTCEncodedAudioFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrame)) – The frame to copy.
  * **options** ([`RTCEncodedAudioFrameOptions`](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrameOptions), optional) – Metadata overriding that of the original.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If `original_frame` isn’t an [`RTCEncodedAudioFrame`](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrame).
  * [**webrtc.DataCloneError**](../exceptions.md#webrtc.exceptions.DataCloneError) – If `original_frame` was written.

#### get_metadata()

Returns the metadata of the frame.

See [MDN: RTCEncodedAudioFrame/getMetadata](https://developer.mozilla.org/en-US/docs/Web/API/RTCEncodedAudioFrame/getMetadata).

* **Returns:**
  [`RTCEncodedAudioFrameMetadata`](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrameMetadata) – A copy, so changing it doesn’t change the frame.
* **Return type:**
  [*RTCEncodedAudioFrameMetadata*](#webrtc.models.rtc_encoded_frame.RTCEncodedAudioFrameMetadata)
