本文にスキップする
Under translation
このページは現在翻訳中です。
Version: 7.0

Video modifier

The video modifier feature allows you to modify local video frames before they are transmitted. This feature enables your application to apply real-time effects, filters, or transformations to the outgoing video stream.

Supported call typeMinimum SDK version
1-to-1 call, group call (conference)PlanetKit 7.0
Note
  • The video modifier only applies to local video captured from the camera.
  • Video modification processing should be designed to minimize computational cost and latency in order to prevent frame drops and quality degradation.

Use cases

The main use cases for video modifiers are as follows.

  • Real-time video effects and filters
  • Beauty filters and facial enhancements
  • Color correction and adjustments

Implementation steps

To implement the video modifier feature, follow these steps.

Implement a video modifier

Create a class that implements the PlanetKitVideoInterceptor interface to modify video frames.

import com.linecorp.planetkit.video.PlanetKitVideoInterceptor
import com.linecorp.planetkit.video.PlanetKitVideoFrameData

class VideoModifier : PlanetKitVideoInterceptor() {
override fun onFrameIntercept(data: PlanetKitVideoFrameData): PlanetKitVideoFrameData? {
// Access video frame properties
val width = data.width // Int: frame width in pixels
val height = data.height // Int: frame height in pixels
val format = data.format // PlanetKitVideoSourceFormat: frame format
val rotation = data.rotation // PlanetKitVideoRotation: rotation angle
val timestamp = data.timestamp // Long: timestamp in nanoseconds
val buffer = data.buffer // ByteBuffer: video frame data
val size = data.size // Int: size in bytes
val isMirrored = data.isMirrored // Boolean: whether frame is horizontally flipped

// Process the frame and apply your effects
// You can either:
// 1. Process synchronously: Modify the frame and return it
// 2. Process asynchronously: Return null and call onFrameProcessedListener later

// Example: Apply your custom effect synchronously
applyVideoEffect(buffer, width, height, format)

// Return the modified frame for synchronous processing
// Return null if processing asynchronously (must set onFrameProcessedListener)
return data
}

private fun applyVideoEffect(
buffer: ByteBuffer,
width: Int,
height: Int,
format: PlanetKitVideoSourceFormat
) {
// Implement your video effect logic here
// Note: This runs on the camera capture thread, keep processing lightweight
}
}

Set the video modifier

Register the modifier with the camera manager to start modifying video frames.

// Get camera manager instance
val cameraManager = PlanetKit.getCameraManager()

// Create and set the modifier
val videoModifier = VideoModifier()
cameraManager.setVideoSourceInterceptor(videoModifier)

Clear the video modifier

Unregister the modifier to stop modifying video frames.

val cameraManager = PlanetKit.getCameraManager()

// Clear the modifier by passing null
cameraManager.setVideoSourceInterceptor(null)

The APIs related to the video modifier feature are as follows.