# SsimHelper

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/test/utils/SsimHelper "View this page in Java")

<br />

```
@UnstableApi
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[decoder](https://developer.android.com/reference/android/media/MediaCodec.html)decodes to luma.

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [DEFAULT_COMPARISON_INTERVAL](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/SsimHelper#DEFAULT_COMPARISON_INTERVAL())` = 11` The default comparison interval. |

|                                      ### Public functions                                       |
|-------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Double](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html) | [calculate](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/SsimHelper#calculate(android.content.Context,java.lang.String,java.lang.String))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!,` ` referenceVideoPath: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` distortedVideoPath: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` `)` Returns the mean SSIM score between the reference and the distorted video. |

## Constants

### DEFAULT_COMPARISON_INTERVAL

```
const val DEFAULT_COMPARISON_INTERVAL = 11: Int
```

The default comparison interval.  

## Public functions

### calculate

```
java-static fun calculate(
    context: Context!,
    referenceVideoPath: String!,
    distortedVideoPath: String!
): Double
```

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

The method compares every[n-th](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/SsimHelper#DEFAULT_COMPARISON_INTERVAL())frame from both videos.  

|                                                 Parameters                                                 |
|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`              | The[Context](https://developer.android.com/reference/android/content/Context.html).                                                               |
| `referenceVideoPath: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The path to the reference video file, which must be in[Assets](https://developer.android.com/reference/android/content/Context.html#getAssets()). |
| `distortedVideoPath: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The path to the distorted video file.                                                                                                             |

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