# Codec Settings

## Overview

A codec, which stands for "compressor-decompressor", is critical in streaming for encoding video and audio data on the server side (compression) and decoding it on the client side (decompression). The choice of codec affects not only the stream quality and bandwidth usage but also compatibility with viewer devices.

***

## Default Codec Configuration

By default, StreamPixel has selected the most efficient codecs for optimal performance. However, depending on your specific use case and the version of Unreal Engine you are using, it might sometimes be beneficial to adjust these settings:

* **Default Settings**: `AV1` as the primary codec with `H.264` as the fallback to ensure maximum compatibility and efficiency.
* **Customization Advice**: Based on your audience’s device capabilities and network conditions, you may find it advantageous to select different primary or fallback codecs.

***

## Codec Options

Streampixel supports several codecs, each with distinct attributes suitable for different streaming requirements:

* **`H.264`**: Offers broad compatibility and fast processing, ideal for almost all devices and browsers, though it may result in blockier images at lower bitrates.
* **`VP8`**: Improves image quality at lower bitrates than H.264 but with less widespread device support.
* **`VP9`**: Provides the highest image quality at the lowest bitrates but may cause issues with WebRTC frame rates, despite excellent internal frame performance.
* **`AV1`**: The most advanced codec, offering the best compression efficiency, which is perfect for reducing bandwidth without sacrificing quality, requiring modern hardware for decoding.

***

## Codec Performance Overview

<table data-full-width="true"><thead><tr><th>Encoder</th><th>Acceleration</th><th>Encoding Speeds at 1080p/4K</th><th>Benefits</th><th>Quality at Low Bitrate</th></tr></thead><tbody><tr><td>AV1</td><td>GPU</td><td>~8.98ms/15.8ms</td><td>Has the highest image quality at the lowest bitrates, compared to other encoders.</td><td>Best</td></tr><tr><td>VP9</td><td>CPU</td><td>~15ms/50ms</td><td>Has highest image quality at lowest  bitrates</td><td>Good</td></tr><tr><td>VP8</td><td>CPU</td><td>~10.5ms/25ms</td><td>Produces a better image quality at lower bitrate</td><td>Average</td></tr><tr><td>H.264</td><td>GPU</td><td>~8.97ms/24.17ms</td><td>Fast encoding/decoding, widely supported</td><td>Blocky</td></tr></tbody></table>

Source: [Unreal Engine Documentation](https://dev.epicgames.com/documentation/en-us/unreal-engine/unreal-engine-pixel-streaming-reference)

***

## Selecting Primary and Fallback Codecs

### **Primary Codec Considerations**

Choose a primary codec based on the balance between quality and bandwidth efficiency, considering the general hardware capabilities of your audience.

{% hint style="danger" %}
AV1 is supported for Unreal Engine versions 5.4 and above. If your Unreal Engine version is below 5.4 and you have selected `AV1` as your primary codec, it will automatically fallback to the designated fallback codec.
{% endhint %}

### **Fallback Codec Usage**

The fallback codec ensures stream accessibility if the primary codec fails due to compatibility issues:

* **Recommended Setup**: Consider `VP9` for enhanced efficiency as a fallback if your audience primarily uses newer devices. Otherwise, maintain `H.264` for its universal support, especially in mixed-device environments.

{% hint style="danger" %}
`VP9` can deliver high-quality video at low bitrates but may lead to dropped WebRTC frame rates. Test this codec for your app and if issues arise, consider using `H.264` for better stability and wider compatibility.
{% endhint %}

**Examples of Fallback Codec Activation:**

1. **Device Compatibility**: If `AV1` is set as the primary codec and a viewer is using an iPhone, which does not support `AV1` decoding, the system will automatically switch to the fallback codec. This ensures that the stream remains viewable without interruption.
2. **Browser Support**: Certain versions of Firefox do not support `AV1`. In such cases, if AV1 is the primary codec, the system will fallback to a compatible codec, such as `VP9` or `H.264`, depending on your settings.

These examples illustrate common situations where the fallback codec ensures continuous service delivery, underscoring the importance of selecting a widely supported fallback codec.

***

## **Customizing Codec Settings**

1. **Access Codec Settings**: Navigate to your Streampixel project’s settings panel.
2. **Configure Codecs**: Adjust the primary and fallback codecs based on testing results and user feedback to optimize for quality and performance.

<figure><img src="https://4054772100-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUAxFCxNtDJTPCgUnSsK1%2Fuploads%2F7OhcxrIJ8kvfZsk0TZn3%2FCodec%20Selection.png?alt=media&#x26;token=249de3bd-ef40-4bb4-ba83-71e2ea737013" alt=""><figcaption><p>Codec Settings</p></figcaption></figure>

***

## **Troubleshooting and Optimization**

Monitor stream performance and user feedback actively to adapt codec settings, ensuring the best possible experience across all devices and network conditions.
