-
Notifications
You must be signed in to change notification settings - Fork 209
Video_CPU_Filter
zanxiaofei edited this page Feb 15, 2017
·
2 revisions
从v4.0.4版本开始,推流端SDK支持在GPU通路中添加CPU滤镜,并应用到预览和推流端,仅支持Android4.4及以上机型。
当前支持的数据格式:
-
✓ RGBA
-
✓ YUVI420
Warning
|
使用该方式会比纯GPU滤镜引入额外的性能消耗,我们建议,尽量改用GPU滤镜实现相同的效果。 |
-
RGBA滤镜
-
参考demo中的RGBABufDemoFilter类的实现,继承RGBABufFilter,实现对RGBA buffer数据的处理;
public class RGBABufDemoFilter extends RGBABufFilter { public RGBABufDemoFilter(GLRender glRender) { super(glRender); } @Override protected void onSizeChanged(int stride, int width, int height) { // do nothing. } /** * 实现对RGBA buffer数据的处理 * * @param buffer the image RGBA buffer * @param stride the row stride for this RGBA plane, in bytes * @param width the image width * @param height the image height * @return 处理后的RGBA数据 */ @Override protected ByteBuffer doFilter(ByteBuffer buffer, int stride, int width, int height) { // handle buffer here return buffer; } }
-
将该CPU滤镜添加到SDK的处理通路中,需要在创建KSYStreamer实例后进行。
// add RGBA buffer filter to ImgTexFilterMgt, this would cause performance drop, // only valid after Android 4.4 RGBABufDemoFilter demoFilter = new RGBABufDemoFilter(mStreamer.getGLRender()); mStreamer.getImgTexFilterMgt().setExtraFilter(demoFilter);
-
-
YUVI420滤镜
-
参考demo中的YUVI420BufDemoFilter类的实现,继承ImgTexBufFilter,实现对YUVI420 buffer数据的处理;
public class YUVI420BufDemoFilter extends ImgTexBufFilter { private static final String TAG = "YUVI420BufDemoFilter"; public YUVI420BufDemoFilter(GLRender glRender) { super(glRender, ImgBufFormat.FMT_I420); //must set ImgBufFormat.FMT_I420 } @Override protected void onSizeChanged(int[] stride, int width, int height) { Log.d(TAG, "onSizeChanged " + stride[0] + " " + width + "x" + height); // do nothing. } /** * 实现对YUVI420 buffer数据的处理 * * @param buffer the image YUVI420 buffer * @param stride the stride for this YUVI420 * @param width the image width * @param height the image height * @return 处理后的YUVI420数据 */ @Override protected ByteBuffer doFilter(ByteBuffer buffer, int[] stride, int width, int height) { Log.d(TAG, "doFilter " + buffer + " " + stride[0] + " " + width + "x" + height); // handle buffer here return buffer; } }
-
将该CPU滤镜添加到SDK的处理通路中,需要在创建KSYStreamer实例后进行。
// add YUVI420 buffer filter to ImgTexFilterMgt, this would cause performance drop, // only valid after Android 4.4 YUVI420BufDemoFilter demoFilter = new YUVI420BufDemoFilter(mStreamer.getGLRender()); mStreamer.getImgTexFilterMgt().setExtraFilter(demoFilter);
-