VideoEffectクラスの実装
このページは映像エフェクトプラグイン作成入門 の一部です。
/icons/-.icon
この記事ではVideoEffectクラスを実装していきます。
VideoEffectクラスでは映像エフェクトの名前やカテゴリなどを設定します。
ファイルの作成
ソリューションエクスプローラーのプロジェクト名を右クリックして追加>新しい項目(W)をクリックしてください。
https://gyazo.com/38d8057525d5770599e8b0d07bb788db
SimpleEffect.csと入力して追加(A)をクリックします。
https://gyazo.com/8c4d5645b17fa7ee6ad79c6fe14419f6
このようにVideoEffectクラスは〇〇Effectという名前にするのが一般的です。
エフェクト名やカテゴリの設定
追加すると以下のコードが書かれた画面になっているかと思います。
code:SimpleEffect.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VideoEffectPluginTutorial
{
class SimpleEffect
{
}
}
以下のように書き換えます。
code:SimpleEffect.cs
using YukkuriMovieMaker.Plugin.Effects;
namespace VideoEffectPluginTutorial
{
[VideoEffect("シンプルエフェクト", "サンプル", "simple effect")]
class SimpleEffect : VideoEffectBase
{
}
}
[VideoEffect("シンプルエフェクト", ["サンプル"], ["simple effect"])]の部分は何を指定しているでしょうか。
ここは左から順に映像エフェクトの名前、カテゴリ、検索ワードを設定しています。
詳細な説明はVideoEffect属性を参照してください。
抽象クラスの実装
先ほどのコードのVideoEffectBaseはYMM4側で用意されているエフェクトの枠組みのようなものです。
あくまでVideoEffectBaseは枠組みなので実際の内容はこちら側で実装する必要があります。
まだ必要な実装を行っていないのでVisual Studio上ではクラス名(SimpleEffect)の下にエラーを示す赤線が表示されています。
赤線部にカーソルを合わせると考えられる修正内容を表示すると出てくるのでクリックしてください。
https://gyazo.com/23cd700608a4e54aae725e5c56f02321
抽象クラスの実装をクリックします。
https://gyazo.com/50ec532b88b2e4337ad3f51725647d44
以下のようにコードが補完されます。
code:SimpleEffect.cs
using YukkuriMovieMaker.Commons;
using YukkuriMovieMaker.Exo;
using YukkuriMovieMaker.Player.Video;
using YukkuriMovieMaker.Plugin.Effects;
namespace VideoEffectPluginTutorial
{
[VideoEffect("シンプルエフェクト", "サンプル", "simple effect")]
class SimpleEffect : VideoEffectBase
{
public override string Label => throw new NotImplementedException();
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription)
{
throw new NotImplementedException();
}
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
{
throw new NotImplementedException();
}
protected override IEnumerable<IAnimatable> GetAnimatables()
{
throw new NotImplementedException();
}
}
}
コード内のthrow new NotImplementedException()はその部分が実装されてないことを表しています。
そのため、これが書いてある場所に適切な内容を記述する必要があります。
次の通りにそれぞれの箇所を書き換えてください。
/icons/-.icon
Label
code:実装前.cs
public override string Label => throw new NotImplementedException();
code:実装後.cs
public override string Label => "シンプルエフェクト";
この部分では映像エフェクトの名前を設定します。
先ほどもエフェクトの名前を設定しましたがこれは表示される場所が異なります。
ここで設定した名前は映像エフェクト欄とファイル(F) > 設定 > プラグインのプラグイン一覧に表示されます。
https://gyazo.com/8c8f1db42b36c627e90778845a645d7ehttps://gyazo.com/1070b43d1ecf5c3b73c499ff91fcc8f9
/icons/-.icon
CreateExoVideoFilters
code:実装前.cs
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription)
{
throw new NotImplementedException();
}
code:実装後.cs
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription)
{
return [];
}
この部分ではExo出力の設定を行います。
今回は非対応のまま実装します。そのため空のstring[]を返しています。
/icons/-.icon
CreateVideoEffect
code:実装前.cs
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
{
throw new NotImplementedException();
}
code:実装後.cs
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
{
return new SimpleEffectProcessor(devices, this);
}
前回述べた通り映像エフェクトには現在実装しているVideoEffectクラスの他にVideoEffectProcessorクラスも必要です。
このCreateVideoEffectメソッドはVideoEffectクラスとVideoEffectProcessorクラスを繋ぐ役割があります。
まだSImpleEffectProcessorクラスを作っていないのでエラーとなっていますが問題ありません。
/icons/-.icon
GetAnimatables
code:実装前.cs
protected override IEnumerable<IAnimatable> GetAnimatables()
{
throw new NotImplementedException();
}
code:実装後.cs
protected override IEnumerable<IAnimatable> GetAnimatables() => [];
この部分ではクラス内のアニメーションスライダーを列挙します。
これについては後ほど解説します。
/icons/-.icon
これでSimpleEffectクラスの実装は完了です。
参考
最終的なSimpleEffect.csは次のようになります。
code:SimpleEffect.cs
using YukkuriMovieMaker.Commons;
using YukkuriMovieMaker.Exo;
using YukkuriMovieMaker.Player.Video;
using YukkuriMovieMaker.Plugin.Effects;
namespace VideoEffectPluginTutorial
{
[VideoEffect("シンプルエフェクト", "サンプル", "simple effect")]
class SimpleEffect : VideoEffectBase
{
public override string Label => "シンプルエフェクト";
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription)
{
return [];
}
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
{
return new SimpleEffectProcessor(devices, this);
}
protected override IEnumerable<IAnimatable> GetAnimatables() => [];
}
}
/icons/-.icon
次はこちら:VideoEffectProcessorクラスの実装