# SsimHelper

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/SsimHelper.java+class:androidx.media3.test.utils.SsimHelper)

*** ** * ** ***


```
@UnstableApi
public final class SsimHelper
```

<br />

*** ** * ** ***

A helper for calculating SSIM score for transcoded videos.

SSIM (Structural Similarity) Index is a statistical measurement of the similarity between two images. The mean SSIM score (taken between multiple frames) of two videos is a metric to determine the similarity of the videos. SSIM does not measure the absolute difference of the two images like MSE (mean squared error), but rather outputs the human perceptual difference. A higher SSIM score signifies higher similarity, while a SSIM score of 1 means the two images are exactly the same.

SSIM is traditionally computed with the luminance channel (Y), this class uses the luma channel (Y') because the `https://developer.android.com/reference/android/media/MediaCodec.html` decodes to luma.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/test/utils/SsimHelper#DEFAULT_COMPARISON_INTERVAL() = 11` The default comparison interval. |

| ### Public methods |
|---|---|
| `static double` | `https://developer.android.com/reference/androidx/media3/test/utils/SsimHelper#calculate(android.content.Context,java.lang.String,java.lang.String)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html referenceVideoPath, https://developer.android.com/reference/java/lang/String.html distortedVideoPath )` Returns the mean SSIM score between the reference and the distorted video. |

## Constants

### DEFAULT_COMPARISON_INTERVAL

```
public static final int DEFAULT_COMPARISON_INTERVAL = 11
```

The default comparison interval.

## Public methods

### calculate

```
public static double calculate(
    Context context,
    String referenceVideoPath,
    String distortedVideoPath
)
```

Returns the mean SSIM score between the reference and the distorted video.

The method compares every `https://developer.android.com/reference/androidx/media3/test/utils/SsimHelper#DEFAULT_COMPARISON_INTERVAL()` frame from both videos.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/java/lang/String.html referenceVideoPath` | The path to the reference video file, which must be in `https://developer.android.com/reference/android/content/Context.html#getAssets()`. |
| `https://developer.android.com/reference/java/lang/String.html distortedVideoPath` | The path to the distorted video file. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | When unable to open the provided video paths. |
| `https://developer.android.com/reference/java/lang/InterruptedException.html` |   |