Android:通过视频动态模糊表面 [英] Android: Dynamically Blur Surface with Video

查看:746
本文介绍了Android:通过视频动态模糊表面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Android应用程序,其中ExoPlayer在SurfaceView的表面上播放视频,并且正在调查是否可以动态模糊播放的视频.

I am building an Android application where an ExoPlayer plays a video onto the surface of a SurfaceView, and I am investigating whether it is possible to dynamically blur the playing video.

首先要生成视图的位图以进行模糊处理的模糊技术将不起作用,因为SurfaceView的表面部分未出现在位图中.

Blurring techniques that involve first generating a bitmap of the view to blur will not work, since the surface part of a SurfaceView does not appear in bitmaps.

表面和视图曾经在旧版Android(例如Surface.FX_SURFACE_BLUR)中具有内置的模糊效果,但是在新的API中似乎已弃用.

Surfaces and views used to have built-in blurring effects in older versions of Android (e.g. Surface.FX_SURFACE_BLUR), but seem to have been deprecated in newer APIs.

谁能分享一些有关如何动态模糊表面的见解?谢谢.

Can anyone share some insight on how a surface can be dynamically blurred? Thank you.

推荐答案

StackOverflow上存在很多问题,其中涉及需要做的事情.我将介绍一下我使用的方法,希望它对某些人有用.

There are lots of questions on StackOverflow with small bits and pieces of what needs to be done. I'll go over the method I used and hopefully it will be useful to somebody.

如果这是视频帧的静态模糊,则足以在TextureView中播放视频,使用.getBitmap()功能,并使用诸如Renderscript之类的工具对生成的位图进行模糊处理.但是,.getBitmap()是在主UI线程上执行的,因此会滞后于试图复制其帧的视频.

If this was a static blur of a video frame, it would be sufficient to play the video in a TextureView, use the .getBitmap() function and blur the resulting Bitmap using a tool such as Renderscript. However, .getBitmap() is performed on the main UI thread, and hence lags the video whose frames it is trying to copy.

要对每个帧执行模糊处理,最好的方法似乎是使用带有自定义渲染器的GLSurfaceView.我使用了 VidEffects 中提供的代码,该代码来自

To perform a blur for every frame, the best approach seems to be to use a GLSurfaceView with a custom renderer. I used the code available in VidEffects pointed to from this answer as a good starting point.

半径大的模糊可能需要大量的计算.这就是为什么我首先使用两个单独的片段着色器(一个用于水平模糊,另一个用于垂直模糊结果)执行模糊.实际上,我最终只使用了一个片段着色器来应用7x7高斯内核.如果GLSurfaceView很大,请记住一个非常重要的事情是在GLSurfaceViewSurfaceHolder上调用setFixedSize()以使其分辨率低于屏幕分辨率.无论如何,结果看起来并不像是像素化的,但是性能提升非常显着.

Blurs with large radii can be very computationally intensive. That is why I first approached performing the blur with two separate fragment shaders (one to blur horizontally, and one to blur the result vertically). I actually ended up using only one fragment shader to apply a 7x7 Gaussian kernel. A very important thing to keep in mind if your GLSurfaceView is large is to call setFixedSize() on the GLSurfaceView's SurfaceHolder to make its resolution lower than that of the screen. The result does not look very pixelated since it is blurred anyway, but the performance increase is very significant.

我所做的模糊处理能够在大多数设备上以24fps的速度播放,而setFixedSize()指定的分辨率为100x70.

The blur I made managed to play 24fps on most devices, with setFixedSize() specifying its resolution to be 100x70.

这篇关于Android:通过视频动态模糊表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆