-
Notifications
You must be signed in to change notification settings - Fork 209
Video_Filter
buliaoyin edited this page Jun 30, 2017
·
12 revisions
推流SDK当前自定义GPU滤镜,即使用OpenGl方式添加App自己的视频滤镜
v4.x硬编和软编均支持自定义GPU滤镜,为开发者提供基类ImgTexFilter自定义视频滤镜
滤镜会在预览和推流端都生效
继承ImgTexFilter类创建自己的类,如DemoFilter
SDK内部为了实现同时对samplerExternalOES和sampler2D两种输入Texture格式的兼容, 会根据输入Texture的类型自动在shader代码开始处添加
"#extension GL_OES_EGL_image_external : require\n" +
"uniform samplerExternalOES sTexture;\n"
或
"uniform sampler2D sTexture;\n"
这就要求开发者在移植时,需要删除原有的输入Texture声明,然后shader代码内部所有用到该输入Texture的地方,将名称改为sTexture.
调用KSYStreamer中的getImgTexFilterMgt.setFilter
接口将自己的filter设置给SDK
通过ImgTexFilter的setFilter接口的多个重载,支持0~N个filter滤镜同时生效(该接口推流过程中设置也生效)
- setFilter(ImgTexFilter filter) 单个filter生效,若filter为null则0个filter生效
- setFilter(ImgTexFilter[] filterArray)和setFilter(List filters) 多个filter生效
注:
自定义美颜和内置美颜可以并存,内置美颜类已经公开,参考API接口速查:com.ksyun.media.streamer.filter.imgtex
ImgTexFilter的构造函数需要传入GLRender
的实例,调用KSYStreamer
的getGLRender接口获取
参考代码如下(demo中CameraActivity):
private void showChooseFilter() {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this)
.setTitle("请选择美颜滤镜")
.setSingleChoiceItems(
new String[]{"BEAUTY_SOFT", "SKIN_WHITEN", "BEAUTY_ILLUSION", "DENOISE",
"BEAUTY_SMOOTH", "DEMOFILTER", "GROUP_FILTER"}, -1,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which < 5) {
//设置内置美颜
mStreamer.getImgTexFilterMgt().setFilter(
mStreamer.getGLRender(), which + 16);
} else if (which == 5) {
//设置一个自定义美颜
mStreamer.getImgTexFilterMgt().setFilter(
new DemoFilter(mStreamer.getGLRender()));
} else if (which == 6) {
//设置多个自定义美颜
List<ImgTexFilter> groupFilter = new LinkedList<>();
groupFilter.add(new DemoFilter2(mStreamer.getGLRender()));
groupFilter.add(new DemoFilter3(mStreamer.getGLRender()));
groupFilter.add(new DemoFilter4(mStreamer.getGLRender()));
mStreamer.getImgTexFilterMgt().setFilter(groupFilter);
}
dialog.dismiss();
}
})
.create();
alertDialog.setCancelable(false);
alertDialog.show();
}