Skip to content

Commit

Permalink
Video Transformers Kotlin sample
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalocostamendes committed Aug 4, 2023
1 parent f22c064 commit fbc521e
Show file tree
Hide file tree
Showing 28 changed files with 1,004 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Video-Transformers-Kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# intellij
*.iml

.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
app/build

.settings/
app/jniLibs/
86 changes: 86 additions & 0 deletions Video-Transformers-Kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Video Transformers
======================

The Video Transformers app is a very simple application created on top of Basic Video Chat meant to get a new developer
started using Media Processor APIs on OpenTok Android SDK. For a full description, see the [Video Transformers tutorial at the
OpenTok developer center](https://tokbox.com/developer/guides/vonage-media-processor/android).

You can use pre-built transformers in the Vonage Media Processor library or create your own custom video transformer to apply to published video.

You can use the <a href="/developer/sdks/android/reference/com/opentok/android/PublisherKit.html#setAudioTransformers(java.util.ArrayList)"><code>PublisherKit.setAudioTransformers()</code></a> and
<a href="/developer/sdks/android/reference/com/opentok/android/PublisherKit.html#setVideoTransformers(java.util.ArrayList)"><code>PublisherKit.setVideoTransformers()</code></a>
methods to apply audio and video transformers to a stream.

For video, you can apply the background blur video transformer included in the Vonage Media Library.

You can also create your own custom audio and video transformers.

## Applying a video transformer from the Vonage Media Library

Use the <a href="/developer/sdks/android/reference/com/opentok/android/PublisherKit.VideoTransformer.html#%3Cinit%3E(java.lang.String,java.lang.String)"><code>PublisherKit.VideoTransformer(String name, String properties)</code></a>
constructor to create a video transformer that uses a named transformer from the Vonage Media Library.

Currently, only one transformer is supported: background blur. Set the `name` parameter to `"BackgroundBlur"`.
Set the `properties` parameter to a JSON string defining properties for the transformer.
For the background blur transformer, this JSON includes one property -- `radius` -- which can be set
to `"High"`, `"Low"`, or `"None"`.

```java
var videoTransformers: ArrayList<VideoTransformer> = ArrayList()
val backgroundBlur = publisher!!.VideoTransformer("BackgroundBlur", "{\"radius\":\"High\"}")
videoTransformers.add(backgroundBlur)
publisher!!.setVideoTransformers(videoTransformers)
```

## Creating a custom video transformer

Create a class that implements the <a href="/developer/sdks/android/reference/com/opentok/android/PublisherKit.CustomVideoTransformer.html"><code>PublisherKit.CustomVideoTransformer</code></a>
interface. Implement the `PublisherKit.CustomVideoTransformer.onTransform​(BaseVideoRenderer.Frame frame)` method. The `PublisherKit.CustomVideoTransformer.onTransform​(BaseVideoRenderer.Frame frame)` method is triggered for each video frame.
In the implementation of the method, apply a transformation to the `frame` object passed into the method:

```java
public class MyCustomTransformer implements PublisherKit.CustomVideoTransformer {
@Override
public void onTransform(BaseVideoRenderer.Frame frame) {
// Replace this with code to transform the frame:
frame.convertInPlace(frame.getYplane(), frame.getVplane(), frame.getUplane(), frame.getYstride(), frame.getUvStride());
}
}
```

Then pass the object that implements the PublisherKit.CustomVideoTransformer interface into the `PublisherKit.setVideoTransformers()` method:

```java
var videoTransformers: ArrayList<VideoTransformer> = ArrayList()
val myCustomTransformer = publisher!!.VideoTransformer("myTransformer", logoTransformer)
videoTransformers.add(myCustomTransformer)
publisher!!.setVideoTransformers(videoTransformers)
```

You can combine the Vonage Media library transformer (see the previous section) with custom transformers or apply
multiple custom transformers by adding multiple PublisherKit.VideoTransformer objects to the ArrayList passed
into the `PublisherKit.setVideoTransformers()` method.

Then pass the object that implements the PublisherKit.CustomAudioRransformer interface into the `PublisherKit.setAudioTransformers()` method:

```java
var videoTransformers: ArrayList<VideoTransformer> = ArrayList()
val backgroundBlur = publisher!!.VideoTransformer("BackgroundBlur", "{\"radius\":\"High\"}")
val myCustomTransformer = publisher!!.VideoTransformer("myTransformer", logoTransformer)
videoTransformers.add(backgroundBlur)
videoTransformers.add(myCustomTransformer)
publisher!!.setVideoTransformers(videoTransformers)
```

You can apply multiple custom transformers by adding multiple PublisherKit.VideoTransformer objects to the ArrayList
passed into the `PublisherKit.setVideoTransformers()` method.

## Clearing video transformers for a publisher

To clear video transformers for a publisher, pass an empty ArrayList into
into the `PublisherKit.setVideoTransformers()` method.

```java
videoTransformers.clear();
publisher!!.setVideoTransformers(videoTransformers)
```
4 changes: 4 additions & 0 deletions Video-Transformers-Kotlin/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
config.gradle
*.jar
*.so
49 changes: 49 additions & 0 deletions Video-Transformers-Kotlin/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
}

apply {
from '../../commons.gradle'
}

android {
compileSdkVersion extCompileSdkVersion

defaultConfig {
applicationId "com.tokbox.sample.basicvideochat"
minSdkVersion extMinSdkVersion
targetSdkVersion extTargetSdkVersion
versionCode extVersionCode
versionName extVersionName
}

buildTypes {
release {
minifyEnabled extMinifyEnabled
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
// Dependency versions are defined in the ../../commons.gradle file
implementation "com.opentok.android:opentok-android-sdk:${extOpentokSdkVersion}"
implementation "androidx.appcompat:appcompat:${extAppCompatVersion}"
implementation "pub.devrel:easypermissions:${extEasyPermissionsVersion}"
implementation "androidx.constraintlayout:constraintlayout:${extConstraintLyoutVersion}"

implementation "com.squareup.retrofit2:retrofit:${extRetrofitVersion}"
implementation "com.squareup.okhttp3:okhttp:${extOkHttpVersion}"
implementation "com.squareup.retrofit2:converter-moshi:${extRetrofit2ConverterMoshi}"
implementation "com.squareup.okhttp3:logging-interceptor:${extOkHttpLoggingInterceptor}"
}
32 changes: 32 additions & 0 deletions Video-Transformers-Kotlin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tokbox.sample.basicvideochat" >

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading

0 comments on commit fbc521e

Please sign in to comment.