本文にスキップする
Version: 7.0

ビデオモディファイアー

ビデオモディファイアー機能を使用すると、ビデオ送信前にローカルビデオフレームを修正できます。この機能により、アプリケーションはリアルタイムエフェクト、フィルター、または変換を送信ビデオストリームに適用できます。

対応する通話タイプSDKの最低バージョン
1対1通話、グループ通話(カンファレンス)PlanetKit 7.0
Note
  • ビデオモディファイアーは、カメラでキャプチャーしたローカルビデオにのみ適用されます。
  • ビデオ修正処理時にフレームのドロップや画質低下を防ぐため、演算コストと遅延時間を最小限に抑える必要があります。

活用事例

ビデオモディファイアーの主な活用例は次のとおりです。

  • リアルタイムのビデオエフェクトとフィルター
  • ビューティーフィルターと顔補正
  • 色補正と調整

実装段階

ビデオモディファイアー機能を実装するには、次の手順に従います。

ビデオモディファイアーの実装

IVideoInterceptorを継承するクラスを作成してビデオフレームを修正します。

#include "PlanetKit.h"
#include "IPlanetKitVideoInterceptor.h"

class VideoModifier : public PlanetKit::IVideoInterceptor {
public:
PlanetKit::SVideoFrame* ProcessVideoFrame(PlanetKit::SVideoFrame* pVideoFrame) override {
if (!pVideoFrame) {
return nullptr;
}

// Access video frame properties from SVideoFrame structure:
// - pVideoFrame->pbuffer: Pointer to the frame buffer
// - pVideoFrame->unBufferSize: Allocated buffer size
// - pVideoFrame->unDataLength: Actual length (in bytes) of buffer data
// - pVideoFrame->unWidth: Frame width in pixels
// - pVideoFrame->unHeight: Frame height in pixels
// - pVideoFrame->llTick: Tick count in microseconds
// - pVideoFrame->llTimeStamp: Timestamp
// - pVideoFrame->llDuration: Frame duration
// - pVideoFrame->eRotation: Rotation angle
// - pVideoFrame->bSubgroupMain: Whether frame belongs to main room
// - pVideoFrame->szSubgroupName: Subgroup name (if bSubgroupMain is false)

// Process the frame and apply your effects
// You can either:
// 1. Process synchronously: Modify the frame and return the pointer
// 2. Process asynchronously: Return nullptr and call delegate->onProcessFinished later

// Example: Apply your custom effect synchronously
ApplyVideoEffect(pVideoFrame);

// Return the modified frame pointer for synchronous processing
// Return nullptr if processing asynchronously (must register a delegate)
return pVideoFrame;
}

bool RegisterDelegate(PlanetKit::IVideoInterceptorDelegate* pDelegate) override {
m_pDelegate = pDelegate;
return true;
}

bool DeregisterDelegate() override {
m_pDelegate = nullptr;
return true;
}

private:
void ApplyVideoEffect(PlanetKit::SVideoFrame* pVideoFrame) {
// Implement your video effect logic here
// Note: This runs on the camera capture thread, keep processing lightweight
}

PlanetKit::IVideoInterceptorDelegate* m_pDelegate = nullptr;
};

ビデオモディファイアーの設定

カメラコントローラーにモディファイアーを登録してビデオフレームの修正を開始します。

// Get camera controller instance
PlanetKit::CameraControllerPtr pCameraController = PlanetKit::PlanetKitManager::GetInstance()->GetCameraController();

// Create and register the modifier
PlanetKit::IVideoInterceptorPtr pVideoModifier = PlanetKit::MakeAutoPtr<VideoModifier>();

bool success = pCameraController->RegisterVideoInterceptor(pVideoModifier);
if (!success) {
// Handle error
}

ビデオモディファイアーの解除

モディファイアーの登録を解除してビデオフレームの修正を中止します。

PlanetKit::CameraControllerPtr pCameraController = PlanetKit::PlanetKitManager::GetInstance()->GetCameraController();

// Deregister the modifier
bool success = pCameraController->DeregisterVideoInterceptor();
if (!success) {
// Handle error
}

関連API

ビデオモディファイアー機能とこれに関連するAPIは以下のとおりです。